เพิ่ม API ค้นหาคนครองจากโครงสร้างปัจจุบัน
This commit is contained in:
parent
66f81707d4
commit
cc7c5c26ae
1 changed files with 144 additions and 0 deletions
|
|
@ -6717,6 +6717,150 @@ export class ProfileController extends Controller {
|
||||||
return new HttpSuccess(mapData);
|
return new HttpSuccess(mapData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ค้นหารายชื่อไปครองตำแหน่งจากโครงสร้างปัจจุบัน
|
||||||
|
*
|
||||||
|
* @summary ค้นหารายชื่อไปครองตำแหน่งจากโครงสร้างปัจจุบัน
|
||||||
|
*/
|
||||||
|
@Post("search/current/person")
|
||||||
|
async searchProfileCurrentPerson(
|
||||||
|
@Body()
|
||||||
|
requestBody: {
|
||||||
|
position?: string | null;
|
||||||
|
posLevelId?: string | null;
|
||||||
|
posTypeId?: string | null;
|
||||||
|
page: number;
|
||||||
|
pageSize: number;
|
||||||
|
keyword?: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionIsCurrent: true,
|
||||||
|
orgRevisionIsDraft: false,
|
||||||
|
},
|
||||||
|
relations: ["posMasters"],
|
||||||
|
});
|
||||||
|
if (!orgRevision) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
|
||||||
|
}
|
||||||
|
const [profiles, total] = await this.profileRepo
|
||||||
|
.createQueryBuilder("profile")
|
||||||
|
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||||
|
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||||
|
.leftJoinAndSelect("profile.posType", "posType")
|
||||||
|
.where(
|
||||||
|
requestBody.position != null && requestBody.position != ""
|
||||||
|
? "profile.position LIKE :position"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
position: `%${requestBody.position}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere("profile.isLeave IS FALSE")
|
||||||
|
.andWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.where(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "profile.prefix LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "profile.firstName LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "profile.lastName LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "CONCAT(profile.prefix,profile.firstName,' ',profile.lastName) LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "CONCAT(profile.firstName,' ',profile.lastName) LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "profile.citizenId LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.andWhere(
|
||||||
|
requestBody.posTypeId != null && requestBody.posTypeId != ""
|
||||||
|
? "profile.posTypeId LIKE :posTypeId"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
posTypeId: `%${requestBody.posTypeId}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(
|
||||||
|
requestBody.posLevelId != null && requestBody.posLevelId != ""
|
||||||
|
? "profile.posLevelId LIKE :posLevelId"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
posLevelId: `%${requestBody.posLevelId}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.where("profile.id NOT IN (:...ids)", {
|
||||||
|
ids:
|
||||||
|
orgRevision.posMasters
|
||||||
|
.filter((x) => x.current_holderId != null)
|
||||||
|
.map((x) => x.current_holderId).length == 0
|
||||||
|
? ["zxc"]
|
||||||
|
: orgRevision.posMasters
|
||||||
|
.filter((x) => x.current_holderId != null)
|
||||||
|
.map((x) => x.current_holderId),
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.skip((requestBody.page - 1) * requestBody.pageSize)
|
||||||
|
.take(requestBody.pageSize)
|
||||||
|
.orderBy("posType.posTypeRank", "ASC")
|
||||||
|
.addOrderBy("posLevel.posLevelRank", "ASC")
|
||||||
|
.getManyAndCount();
|
||||||
|
|
||||||
|
const data = profiles.map((_data) => ({
|
||||||
|
id: _data.id,
|
||||||
|
prefix: _data.prefix,
|
||||||
|
rank: _data.rank,
|
||||||
|
firstName: _data.firstName,
|
||||||
|
lastName: _data.lastName,
|
||||||
|
citizenId: _data.citizenId,
|
||||||
|
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
|
||||||
|
posType: _data.posType == null ? null : _data.posType.posTypeName,
|
||||||
|
position: _data.position,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return new HttpSuccess({ data: data, total });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API ข้อมูลสิทธิ์การแก้ไขทะเบียนประวัติ
|
* API ข้อมูลสิทธิ์การแก้ไขทะเบียนประวัติ
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue