คิวรี่ลูกจ้าง
This commit is contained in:
parent
124e6ea1d7
commit
7a2ed91612
1 changed files with 98 additions and 16 deletions
|
|
@ -192,24 +192,106 @@ export class ProfileEmployeeController extends Controller {
|
|||
async listProfile(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query() searchField?: "firstName" | "lastName" | "citizenId" | "position",
|
||||
@Query() searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position",
|
||||
@Query() searchKeyword: string = "",
|
||||
@Query() posType?: string,
|
||||
@Query() posLevel?: string,
|
||||
@Query() yearLeave?: number,
|
||||
@Query() isProbation?: boolean,
|
||||
@Query() isRetire?: boolean,
|
||||
) {
|
||||
const [record, total] = await this.profileRepo.findAndCount({
|
||||
relations: {
|
||||
posLevel: true,
|
||||
posType: true,
|
||||
// gender: true,
|
||||
// relationship: true,
|
||||
// bloodGroup: true,
|
||||
},
|
||||
where:
|
||||
searchField && searchKeyword ? [{ [searchField]: Like(`%${searchKeyword}%`) }] : undefined,
|
||||
order: { createdAt: "ASC" },
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
});
|
||||
return new HttpSuccess({ data: record, total });
|
||||
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";
|
||||
}
|
||||
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.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
||||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||
.andWhere(
|
||||
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
|
||||
? queryLike
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${searchKeyword}%`,
|
||||
},
|
||||
)
|
||||
.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 == true
|
||||
? `profile.dateRetire IS null`
|
||||
: `profile.dateRetire IS NOT NULL`
|
||||
: "1=1",
|
||||
)
|
||||
.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[0].orgChild4 != null
|
||||
? `${_data.current_holders[0].orgChild4.orgChild4ShortName}${_data.current_holders[0].posMasterNo}`
|
||||
: _data.current_holders[0].orgChild3 != null
|
||||
? `${_data.current_holders[0].orgChild3.orgChild3ShortName}${_data.current_holders[0].posMasterNo}`
|
||||
: _data.current_holders[0].orgChild2 != null
|
||||
? `${_data.current_holders[0].orgChild2.orgChild2ShortName}${_data.current_holders[0].posMasterNo}`
|
||||
: _data.current_holders[0].orgChild1 != null
|
||||
? `${_data.current_holders[0].orgChild1.orgChild1ShortName}${_data.current_holders[0].posMasterNo}`
|
||||
: _data.current_holders[0].orgRoot != null
|
||||
? `${_data.current_holders[0].orgRoot.orgRootShortName}${_data.current_holders[0].posMasterNo}`
|
||||
: null;
|
||||
return {
|
||||
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,
|
||||
posTypeShortName: _data.posType == null ? null : _data.posType.posTypeShortName,
|
||||
posLevelId: _data.posLevel == null ? null : _data.posLevel.id,
|
||||
posTypeId: _data.posType == null ? null : _data.posType.id,
|
||||
position: _data.position,
|
||||
posNo: shortName,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess({ data: data, total });
|
||||
}
|
||||
|
||||
@Get("history/{id}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue