no message
This commit is contained in:
parent
5d2ab9269d
commit
045ac98952
1 changed files with 80 additions and 280 deletions
|
|
@ -2476,192 +2476,12 @@ export class PositionController extends Controller {
|
|||
typeCommand: string;
|
||||
posType: string;
|
||||
posLevel: string;
|
||||
isAll: boolean;
|
||||
isBlank: boolean;
|
||||
},
|
||||
) {
|
||||
let typeCondition: any = {};
|
||||
|
||||
if (body.node === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.nodeId,
|
||||
orgChild1Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
};
|
||||
} else if (body.node === 1) {
|
||||
typeCondition = {
|
||||
orgChild1Id: body.nodeId,
|
||||
orgChild2Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
};
|
||||
} else if (body.node === 2) {
|
||||
typeCondition = {
|
||||
orgChild2Id: body.nodeId,
|
||||
orgChild3Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
};
|
||||
} else if (body.node === 3) {
|
||||
typeCondition = {
|
||||
orgChild3Id: body.nodeId,
|
||||
orgChild4Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
};
|
||||
} else if (body.node === 4) {
|
||||
typeCondition = {
|
||||
orgChild4Id: body.nodeId,
|
||||
next_holderId: IsNull(),
|
||||
};
|
||||
}
|
||||
|
||||
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
|
||||
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
|
||||
.where(typeCondition)
|
||||
.orderBy("posMaster.posMasterOrder", "ASC")
|
||||
.getManyAndCount();
|
||||
|
||||
const formattedData = await Promise.all(
|
||||
posMaster.map(async (posMaster) => {
|
||||
const positions = await this.positionRepository.find({
|
||||
where: {
|
||||
posMasterId: posMaster.id,
|
||||
},
|
||||
relations: ["posLevel", "posType", "posExecutive"],
|
||||
});
|
||||
|
||||
let profile: any;
|
||||
const chkRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: posMaster.orgRevisionId },
|
||||
});
|
||||
if (chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft) {
|
||||
profile = await this.profileRepository.findOne({
|
||||
where: { id: String(posMaster.current_holderId) },
|
||||
});
|
||||
} else if (!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft) {
|
||||
profile = await this.profileRepository.findOne({
|
||||
where: { id: String(posMaster.next_holderId) },
|
||||
});
|
||||
}
|
||||
const type = await this.posTypeRepository.findOne({
|
||||
where: { id: String(profile?.posTypeId) },
|
||||
});
|
||||
const level = await this.posLevelRepository.findOne({
|
||||
where: { id: String(profile?.posLevelId) },
|
||||
});
|
||||
|
||||
let shortName = "";
|
||||
|
||||
if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id == null &&
|
||||
posMaster.orgChild2Id == null &&
|
||||
posMaster.orgChild3Id == null
|
||||
) {
|
||||
body.node = 0;
|
||||
shortName = posMaster.orgRoot.orgRootShortName;
|
||||
} else if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id !== null &&
|
||||
posMaster.orgChild2Id == null &&
|
||||
posMaster.orgChild3Id == null
|
||||
) {
|
||||
body.node = 1;
|
||||
shortName = posMaster.orgChild1.orgChild1ShortName;
|
||||
} else if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id !== null &&
|
||||
posMaster.orgChild2Id !== null &&
|
||||
posMaster.orgChild3Id == null
|
||||
) {
|
||||
body.node = 2;
|
||||
shortName = posMaster.orgChild2.orgChild2ShortName;
|
||||
} else if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id !== null &&
|
||||
posMaster.orgChild2Id !== null &&
|
||||
posMaster.orgChild3Id !== null
|
||||
) {
|
||||
body.node = 3;
|
||||
shortName = posMaster.orgChild3.orgChild3ShortName;
|
||||
} else if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id !== null &&
|
||||
posMaster.orgChild2Id !== null &&
|
||||
posMaster.orgChild3Id !== null
|
||||
) {
|
||||
body.node = 4;
|
||||
shortName = posMaster.orgChild4.orgChild4ShortName;
|
||||
}
|
||||
|
||||
return {
|
||||
id: posMaster.id,
|
||||
orgRootId: posMaster.orgRootId,
|
||||
orgChild1Id: posMaster.orgChild1Id,
|
||||
orgChild2Id: posMaster.orgChild2Id,
|
||||
orgChild3Id: posMaster.orgChild3Id,
|
||||
orgChild4Id: posMaster.orgChild4Id,
|
||||
posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
||||
posMasterNo: posMaster.posMasterNo,
|
||||
posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
||||
fullNameCurrentHolder:
|
||||
posMaster.current_holder == null
|
||||
? null
|
||||
: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`,
|
||||
fullNameNextHolder:
|
||||
posMaster.next_holder == null
|
||||
? null
|
||||
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
|
||||
orgShortname: shortName,
|
||||
isSit: posMaster.isSit,
|
||||
profilePosition: profile == null || profile.position == null ? null : profile.position,
|
||||
profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName,
|
||||
profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName,
|
||||
isPosition: positions.filter((x) => x.positionName == body.position).length > 0,
|
||||
positions: positions.map((position) => ({
|
||||
id: position.id,
|
||||
positionName: position.positionName,
|
||||
positionField: position.positionField,
|
||||
posTypeId: position.posTypeId,
|
||||
posTypeName: position.posType == null ? null : position.posType.posTypeName,
|
||||
posLevelId: position.posLevelId,
|
||||
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
|
||||
posExecutiveId: position.posExecutiveId,
|
||||
posExecutiveName:
|
||||
position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
|
||||
positionExecutiveField: position.positionExecutiveField,
|
||||
positionArea: position.positionArea,
|
||||
positionIsSelected: position.positionIsSelected,
|
||||
isSpecial: position.isSpecial,
|
||||
})),
|
||||
};
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
}
|
||||
/**
|
||||
* API ค้นหาตำแหน่งในระบบสมัครสอบ
|
||||
*
|
||||
* @summary ค้นหาตำแหน่งในระบบสมัครสอบ
|
||||
*
|
||||
*/
|
||||
@Post("placement/searchh")
|
||||
async searchPlacementt(
|
||||
@Body()
|
||||
body: {
|
||||
node: number;
|
||||
nodeId: string;
|
||||
position: string;
|
||||
typeCommand: string;
|
||||
posType: string;
|
||||
posLevel: string;
|
||||
},
|
||||
) {
|
||||
let typeCondition: any = {};
|
||||
let conditionA: any = {};
|
||||
let conditionA: any = null;
|
||||
|
||||
let posType = await this.posTypeRepository.findOne({
|
||||
where: { id: String(body.posType) },
|
||||
|
|
@ -2671,65 +2491,71 @@ export class PositionController extends Controller {
|
|||
});
|
||||
|
||||
if (body.typeCommand == "APPOINTED" || body.typeCommand == "MOVE") {
|
||||
conditionA = {
|
||||
posTypeId: body.posType,
|
||||
posLevelId: body.posLevel,
|
||||
};
|
||||
conditionA = "positions.posTypeId LIKE :posType AND positions.posLevelId LIKE :posLevel";
|
||||
} else if (body.typeCommand == "APPOINT") {
|
||||
conditionA = {
|
||||
posType: {
|
||||
posTypeRank: MoreThan(posType == null ? 0 : posType.posTypeRank),
|
||||
},
|
||||
};
|
||||
conditionA = "posType.posTypeRank > :posTypeRank";
|
||||
} else if (body.typeCommand == "SLIP") {
|
||||
conditionA = {
|
||||
posTypeId: body.posType,
|
||||
posLevel: {
|
||||
posLevelRank: MoreThan(posLevel == null ? 0 : posLevel.posLevelRank),
|
||||
},
|
||||
};
|
||||
conditionA = "positions.posTypeId LIKE :posType AND posLevel.posLevelRank > :posLevelRank";
|
||||
}
|
||||
|
||||
if (body.node === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.nodeId,
|
||||
orgChild1Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
positions: conditionA,
|
||||
};
|
||||
} else if (body.node === 1) {
|
||||
typeCondition = {
|
||||
orgChild1Id: body.nodeId,
|
||||
orgChild2Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
positions: conditionA,
|
||||
};
|
||||
} else if (body.node === 2) {
|
||||
typeCondition = {
|
||||
orgChild2Id: body.nodeId,
|
||||
orgChild3Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
positions: conditionA,
|
||||
};
|
||||
} else if (body.node === 3) {
|
||||
typeCondition = {
|
||||
orgChild3Id: body.nodeId,
|
||||
orgChild4Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
positions: {
|
||||
posTypeId: body.posType,
|
||||
posLevelId: body.posLevel,
|
||||
},
|
||||
};
|
||||
} else if (body.node === 4) {
|
||||
typeCondition = {
|
||||
orgChild4Id: body.nodeId,
|
||||
next_holderId: IsNull(),
|
||||
positions: {
|
||||
posTypeId: body.posType,
|
||||
posLevelId: body.posLevel,
|
||||
},
|
||||
};
|
||||
if (body.isAll == false) {
|
||||
if (body.node === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.nodeId,
|
||||
orgChild1Id: IsNull(),
|
||||
current_holder: body.isBlank == true ? IsNull() : Not(IsNull()),
|
||||
};
|
||||
} else if (body.node === 1) {
|
||||
typeCondition = {
|
||||
orgChild1Id: body.nodeId,
|
||||
orgChild2Id: IsNull(),
|
||||
current_holder: body.isBlank == true ? IsNull() : Not(IsNull()),
|
||||
};
|
||||
} else if (body.node === 2) {
|
||||
typeCondition = {
|
||||
orgChild2Id: body.nodeId,
|
||||
orgChild3Id: IsNull(),
|
||||
current_holder: body.isBlank == true ? IsNull() : Not(IsNull()),
|
||||
};
|
||||
} else if (body.node === 3) {
|
||||
typeCondition = {
|
||||
orgChild3Id: body.nodeId,
|
||||
orgChild4Id: IsNull(),
|
||||
current_holder: body.isBlank == true ? IsNull() : Not(IsNull()),
|
||||
};
|
||||
} else if (body.node === 4) {
|
||||
typeCondition = {
|
||||
orgChild4Id: body.nodeId,
|
||||
current_holder: body.isBlank == true ? IsNull() : Not(IsNull()),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (body.node === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.nodeId,
|
||||
current_holder: body.isBlank == true ? IsNull() : Not(IsNull()),
|
||||
};
|
||||
} else if (body.node === 1) {
|
||||
typeCondition = {
|
||||
orgChild1Id: body.nodeId,
|
||||
current_holder: body.isBlank == true ? IsNull() : Not(IsNull()),
|
||||
};
|
||||
} else if (body.node === 2) {
|
||||
typeCondition = {
|
||||
orgChild2Id: body.nodeId,
|
||||
current_holder: body.isBlank == true ? IsNull() : Not(IsNull()),
|
||||
};
|
||||
} else if (body.node === 3) {
|
||||
typeCondition = {
|
||||
orgChild3Id: body.nodeId,
|
||||
current_holder: body.isBlank == true ? IsNull() : Not(IsNull()),
|
||||
};
|
||||
} else if (body.node === 4) {
|
||||
typeCondition = {
|
||||
orgChild4Id: body.nodeId,
|
||||
current_holder: body.isBlank == true ? IsNull() : Not(IsNull()),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||
|
|
@ -2741,41 +2567,26 @@ export class PositionController extends Controller {
|
|||
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
|
||||
.where(typeCondition)
|
||||
.leftJoinAndSelect("posMaster.positions", "positions")
|
||||
.leftJoinAndSelect("positions.posType", "posType")
|
||||
.leftJoinAndSelect("positions.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.andWhere(typeCondition).andWhere(conditionA == null ? "1=1" : conditionA, {
|
||||
posType: `${body.posType}`,
|
||||
posLevel: `${body.posLevel}`,
|
||||
posTypeRank: posType == null ? 0 : posType.posTypeRank,
|
||||
posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("posMaster.posMasterOrder", "ASC")
|
||||
.getManyAndCount();
|
||||
|
||||
const formattedData = await Promise.all(
|
||||
posMaster.map(async (posMaster) => {
|
||||
const positions = await this.positionRepository.find({
|
||||
where: {
|
||||
posMasterId: posMaster.id,
|
||||
},
|
||||
relations: ["posLevel", "posType", "posExecutive"],
|
||||
});
|
||||
|
||||
let profile: any;
|
||||
const chkRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: posMaster.orgRevisionId },
|
||||
});
|
||||
if (chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft) {
|
||||
profile = await this.profileRepository.findOne({
|
||||
where: { id: String(posMaster.current_holderId) },
|
||||
});
|
||||
} else if (!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft) {
|
||||
profile = await this.profileRepository.findOne({
|
||||
where: { id: String(posMaster.next_holderId) },
|
||||
});
|
||||
}
|
||||
const type = await this.posTypeRepository.findOne({
|
||||
where: { id: String(profile?.posTypeId) },
|
||||
});
|
||||
const level = await this.posLevelRepository.findOne({
|
||||
where: { id: String(profile?.posLevelId) },
|
||||
});
|
||||
|
||||
let shortName = "";
|
||||
|
||||
if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id == null &&
|
||||
|
|
@ -2828,21 +2639,10 @@ export class PositionController extends Controller {
|
|||
posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
||||
posMasterNo: posMaster.posMasterNo,
|
||||
posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
||||
fullNameCurrentHolder:
|
||||
posMaster.current_holder == null
|
||||
? null
|
||||
: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`,
|
||||
fullNameNextHolder:
|
||||
posMaster.next_holder == null
|
||||
? null
|
||||
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
|
||||
orgShortname: shortName,
|
||||
isSit: posMaster.isSit,
|
||||
profilePosition: profile == null || profile.position == null ? null : profile.position,
|
||||
profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName,
|
||||
profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName,
|
||||
isPosition: positions.filter((x) => x.positionName == body.position).length > 0,
|
||||
positions: positions.map((position) => ({
|
||||
isPosition: posMaster.positions.filter((x) => x.positionName == body.position).length > 0,
|
||||
positions: posMaster.positions.map((position) => ({
|
||||
id: position.id,
|
||||
positionName: position.positionName,
|
||||
positionField: position.positionField,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue