คิวรี่ลูกจ้าง
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(
|
async listProfile(
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query() searchField?: "firstName" | "lastName" | "citizenId" | "position",
|
@Query() searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position",
|
||||||
@Query() searchKeyword: string = "",
|
@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({
|
let queryLike =
|
||||||
relations: {
|
"CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword";
|
||||||
posLevel: true,
|
if (searchField == "citizenId") {
|
||||||
posType: true,
|
queryLike = "profileEmployee.citizenId LIKE :keyword";
|
||||||
// gender: true,
|
} else if (searchField == "position") {
|
||||||
// relationship: true,
|
queryLike = "profileEmployee.position LIKE :keyword";
|
||||||
// bloodGroup: true,
|
}
|
||||||
},
|
const [record, total] = await this.profileRepo
|
||||||
where:
|
.createQueryBuilder("profileEmployee")
|
||||||
searchField && searchKeyword ? [{ [searchField]: Like(`%${searchKeyword}%`) }] : undefined,
|
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
|
||||||
order: { createdAt: "ASC" },
|
.leftJoinAndSelect("profileEmployee.posType", "posType")
|
||||||
skip: (page - 1) * pageSize,
|
.leftJoinAndSelect("profileEmployee.current_holders", "current_holders")
|
||||||
take: pageSize,
|
.leftJoinAndSelect("current_holders.positions", "positions")
|
||||||
});
|
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
||||||
return new HttpSuccess({ data: record, total });
|
.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}")
|
@Get("history/{id}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue