no message

This commit is contained in:
kittapath 2025-02-18 23:02:38 +07:00
parent 28bfc04d64
commit 539f433bd7
4 changed files with 242 additions and 66 deletions

View file

@ -1213,31 +1213,31 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot.ancestorDNA ?? null,
)?.orgRoot?.ancestorDNA ?? null,
child1DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3.ancestorDNA ?? null,
)?.orgChild3?.ancestorDNA ?? null,
child2DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2.ancestorDNA ?? null,
)?.orgChild2?.ancestorDNA ?? null,
child3DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3.ancestorDNA ?? null,
)?.orgChild3?.ancestorDNA ?? null,
child4DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4.ancestorDNA ?? null,
)?.orgChild4?.ancestorDNA ?? null,
commander: fullname,
posLevel: profile.posLevel?.posLevelName ?? null,
posType: profile.posType?.posTypeName ?? null,
@ -1510,31 +1510,31 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot.ancestorDNA ?? null,
)?.orgRoot?.ancestorDNA ?? null,
child1DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1.ancestorDNA ?? null,
)?.orgChild1?.ancestorDNA ?? null,
child2DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2.ancestorDNA ?? null,
)?.orgChild2?.ancestorDNA ?? null,
child3DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3.ancestorDNA ?? null,
)?.orgChild3?.ancestorDNA ?? null,
child4DnaId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4.ancestorDNA ?? null,
)?.orgChild4?.ancestorDNA ?? null,
commander: fullname,
posLevel: profile.posLevel?.posLevelName ?? null,
posType: profile.posType?.posTypeName ?? null,
@ -2276,7 +2276,7 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot.ancestorDNA ?? null,
)?.orgRoot?.ancestorDNA ?? null,
child1:
profile?.current_holders?.find(
(x) =>
@ -2294,7 +2294,7 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1.ancestorDNA ?? null,
)?.orgChild1?.ancestorDNA ?? null,
child2:
profile?.current_holders?.find(
(x) =>
@ -2312,7 +2312,7 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2.ancestorDNA ?? null,
)?.orgChild2?.ancestorDNA ?? null,
child3:
profile?.current_holders?.find(
(x) =>
@ -2330,7 +2330,7 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3.ancestorDNA ?? null,
)?.orgChild3?.ancestorDNA ?? null,
child4:
profile?.current_holders?.find(
(x) =>
@ -2348,7 +2348,7 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4.ancestorDNA ?? null,
)?.orgChild4?.ancestorDNA ?? null,
posNo: shortName ?? "",
};
});
@ -2643,7 +2643,7 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot.ancestorDNA ?? null,
)?.orgRoot?.ancestorDNA ?? null,
child1:
profile?.current_holders?.find(
(x) =>
@ -2661,7 +2661,7 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1.ancestorDNA ?? null,
)?.orgChild1?.ancestorDNA ?? null,
child2:
profile?.current_holders?.find(
(x) =>
@ -2679,7 +2679,7 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2.ancestorDNA ?? null,
)?.orgChild2?.ancestorDNA ?? null,
child3:
profile?.current_holders?.find(
(x) =>
@ -2697,7 +2697,7 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3.ancestorDNA ?? null,
)?.orgChild3?.ancestorDNA ?? null,
child4:
profile?.current_holders?.find(
(x) =>
@ -2715,7 +2715,7 @@ export class OrganizationDotnetController extends Controller {
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4.ancestorDNA ?? null,
)?.orgChild4?.ancestorDNA ?? null,
posNo: shortName ?? "",
};
});

View file

@ -4386,9 +4386,6 @@ export class ProfileController extends Controller {
.andWhere(nodeCondition, {
nodeId: nodeId,
})
// .andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, {
// orgRevisionId: revisionId,
// })
.orderBy("current_holders.posMasterNo", "ASC")
.skip((page - 1) * pageSize)
.take(pageSize)
@ -7303,6 +7300,7 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.andWhere("profile.isLeave = false")
.andWhere(
_data.root != undefined && _data.root != null
? _data.root[0] != null

View file

@ -67,6 +67,7 @@ import { ProfileLeave } from "../entities/ProfileLeave";
import permission from "../interfaces/permission";
import axios from "axios";
import { Position } from "../entities/Position";
import { EmployeePosition } from "../entities/EmployeePosition";
@Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee")
@Security("bearerAuth")
@ -108,6 +109,7 @@ export class ProfileEmployeeController extends Controller {
private profileInsigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave);
private positionRepository = AppDataSource.getRepository(Position);
private employeePositionRepository = AppDataSource.getRepository(EmployeePosition);
/**
* report
@ -1399,6 +1401,219 @@ export class ProfileEmployeeController extends Controller {
return new HttpSuccess(formattedData);
}
/**
* API
*
* @summary ORG_065 -
*
*/
@Get("otherSystem")
async listProfileNoPermission(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query()
searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position" | "posNo",
@Query() searchKeyword: string = "",
@Query() posType?: string,
@Query() posLevel?: string,
@Query() yearLeave?: number,
@Query() isProbation?: boolean,
@Query() isRetire?: boolean,
@Query() nodeId?: string,
) {
let queryLike =
"CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword";
if (searchField == "citizenId") {
queryLike = "profileEmployee.citizenId LIKE :keyword";
} else if (searchField == "position") {
queryLike = "profileEmployee.position LIKE :keyword";
} else if (searchField == "posNo") {
queryLike = `
CASE
WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
END LIKE :keyword
`;
}
let posMaster = await this.posMasterRepo.findOne({
where: {
current_holder: { keycloak: request.user.sub },
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
});
let revisionId = "";
if (nodeId == null) {
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
revisionId = findRevision.id;
if (posMaster != null) nodeId = posMaster.orgRootId ?? "";
} else {
const findRoot = await this.orgRootRepository.findOne({
where: { id: nodeId },
});
if (!findRoot) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบสำนักงานนี้ในระบบ");
}
revisionId = findRoot.orgRevisionId;
}
let nodeCondition = "current_holders.orgRootId = :nodeId";
const [record, total] = await this.profileRepo
.createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
.leftJoinAndSelect("profileEmployee.posType", "posType")
.leftJoinAndSelect("profileEmployee.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: revisionId })
.andWhere(
posType != undefined && posType != null && posType != ""
? "posType.posTypeName LIKE :keyword1"
: "1=1",
{
keyword1: `${posType}`,
},
)
.andWhere(
posLevel != undefined && posLevel != null && posLevel != ""
? "posLevel.posLevelName LIKE :keyword2"
: "1=1",
{
keyword2: `${posLevel}`,
},
)
.andWhere(
isProbation != undefined && isProbation != null
? `profile.isProbation = ${isProbation}`
: "1=1",
)
.andWhere(
isRetire != undefined && isRetire != null
? isRetire == false
? `profile.dateLeave IS null`
: `profile.dateLeave IS NOT NULL`
: "1=1",
)
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.andWhere(nodeCondition, {
nodeId: nodeId,
})
.orderBy("current_holders.posMasterNo", "ASC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const data = await Promise.all(
record.map((_data) => {
const shortName =
_data.current_holders.length == 0
? null
: _data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3 !=
null
? `${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2 !=
null
? `${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1 !=
null
? `${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot !=
null
? `${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.posMasterNo}`
: null;
const root =
_data.current_holders.length == 0 ||
(_data.current_holders.find((x) => x.orgRevisionId == revisionId) != null &&
_data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot == null)
? null
: _data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot;
const child1 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == revisionId) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1;
const child2 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == revisionId) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2;
const child3 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == revisionId) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3;
const child4 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == revisionId) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4;
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`;
return {
id: _data.id,
avatar: _data.avatar,
avatarName: _data.avatarName,
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,
posLevelId: _data.posLevel == null ? null : _data.posLevel.id,
posTypeId: _data.posType == null ? null : _data.posType.id,
position: _data.position,
posNo: shortName,
rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName,
orgRootShortName: root == null ? null : root.orgRootShortName,
orgRevisionId: root == null ? null : root.orgRevisionId,
org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`,
};
}),
);
return new HttpSuccess({ data: data, total });
}
/**
* API Update amount
*
@ -2201,8 +2416,7 @@ export class ProfileEmployeeController extends Controller {
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4;
const position = await this.positionRepository.findOne({
relations: ["posExecutive"],
const position = await this.employeePositionRepository.findOne({
where: {
posMasterId: posMaster?.id,
},
@ -2231,16 +2445,9 @@ export class ProfileEmployeeController extends Controller {
posTypeName: profile.posType == null ? null : profile.posType.posTypeName,
posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank,
posTypeId: profile.posType == null ? null : profile.posType.id,
posExecutiveName:
position == null || position.posExecutive == null
? null
: position.posExecutive.posExecutiveName,
posExecutivePriority:
position == null || position.posExecutive == null
? null
: position.posExecutive.posExecutivePriority,
posExecutiveId:
position == null || position.posExecutive == null ? null : position.posExecutive.id,
posExecutiveName: null,
posExecutivePriority: null,
posExecutiveId: null,
rootId: root == null ? null : root.id,
rootDnaId: root == null ? null : root.ancestorDNA,
root: root == null ? null : root.orgRootName,
@ -3015,6 +3222,7 @@ export class ProfileEmployeeController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.andWhere("profile.isLeave = false")
.andWhere(
_data.root != undefined && _data.root != null
? _data.root[0] != null
@ -3279,10 +3487,6 @@ export class ProfileEmployeeController extends Controller {
posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName,
posTypeName: item.posType == null ? null : item.posType.posTypeName,
posNo: `${posMaster == null ? null : posMaster.posMasterNo}${shortName}`,
// positionField: position == null ? null : position.positionField,
// positionArea: position == null ? null : position.positionArea,
// posExecutiveName: posExecutive,
// positionExecutiveField: position == null ? null : position.positionExecutiveField,
isProbation: item.isProbation,
orgRootName:
item.current_holders == null ||
@ -3729,7 +3933,6 @@ export class ProfileEmployeeController extends Controller {
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions")
// .leftJoinAndSelect("positions.posExecutive", "posExecutive")
.where("YEAR(profileEmployee.dateRetire) = :year", { year })
.getMany();
@ -3750,23 +3953,6 @@ export class ProfileEmployeeController extends Controller {
item.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id);
// const posExecutive =
// position == null ||
// item.current_holders
// .find((x) => x.orgRevisionId == findRevision.id)
// ?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
// null ||
// item.current_holders
// .find((x) => x.orgRevisionId == findRevision.id)
// ?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
// ?.posExecutiveName == null
// ? null
// : item.current_holders
// .find((x) => x.orgRevisionId == findRevision.id)
// ?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
// .posExecutiveName;
// const posExecutiveId =
// position == null || position.posExecutive == null ? null : position.posExecutive.id;
const shortName =
item.current_holders.length == 0
@ -3880,8 +4066,6 @@ export class ProfileEmployeeController extends Controller {
posNo: shortName,
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
position: item.position,
// posExecutiveId: posExecutiveId,
// posExecutiveName: posExecutive,
node: node,
nodeId: nodeId,
nodeShortName: nodeShortName,
@ -4536,12 +4720,6 @@ export class ProfileEmployeeController extends Controller {
null
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4;
// const position = await this.positionRepository.findOne({
// relations: ["posExecutive"],
// where: {
// posMasterId: posMaster?.id,
// },
// });
const shortName =
profile.current_holders.length == 0
? null
@ -4588,7 +4766,6 @@ export class ProfileEmployeeController extends Controller {
posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank,
posTypeShortName: profile.posType == null ? null : profile.posType.posTypeShortName,
posTypeId: profile.posType == null ? null : profile.posType.id,
// posExecutiveName: "",
rootId: root == null ? null : root.id,
rootDnaId: root == null ? null : root.ancestorDNA,
root: root == null ? null : root.orgRootName,

View file

@ -2565,6 +2565,7 @@ export class ProfileEmployeeTempController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.andWhere("profile.isLeave = false")
.where("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", {
keyword: `%${body.keyword}%`,
})