#1290 (ข้อมูลเท่าที่ where ได้)
This commit is contained in:
parent
5f7ed72261
commit
bdd654089f
2 changed files with 478 additions and 407 deletions
|
|
@ -78,6 +78,10 @@ import { ProfileDuty } from "../entities/ProfileDuty";
|
||||||
import { ProfileAssessment } from "../entities/ProfileAssessment";
|
import { ProfileAssessment } from "../entities/ProfileAssessment";
|
||||||
import { ProfileAbility } from "../entities/ProfileAbility";
|
import { ProfileAbility } from "../entities/ProfileAbility";
|
||||||
import { PermissionProfile } from "../entities/PermissionProfile";
|
import { PermissionProfile } from "../entities/PermissionProfile";
|
||||||
|
import { OrgChild1 } from "../entities/OrgChild1";
|
||||||
|
import { OrgChild2 } from "../entities/OrgChild2";
|
||||||
|
import { OrgChild3 } from "../entities/OrgChild3";
|
||||||
|
import { OrgChild4 } from "../entities/OrgChild4";
|
||||||
|
|
||||||
@Route("api/v1/org/profile")
|
@Route("api/v1/org/profile")
|
||||||
@Tags("Profile")
|
@Tags("Profile")
|
||||||
|
|
@ -90,6 +94,10 @@ import { PermissionProfile } from "../entities/PermissionProfile";
|
||||||
export class ProfileController extends Controller {
|
export class ProfileController extends Controller {
|
||||||
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
|
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
|
||||||
private orgRootRepo = AppDataSource.getRepository(OrgRoot);
|
private orgRootRepo = AppDataSource.getRepository(OrgRoot);
|
||||||
|
private orgChild1Repo = AppDataSource.getRepository(OrgChild1);
|
||||||
|
private orgChild2Repo = AppDataSource.getRepository(OrgChild2);
|
||||||
|
private orgChild3Repo = AppDataSource.getRepository(OrgChild3);
|
||||||
|
private orgChild4Repo = AppDataSource.getRepository(OrgChild4);
|
||||||
private posMasterRepo = AppDataSource.getRepository(PosMaster);
|
private posMasterRepo = AppDataSource.getRepository(PosMaster);
|
||||||
private profileRepo = AppDataSource.getRepository(Profile);
|
private profileRepo = AppDataSource.getRepository(Profile);
|
||||||
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
|
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
|
@ -5542,251 +5550,251 @@ export class ProfileController extends Controller {
|
||||||
queryLike = "profile.citizenId LIKE :keyword";
|
queryLike = "profile.citizenId LIKE :keyword";
|
||||||
} else if (searchField == "position") {
|
} else if (searchField == "position") {
|
||||||
queryLike = "profile.position LIKE :keyword";
|
queryLike = "profile.position LIKE :keyword";
|
||||||
} else if (searchField == "posNo") {
|
}
|
||||||
queryLike = `
|
// else if (searchField == "posNo") {
|
||||||
CASE
|
// queryLike = `
|
||||||
WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
|
// CASE
|
||||||
WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
|
// WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
|
||||||
WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
|
// WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
|
||||||
WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
|
// WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
|
||||||
ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
|
// WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
|
||||||
END LIKE :keyword
|
// ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
|
||||||
`;
|
// END LIKE :keyword
|
||||||
}
|
// `;
|
||||||
|
// }
|
||||||
let nodeCondition = "1=1";
|
let nodeCondition = "1=1";
|
||||||
let nodeAll = "";
|
let nodeAll = "";
|
||||||
|
let orgRoot = null;
|
||||||
|
let orgChild1 = null;
|
||||||
|
let orgChild2 = null;
|
||||||
|
let orgChild3 = null;
|
||||||
|
let orgChild4 = null;
|
||||||
|
|
||||||
|
let pmsCondition = "1=1";
|
||||||
|
let orgRootPms = null;
|
||||||
|
let orgChild1Pms = null;
|
||||||
|
let orgChild2Pms = null;
|
||||||
|
let orgChild3Pms = null;
|
||||||
|
let orgChild4Pms = null;
|
||||||
|
|
||||||
if (node === 0 && nodeId) {
|
if (node === 0 && nodeId) {
|
||||||
nodeCondition = "current_holders.orgRootId = :nodeId";
|
orgRoot = await this.orgRootRepo.findOne({where: { id: nodeId }});
|
||||||
if (isAll == false) nodeAll = " AND current_holders.orgChild1Id IS NULL";
|
if (orgRoot) {
|
||||||
|
nodeCondition = "profileSalary.orgRoot = :orgRoot";
|
||||||
|
}
|
||||||
|
if (isAll == false) nodeAll = " AND profileSalary.orgChild1Id IS NULL";
|
||||||
} else if (node === 1 && nodeId) {
|
} else if (node === 1 && nodeId) {
|
||||||
nodeCondition = "current_holders.orgChild1Id = :nodeId";
|
orgChild1 = await this.orgChild1Repo.findOne({where: { id: nodeId }});
|
||||||
if (isAll == false) nodeAll = " AND current_holders.orgChild2Id IS NULL";
|
if (orgChild1) {
|
||||||
|
nodeCondition = "profileSalary.orgChild1 = :orgChild1";
|
||||||
|
}
|
||||||
|
if (isAll == false) nodeAll = " AND profileSalary.orgChild2Id IS NULL";
|
||||||
} else if (node === 2 && nodeId) {
|
} else if (node === 2 && nodeId) {
|
||||||
nodeCondition = "current_holders.orgChild2Id = :nodeId";
|
orgChild2 = await this.orgChild2Repo.findOne({where: { id: nodeId }});
|
||||||
if (isAll == false) nodeAll = " AND current_holders.orgChild3Id IS NULL";
|
if (orgChild2) {
|
||||||
|
nodeCondition = "profileSalary.orgChild2 = :orgChild2";
|
||||||
|
}
|
||||||
|
if (isAll == false) nodeAll = " AND profileSalary.orgChild3Id IS NULL";
|
||||||
} else if (node === 3 && nodeId) {
|
} else if (node === 3 && nodeId) {
|
||||||
nodeCondition = "current_holders.orgChild3Id = :nodeId";
|
orgChild3 = await this.orgChild3Repo.findOne({where: { id: nodeId }});
|
||||||
if (isAll == false) nodeAll = " AND current_holders.orgChild4Id IS NULL";
|
if (orgChild3) {
|
||||||
|
nodeCondition = "profileSalary.orgChild3 = :orgChild3";
|
||||||
|
}
|
||||||
|
if (isAll == false) nodeAll = " AND profileSalary.orgChild4Id IS NULL";
|
||||||
} else if (node === 4 && nodeId) {
|
} else if (node === 4 && nodeId) {
|
||||||
nodeCondition = "current_holders.orgChild4Id = :nodeId";
|
orgChild4 = await this.orgChild4Repo.findOne({where: { id: nodeId }});
|
||||||
|
if (orgChild4) {
|
||||||
|
nodeCondition = "profileSalary.orgChild4 = :orgChild4";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
nodeCondition = nodeCondition + nodeAll;
|
nodeCondition = nodeCondition + nodeAll;
|
||||||
const findRevision = await this.orgRevisionRepo.findOne({
|
|
||||||
where: { orgRevisionIsCurrent: true },
|
if (_data.root) {
|
||||||
});
|
orgRootPms = await this.orgRootRepo.findOne({where: { id: _data.root }});
|
||||||
if (!findRevision) {
|
if (orgRootPms) {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
pmsCondition = "profileSalary.orgRoot = :orgRoot";
|
||||||
|
}
|
||||||
|
} else if (_data.child1) {
|
||||||
|
orgChild1Pms = await this.orgChild1Repo.findOne({where: { id: _data.child1 }});
|
||||||
|
if (orgChild1Pms) {
|
||||||
|
pmsCondition = "profileSalary.orgChild1 = :orgChild1";
|
||||||
|
}
|
||||||
|
} else if (_data.child2) {
|
||||||
|
orgChild2Pms = await this.orgChild2Repo.findOne({where: { id: _data.child2 }});
|
||||||
|
if (orgChild2Pms) {
|
||||||
|
pmsCondition = "profileSalary.orgChild2 = :orgChild2";
|
||||||
|
}
|
||||||
|
} else if (_data.child3) {
|
||||||
|
orgChild3Pms = await this.orgChild3Repo.findOne({where: { id: _data.child3 }});
|
||||||
|
if (orgChild3Pms) {
|
||||||
|
pmsCondition = "profileSalary.orgChild3 = :orgChild3";
|
||||||
|
}
|
||||||
|
} else if (_data.child4) {
|
||||||
|
orgChild4Pms = await this.orgChild4Repo.findOne({where: { id: _data.child4 }});
|
||||||
|
if (orgChild4Pms) {
|
||||||
|
pmsCondition = "profileSalary.orgChild4 = :orgChild4";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// const findRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
// where: { orgRevisionIsCurrent: true },
|
||||||
|
// });
|
||||||
|
// if (!findRevision) {
|
||||||
|
// throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
||||||
|
// }
|
||||||
const [record, total] = await this.profileRepo
|
const [record, total] = await this.profileRepo
|
||||||
.createQueryBuilder("profile")
|
.createQueryBuilder("profile")
|
||||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||||
.leftJoinAndSelect("profile.posType", "posType")
|
.leftJoinAndSelect("profile.posType", "posType")
|
||||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
.leftJoinAndSelect("profile.profileSalary", "profileSalary")
|
||||||
.leftJoinAndSelect("current_holders.positions", "positions")
|
// .leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||||
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
|
// .leftJoinAndSelect("current_holders.positions", "positions")
|
||||||
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
|
// .leftJoinAndSelect("positions.posExecutive", "posExecutive")
|
||||||
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
.where(
|
||||||
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
|
||||||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
|
||||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
|
||||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
|
||||||
.where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
|
|
||||||
orgRevisionId: node && nodeId ? findRevision.id : undefined,
|
|
||||||
})
|
|
||||||
.andWhere(
|
|
||||||
new Brackets(qb => {
|
|
||||||
qb.where("profile.isLeave IS TRUE")
|
|
||||||
.orWhere("profile.isRetirement IS TRUE");
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.andWhere(
|
|
||||||
_data.root != undefined && _data.root != null
|
|
||||||
? _data.root[0] != null
|
|
||||||
? `current_holders.orgRootId IN (:...root)`
|
|
||||||
: `current_holders.orgRootId is null`
|
|
||||||
: "1=1",
|
|
||||||
{
|
|
||||||
root: _data.root,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.andWhere(
|
|
||||||
_data.child1 != undefined && _data.child1 != null
|
|
||||||
? _data.child1[0] != null
|
|
||||||
? `current_holders.orgChild1Id IN (:...child1)`
|
|
||||||
: `current_holders.orgChild1Id is null`
|
|
||||||
: "1=1",
|
|
||||||
{
|
|
||||||
child1: _data.child1,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.andWhere(
|
|
||||||
_data.child2 != undefined && _data.child2 != null
|
|
||||||
? _data.child2[0] != null
|
|
||||||
? `current_holders.orgChild2Id IN (:...child2)`
|
|
||||||
: `current_holders.orgChild2Id is null`
|
|
||||||
: "1=1",
|
|
||||||
{
|
|
||||||
child2: _data.child2,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.andWhere(
|
|
||||||
_data.child3 != undefined && _data.child3 != null
|
|
||||||
? _data.child3[0] != null
|
|
||||||
? `current_holders.orgChild3Id IN (:...child3)`
|
|
||||||
: `current_holders.orgChild3Id is null`
|
|
||||||
: "1=1",
|
|
||||||
{
|
|
||||||
child3: _data.child3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.andWhere(
|
|
||||||
_data.child4 != undefined && _data.child4 != null
|
|
||||||
? _data.child4[0] != null
|
|
||||||
? `current_holders.orgChild4Id IN (:...child4)`
|
|
||||||
: `current_holders.orgChild4Id is null`
|
|
||||||
: "1=1",
|
|
||||||
{
|
|
||||||
child4: _data.child4,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.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.isLeave IS FALSE`
|
|
||||||
// : isRetire == true && retireType != undefined && retireType != null
|
|
||||||
// ? // ? `profile.dateLeave IS NOT NULL AND profile.leaveType = '${retireType}'`
|
|
||||||
// // : `profile.dateLeave IS NOT NULL`
|
|
||||||
// `profile.isLeave IS TRUE AND profile.leaveType = '${retireType}'`
|
|
||||||
// : `profile.isLeave IS TRUE`
|
|
||||||
// : "1=1",
|
|
||||||
// )
|
|
||||||
.andWhere(nodeCondition, {
|
|
||||||
nodeId: nodeId,
|
|
||||||
})
|
|
||||||
|
|
||||||
.andWhere(
|
|
||||||
new Brackets((qb) => {
|
new Brackets((qb) => {
|
||||||
qb.orWhere(
|
qb.where("profile.isLeave = :isLeave", { isLeave: true })
|
||||||
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
|
.orWhere("profile.isRetirement = :isRetirement", { isRetirement: true });
|
||||||
? queryLike
|
})
|
||||||
: "1=1",
|
|
||||||
{
|
|
||||||
keyword: `%${searchKeyword}%`,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
// .orderBy("current_holders.posMasterNo", "ASC")
|
.andWhere("profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id)")
|
||||||
.orderBy(`${sortBy}`, sort)
|
|
||||||
.skip((page - 1) * pageSize)
|
.andWhere(
|
||||||
.take(pageSize)
|
posType != undefined && posType != null && posType != ""
|
||||||
.getManyAndCount();
|
? "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(pmsCondition, {
|
||||||
|
orgRoot: orgRootPms ? orgRootPms.orgRootName : undefined,
|
||||||
|
orgChild1: orgChild1Pms ? orgChild1Pms.orgChild1Name : undefined,
|
||||||
|
orgChild2: orgChild2Pms ? orgChild2Pms.orgChild2Name : undefined,
|
||||||
|
orgChild3: orgChild3Pms ? orgChild3Pms.orgChild3Name : undefined,
|
||||||
|
orgChild4: orgChild4Pms ? orgChild4Pms.orgChild4Name : undefined,
|
||||||
|
})
|
||||||
|
.andWhere(nodeCondition, {
|
||||||
|
orgRoot: orgRoot ? orgRoot.orgRootName : undefined,
|
||||||
|
orgChild1: orgChild1 ? orgChild1.orgChild1Name : undefined,
|
||||||
|
orgChild2: orgChild2 ? orgChild2.orgChild2Name : undefined,
|
||||||
|
orgChild3: orgChild3 ? orgChild3.orgChild3Name : undefined,
|
||||||
|
orgChild4: orgChild4 ? orgChild4.orgChild4Name : undefined,
|
||||||
|
})
|
||||||
|
.andWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.orWhere(
|
||||||
|
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
|
||||||
|
? queryLike
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
// .orderBy("current_holders.posMasterNo", "ASC")
|
||||||
|
// .orderBy(`${sortBy}`, sort)
|
||||||
|
.skip((page - 1) * pageSize)
|
||||||
|
.take(pageSize)
|
||||||
|
.getManyAndCount();
|
||||||
|
|
||||||
const data = await Promise.all(
|
const data = await Promise.all(
|
||||||
record.map((_data) => {
|
record.map((_data) => {
|
||||||
const posExecutive =
|
// const posExecutive =
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ||
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ||
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
|
||||||
0 ||
|
// 0 ||
|
||||||
_data.current_holders
|
// _data.current_holders
|
||||||
.find((x) => x.orgRevisionId == findRevision.id)
|
// .find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.positions.find((x: any) => x.positionIsSelected == true) == null ||
|
// ?.positions.find((x: any) => x.positionIsSelected == true) == null ||
|
||||||
_data.current_holders
|
// _data.current_holders
|
||||||
.find((x) => x.orgRevisionId == findRevision.id)
|
// .find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive == null
|
// ?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive == null
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders
|
// : _data.current_holders
|
||||||
.find((x) => x.orgRevisionId == findRevision.id)
|
// .find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive
|
// ?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive
|
||||||
?.posExecutiveName;
|
// ?.posExecutiveName;
|
||||||
|
|
||||||
const shortName =
|
// const shortName =
|
||||||
_data.current_holders.length == 0
|
// _data.current_holders.length == 0
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
|
||||||
null
|
// null
|
||||||
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.orgChild3 != null
|
// ?.orgChild3 != null
|
||||||
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.orgChild2 != null
|
// ?.orgChild2 != null
|
||||||
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.orgChild1 != null
|
// ?.orgChild1 != null
|
||||||
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
|
||||||
null &&
|
// null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.orgRoot != null
|
// ?.orgRoot != null
|
||||||
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||||
: null;
|
// : null;
|
||||||
const root =
|
// const root =
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
(_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
// (_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
|
||||||
|
|
||||||
const child1 =
|
// const child1 =
|
||||||
_data.current_holders == null ||
|
// _data.current_holders == null ||
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
|
||||||
|
|
||||||
const child2 =
|
// const child2 =
|
||||||
_data.current_holders == null ||
|
// _data.current_holders == null ||
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
|
||||||
|
|
||||||
const child3 =
|
// const child3 =
|
||||||
_data.current_holders == null ||
|
// _data.current_holders == null ||
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
|
||||||
|
|
||||||
const child4 =
|
// const child4 =
|
||||||
_data.current_holders == null ||
|
// _data.current_holders == null ||
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
|
||||||
|
|
||||||
let _child1 = child1?.orgChild1Name;
|
// let _child1 = child1?.orgChild1Name;
|
||||||
let _child2 = child2?.orgChild2Name;
|
// let _child2 = child2?.orgChild2Name;
|
||||||
let _child3 = child3?.orgChild3Name;
|
// let _child3 = child3?.orgChild3Name;
|
||||||
let _child4 = child4?.orgChild4Name;
|
// let _child4 = child4?.orgChild4Name;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: _data.id,
|
id: _data.id,
|
||||||
|
|
@ -5798,23 +5806,24 @@ export class ProfileController extends Controller {
|
||||||
firstName: _data.firstName,
|
firstName: _data.firstName,
|
||||||
lastName: _data.lastName,
|
lastName: _data.lastName,
|
||||||
citizenId: _data.citizenId,
|
citizenId: _data.citizenId,
|
||||||
|
|
||||||
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
|
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
|
||||||
posType: _data.posType == null ? null : _data.posType.posTypeName,
|
posType: _data.posType == null ? null : _data.posType.posTypeName,
|
||||||
posLevelId: _data.posLevel == null ? null : _data.posLevel.id,
|
posLevelId: _data.posLevel == null ? null : _data.posLevel.id,
|
||||||
posTypeId: _data.posType == null ? null : _data.posType.id,
|
posTypeId: _data.posType == null ? null : _data.posType.id,
|
||||||
position: _data.position,
|
position: _data.position,
|
||||||
posExecutive: posExecutive,
|
posExecutive: _data.profileSalary[0].positionExecutive == null ? null : _data.profileSalary[0].positionExecutive,
|
||||||
posNo: shortName,
|
posNo: _data.profileSalary[0].posNoAbb == "" ? "" : _data.profileSalary[0].posNoAbb + _data.profileSalary[0].posNo == "" ? "" : _data.profileSalary[0].posNo,
|
||||||
rootId: root == null ? null : root.id,
|
rootId: null ,
|
||||||
root: root == null ? null : root.orgRootName,
|
root: _data.profileSalary[0].orgRoot == null ? null : _data.profileSalary[0].orgRoot,
|
||||||
orgRootShortName: root == null ? null : root.orgRootShortName,
|
orgRootShortName: _data.profileSalary[0].posNoAbb == null ? null : _data.profileSalary[0].posNoAbb,
|
||||||
orgRevisionId: root == null ? null : root.orgRevisionId,
|
orgRevisionId: null,
|
||||||
org: (_child4 == null ? "" : _child4 + "\n") +
|
org: (_data.profileSalary[0].orgChild4 == null ? "" : _data.profileSalary[0].orgChild4 + "\n") +
|
||||||
(_child3 == null ? "" : _child3 + "\n") +
|
(_data.profileSalary[0].orgChild3 == null ? "" : _data.profileSalary[0].orgChild3 + "\n") +
|
||||||
(_child2 == null ? "" : _child2 + "\n") +
|
(_data.profileSalary[0].orgChild2 == null ? "" : _data.profileSalary[0].orgChild2 + "\n") +
|
||||||
(_child1 == null ? "" : _child1 + "\n") +
|
(_data.profileSalary[0].orgChild1 == null ? "" : _data.profileSalary[0].orgChild1 + "\n") +
|
||||||
(root?.orgRootName == null ? "" : root?.orgRootName),
|
(_data.profileSalary[0].orgRoot == null ? "" : _data.profileSalary[0].orgRoot) ,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1686,113 +1686,172 @@ export class ProfileEmployeeController extends Controller {
|
||||||
queryLike = "profileEmployee.citizenId LIKE :keyword";
|
queryLike = "profileEmployee.citizenId LIKE :keyword";
|
||||||
} else if (searchField == "position") {
|
} else if (searchField == "position") {
|
||||||
queryLike = "profileEmployee.position LIKE :keyword";
|
queryLike = "profileEmployee.position LIKE :keyword";
|
||||||
} else if (searchField == "posNo") {
|
}
|
||||||
queryLike = `
|
// else if (searchField == "posNo") {
|
||||||
CASE
|
// queryLike = `
|
||||||
WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
|
// CASE
|
||||||
WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
|
// WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
|
||||||
WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
|
// WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
|
||||||
WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
|
// WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
|
||||||
ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
|
// WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
|
||||||
END LIKE :keyword
|
// ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
|
||||||
`;
|
// END LIKE :keyword
|
||||||
}
|
// `;
|
||||||
|
// }
|
||||||
let nodeCondition = "1=1";
|
let nodeCondition = "1=1";
|
||||||
let nodeAll = "";
|
let nodeAll = "";
|
||||||
if (node === 0 && nodeId) {
|
let orgRoot = null;
|
||||||
nodeCondition = "current_holders.orgRootId = :nodeId";
|
let orgChild1 = null;
|
||||||
if (isAll == false) nodeAll = " AND current_holders.orgChild1Id IS NULL";
|
let orgChild2 = null;
|
||||||
} else if (node === 1 && nodeId) {
|
let orgChild3 = null;
|
||||||
nodeCondition = "current_holders.orgChild1Id = :nodeId";
|
let orgChild4 = null;
|
||||||
if (isAll == false) nodeAll = " AND current_holders.orgChild2Id IS NULL";
|
|
||||||
} else if (node === 2 && nodeId) {
|
let pmsCondition = "1=1";
|
||||||
nodeCondition = "current_holders.orgChild2Id = :nodeId";
|
let orgRootPms = null;
|
||||||
if (isAll == false) nodeAll = " AND current_holders.orgChild3Id IS NULL";
|
let orgChild1Pms = null;
|
||||||
} else if (node === 3 && nodeId) {
|
let orgChild2Pms = null;
|
||||||
nodeCondition = "current_holders.orgChild3Id = :nodeId";
|
let orgChild3Pms = null;
|
||||||
if (isAll == false) nodeAll = " AND current_holders.orgChild4Id IS NULL";
|
let orgChild4Pms = null;
|
||||||
} else if (node === 4 && nodeId) {
|
|
||||||
nodeCondition = "current_holders.orgChild4Id = :nodeId";
|
if (node === 0 && nodeId) {
|
||||||
}
|
orgRoot = await this.orgRootRepository.findOne({where: { id: nodeId }});
|
||||||
nodeCondition = nodeCondition + nodeAll;
|
if (orgRoot) {
|
||||||
const findRevision = await this.orgRevisionRepo.findOne({
|
nodeCondition = "profileSalary.orgRoot = :orgRoot";
|
||||||
where: { orgRevisionIsCurrent: true },
|
}
|
||||||
});
|
if (isAll == false) nodeAll = " AND profileSalary.orgChild1Id IS NULL";
|
||||||
if (!findRevision) {
|
} else if (node === 1 && nodeId) {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
orgChild1 = await this.child1Repository.findOne({where: { id: nodeId }});
|
||||||
|
if (orgChild1) {
|
||||||
|
nodeCondition = "profileSalary.orgChild1 = :orgChild1";
|
||||||
|
}
|
||||||
|
if (isAll == false) nodeAll = " AND profileSalary.orgChild2Id IS NULL";
|
||||||
|
} else if (node === 2 && nodeId) {
|
||||||
|
orgChild2 = await this.child2Repository.findOne({where: { id: nodeId }});
|
||||||
|
if (orgChild2) {
|
||||||
|
nodeCondition = "profileSalary.orgChild2 = :orgChild2";
|
||||||
|
}
|
||||||
|
if (isAll == false) nodeAll = " AND profileSalary.orgChild3Id IS NULL";
|
||||||
|
} else if (node === 3 && nodeId) {
|
||||||
|
orgChild3 = await this.child3Repository.findOne({where: { id: nodeId }});
|
||||||
|
if (orgChild3) {
|
||||||
|
nodeCondition = "profileSalary.orgChild3 = :orgChild3";
|
||||||
|
}
|
||||||
|
if (isAll == false) nodeAll = " AND profileSalary.orgChild4Id IS NULL";
|
||||||
|
} else if (node === 4 && nodeId) {
|
||||||
|
orgChild4 = await this.child4Repository.findOne({where: { id: nodeId }});
|
||||||
|
if (orgChild4) {
|
||||||
|
nodeCondition = "profileSalary.orgChild4Id = :nodeId";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nodeCondition = nodeCondition + nodeAll;
|
||||||
|
|
||||||
|
if (_data.root) {
|
||||||
|
orgRootPms = await this.orgRootRepository.findOne({where: { id: _data.root }});
|
||||||
|
if (orgRootPms) {
|
||||||
|
pmsCondition = "profileSalary.orgRoot = :orgRoot";
|
||||||
|
}
|
||||||
|
} else if (_data.child1) {
|
||||||
|
orgChild1Pms = await this.child1Repository.findOne({where: { id: _data.child1 }});
|
||||||
|
if (orgChild1Pms) {
|
||||||
|
pmsCondition = "profileSalary.orgChild1 = :orgChild1";
|
||||||
|
}
|
||||||
|
} else if (_data.child2) {
|
||||||
|
orgChild2Pms = await this.child2Repository.findOne({where: { id: _data.child2 }});
|
||||||
|
if (orgChild2Pms) {
|
||||||
|
pmsCondition = "profileSalary.orgChild2 = :orgChild2";
|
||||||
|
}
|
||||||
|
} else if (_data.child3) {
|
||||||
|
orgChild3Pms = await this.child3Repository.findOne({where: { id: _data.child3 }});
|
||||||
|
if (orgChild3Pms) {
|
||||||
|
pmsCondition = "profileSalary.orgChild3 = :orgChild3";
|
||||||
|
}
|
||||||
|
} else if (_data.child4) {
|
||||||
|
orgChild4Pms = await this.child4Repository.findOne({where: { id: _data.child4 }});
|
||||||
|
if (orgChild4Pms) {
|
||||||
|
pmsCondition = "profileSalary.orgChild4 = :orgChild4";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// const findRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
// where: { orgRevisionIsCurrent: true },
|
||||||
|
// });
|
||||||
|
// if (!findRevision) {
|
||||||
|
// throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
||||||
|
// }
|
||||||
const [record, total] = await this.profileRepo
|
const [record, total] = await this.profileRepo
|
||||||
.createQueryBuilder("profileEmployee")
|
.createQueryBuilder("profileEmployee")
|
||||||
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
|
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
|
||||||
.leftJoinAndSelect("profileEmployee.posType", "posType")
|
.leftJoinAndSelect("profileEmployee.posType", "posType")
|
||||||
.leftJoinAndSelect("profileEmployee.current_holders", "current_holders")
|
// .leftJoinAndSelect("profileEmployee.current_holders", "current_holders")
|
||||||
.leftJoinAndSelect("profileEmployee.profileEmployeeEmployment", "profileEmployeeEmployment")
|
.leftJoinAndSelect("profileEmployee.profileEmployeeEmployment", "profileEmployeeEmployment")
|
||||||
.leftJoinAndSelect("current_holders.positions", "positions")
|
// .leftJoinAndSelect("current_holders.positions", "positions")
|
||||||
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
|
.leftJoinAndSelect("profileEmployee.profileSalary", "profileSalary")
|
||||||
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
// .leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
|
||||||
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
// .leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
||||||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
// .leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
||||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
// .leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
// .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||||
.where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
|
// .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||||
orgRevisionId: node && nodeId ? findRevision.id : undefined,
|
// .where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
|
||||||
})
|
// orgRevisionId: node && nodeId ? findRevision.id : undefined,
|
||||||
.andWhere(
|
// })
|
||||||
new Brackets(qb => {
|
.where(
|
||||||
qb.where("profileEmployee.isLeave IS TRUE")
|
new Brackets((qb) => {
|
||||||
.orWhere("profileEmployee.isRetirement IS TRUE");
|
qb.where("profileEmployee.isLeave = :isLeave", { isLeave: true })
|
||||||
|
.orWhere("profileEmployee.isRetirement = :isRetirement", { isRetirement: true });
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.andWhere(
|
.andWhere("profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileEmployeeId = profileEmployee.id)")
|
||||||
_data.root != undefined && _data.root != null
|
|
||||||
? _data.root[0] != null
|
// .andWhere(
|
||||||
? `current_holders.orgRootId IN (:...root)`
|
// _data.root != undefined && _data.root != null
|
||||||
: `current_holders.orgRootId is null`
|
// ? _data.root[0] != null
|
||||||
: "1=1",
|
// ? `current_holders.orgRootId IN (:...root)`
|
||||||
{
|
// : `current_holders.orgRootId is null`
|
||||||
root: _data.root,
|
// : "1=1",
|
||||||
},
|
// {
|
||||||
)
|
// root: _data.root,
|
||||||
.andWhere(
|
// },
|
||||||
_data.child1 != undefined && _data.child1 != null
|
// )
|
||||||
? _data.child1[0] != null
|
// .andWhere(
|
||||||
? `current_holders.orgChild1Id IN (:...child1)`
|
// _data.child1 != undefined && _data.child1 != null
|
||||||
: `current_holders.orgChild1Id is null`
|
// ? _data.child1[0] != null
|
||||||
: "1=1",
|
// ? `current_holders.orgChild1Id IN (:...child1)`
|
||||||
{
|
// : `current_holders.orgChild1Id is null`
|
||||||
child1: _data.child1,
|
// : "1=1",
|
||||||
},
|
// {
|
||||||
)
|
// child1: _data.child1,
|
||||||
.andWhere(
|
// },
|
||||||
_data.child2 != undefined && _data.child2 != null
|
// )
|
||||||
? _data.child2[0] != null
|
// .andWhere(
|
||||||
? `current_holders.orgChild2Id IN (:...child2)`
|
// _data.child2 != undefined && _data.child2 != null
|
||||||
: `current_holders.orgChild2Id is null`
|
// ? _data.child2[0] != null
|
||||||
: "1=1",
|
// ? `current_holders.orgChild2Id IN (:...child2)`
|
||||||
{
|
// : `current_holders.orgChild2Id is null`
|
||||||
child2: _data.child2,
|
// : "1=1",
|
||||||
},
|
// {
|
||||||
)
|
// child2: _data.child2,
|
||||||
.andWhere(
|
// },
|
||||||
_data.child3 != undefined && _data.child3 != null
|
// )
|
||||||
? _data.child3[0] != null
|
// .andWhere(
|
||||||
? `current_holders.orgChild3Id IN (:...child3)`
|
// _data.child3 != undefined && _data.child3 != null
|
||||||
: `current_holders.orgChild3Id is null`
|
// ? _data.child3[0] != null
|
||||||
: "1=1",
|
// ? `current_holders.orgChild3Id IN (:...child3)`
|
||||||
{
|
// : `current_holders.orgChild3Id is null`
|
||||||
child3: _data.child3,
|
// : "1=1",
|
||||||
},
|
// {
|
||||||
)
|
// child3: _data.child3,
|
||||||
.andWhere(
|
// },
|
||||||
_data.child4 != undefined && _data.child4 != null
|
// )
|
||||||
? _data.child4[0] != null
|
// .andWhere(
|
||||||
? `current_holders.orgChild4Id IN (:...child4)`
|
// _data.child4 != undefined && _data.child4 != null
|
||||||
: `current_holders.orgChild4Id is null`
|
// ? _data.child4[0] != null
|
||||||
: "1=1",
|
// ? `current_holders.orgChild4Id IN (:...child4)`
|
||||||
{
|
// : `current_holders.orgChild4Id is null`
|
||||||
child4: _data.child4,
|
// : "1=1",
|
||||||
},
|
// {
|
||||||
)
|
// child4: _data.child4,
|
||||||
|
// },
|
||||||
|
// )
|
||||||
.andWhere(
|
.andWhere(
|
||||||
posType != undefined && posType != null && posType != ""
|
posType != undefined && posType != null && posType != ""
|
||||||
? "posType.posTypeName LIKE :keyword1"
|
? "posType.posTypeName LIKE :keyword1"
|
||||||
|
|
@ -1814,15 +1873,6 @@ export class ProfileEmployeeController extends Controller {
|
||||||
? `profileEmployee.isProbation = ${isProbation}`
|
? `profileEmployee.isProbation = ${isProbation}`
|
||||||
: "1=1",
|
: "1=1",
|
||||||
)
|
)
|
||||||
// .andWhere(
|
|
||||||
// isRetire != undefined && isRetire != null
|
|
||||||
// ? isRetire == false
|
|
||||||
// ? `profileEmployee.isLeave IS FALSE`
|
|
||||||
// : isRetire == true && retireType != undefined && retireType != null
|
|
||||||
// ? `profileEmployee.isLeave IS TRUE AND profileEmployee.leaveType = '${retireType}'`
|
|
||||||
// : `profileEmployee.isLeave IS TRUE`
|
|
||||||
// : "1=1",
|
|
||||||
// )
|
|
||||||
.andWhere("profileEmployee.employeeClass LIKE :type", {
|
.andWhere("profileEmployee.employeeClass LIKE :type", {
|
||||||
type: "PERM",
|
type: "PERM",
|
||||||
})
|
})
|
||||||
|
|
@ -1834,89 +1884,101 @@ export class ProfileEmployeeController extends Controller {
|
||||||
keyword: `%${searchKeyword}%`,
|
keyword: `%${searchKeyword}%`,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
.andWhere(pmsCondition, {
|
||||||
|
orgRoot: orgRootPms ? orgRootPms.orgRootName : undefined,
|
||||||
|
orgChild1: orgChild1Pms ? orgChild1Pms.orgChild1Name : undefined,
|
||||||
|
orgChild2: orgChild2Pms ? orgChild2Pms.orgChild2Name : undefined,
|
||||||
|
orgChild3: orgChild3Pms ? orgChild3Pms.orgChild3Name : undefined,
|
||||||
|
orgChild4: orgChild4Pms ? orgChild4Pms.orgChild4Name : undefined,
|
||||||
|
})
|
||||||
|
|
||||||
.andWhere(nodeCondition, {
|
.andWhere(nodeCondition, {
|
||||||
nodeId: nodeId,
|
orgRoot: orgRoot ? orgRoot.orgRootName : undefined,
|
||||||
|
orgChild1: orgChild1 ? orgChild1.orgChild1Name : undefined,
|
||||||
|
orgChild2: orgChild2 ? orgChild2.orgChild2Name : undefined,
|
||||||
|
orgChild3: orgChild3 ? orgChild3.orgChild3Name : undefined,
|
||||||
|
orgChild4: orgChild4 ? orgChild4.orgChild4Name : undefined,
|
||||||
})
|
})
|
||||||
// .andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, {
|
// .andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, {
|
||||||
// orgRevisionId: findRevision.id,
|
// orgRevisionId: findRevision.id,
|
||||||
// })
|
// })
|
||||||
// .orderBy("current_holders.posMasterNo", "ASC")
|
// .orderBy("current_holders.posMasterNo", "ASC")
|
||||||
.orderBy(`${sortBy}`, sort)
|
// .orderBy(`${sortBy}`, sort)
|
||||||
.skip((page - 1) * pageSize)
|
.skip((page - 1) * pageSize)
|
||||||
.take(pageSize)
|
.take(pageSize)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
const data = await Promise.all(
|
const data = await Promise.all(
|
||||||
record.map((_data) => {
|
record.map((_data) => {
|
||||||
const shortName =
|
// const shortName =
|
||||||
_data.current_holders.length == 0
|
// _data.current_holders.length == 0
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
|
||||||
null
|
// null
|
||||||
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.orgChild3 != null
|
// ?.orgChild3 != null
|
||||||
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.orgChild2 != null
|
// ?.orgChild2 != null
|
||||||
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.orgChild1 != null
|
// ?.orgChild1 != null
|
||||||
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
|
||||||
null &&
|
// null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||||
?.orgRoot != null
|
// ?.orgRoot != null
|
||||||
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||||
: null;
|
// : null;
|
||||||
const dateEmployment =
|
const dateEmployment =
|
||||||
_data.profileEmployeeEmployment.length == 0
|
_data.profileEmployeeEmployment.length == 0
|
||||||
? null
|
? null
|
||||||
: _data.profileEmployeeEmployment.reduce((latest, current) => {
|
: _data.profileEmployeeEmployment.reduce((latest, current) => {
|
||||||
return latest.date > current.date ? latest : current;
|
return latest.date > current.date ? latest : current;
|
||||||
}).date;
|
}).date;
|
||||||
const root =
|
// const root =
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
(_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
// (_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
|
||||||
|
|
||||||
const child1 =
|
// const child1 =
|
||||||
_data.current_holders == null ||
|
// _data.current_holders == null ||
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
|
||||||
|
|
||||||
const child2 =
|
// const child2 =
|
||||||
_data.current_holders == null ||
|
// _data.current_holders == null ||
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
|
||||||
|
|
||||||
const child3 =
|
// const child3 =
|
||||||
_data.current_holders == null ||
|
// _data.current_holders == null ||
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
|
||||||
|
|
||||||
const child4 =
|
// const child4 =
|
||||||
_data.current_holders == null ||
|
// _data.current_holders == null ||
|
||||||
_data.current_holders.length == 0 ||
|
// _data.current_holders.length == 0 ||
|
||||||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||||
? null
|
// ? null
|
||||||
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
|
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
|
||||||
|
|
||||||
let _child1 = child1?.orgChild1Name;
|
// let _child1 = child1?.orgChild1Name;
|
||||||
let _child2 = child2?.orgChild2Name;
|
// let _child2 = child2?.orgChild2Name;
|
||||||
let _child3 = child3?.orgChild3Name;
|
// let _child3 = child3?.orgChild3Name;
|
||||||
let _child4 = child4?.orgChild4Name;
|
// let _child4 = child4?.orgChild4Name;
|
||||||
return {
|
return {
|
||||||
id: _data.id,
|
id: _data.id,
|
||||||
prefix: _data.prefix,
|
prefix: _data.prefix,
|
||||||
|
|
@ -1932,7 +1994,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
positionId: _data.positionIdTemp,
|
positionId: _data.positionIdTemp,
|
||||||
posmasterId: _data.posmasterIdTemp,
|
posmasterId: _data.posmasterIdTemp,
|
||||||
position: _data.position,
|
position: _data.position,
|
||||||
posNo: _data.employeeClass == "TEMP" ? _data.posMasterNoTemp : shortName,
|
posNo: _data.profileSalary[0].posNoAbb == "" ? "" : _data.profileSalary[0].posNoAbb + _data.profileSalary[0].posNo == "" ? "" : _data.profileSalary[0].posNo,
|
||||||
employeeClass: _data.employeeClass == null ? null : _data.employeeClass,
|
employeeClass: _data.employeeClass == null ? null : _data.employeeClass,
|
||||||
govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0),
|
govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0),
|
||||||
age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0),
|
age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0),
|
||||||
|
|
@ -1996,11 +2058,11 @@ export class ProfileEmployeeController extends Controller {
|
||||||
child4: _data.child4Temp ? _data.child4Temp : null,
|
child4: _data.child4Temp ? _data.child4Temp : null,
|
||||||
child4Id: _data.child4IdTemp ? _data.child4IdTemp : null,
|
child4Id: _data.child4IdTemp ? _data.child4IdTemp : null,
|
||||||
child4ShortName: _data.child4ShortNameTemp ? _data.child4ShortNameTemp : null,
|
child4ShortName: _data.child4ShortNameTemp ? _data.child4ShortNameTemp : null,
|
||||||
org: (_child4 == null ? "" : _child4 + "\n") +
|
org: (_data.profileSalary[0].orgChild4 == null ? "" : _data.profileSalary[0].orgChild4 + "\n") +
|
||||||
(_child3 == null ? "" : _child3 + "\n") +
|
(_data.profileSalary[0].orgChild3 == null ? "" : _data.profileSalary[0].orgChild3 + "\n") +
|
||||||
(_child2 == null ? "" : _child2 + "\n") +
|
(_data.profileSalary[0].orgChild2 == null ? "" : _data.profileSalary[0].orgChild2 + "\n") +
|
||||||
(_child1 == null ? "" : _child1 + "\n") +
|
(_data.profileSalary[0].orgChild1 == null ? "" : _data.profileSalary[0].orgChild1 + "\n") +
|
||||||
(root?.orgRootName == null ? "" : root?.orgRootName),
|
(_data.profileSalary[0].orgRoot == null ? "" : _data.profileSalary[0].orgRoot),
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue