no message
This commit is contained in:
parent
dc88a80904
commit
d083689f68
4 changed files with 256 additions and 215 deletions
|
|
@ -64,6 +64,7 @@ import permission from "../interfaces/permission";
|
|||
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||
import axios from "axios";
|
||||
import { OrgChild1 } from "../entities/OrgChild1";
|
||||
import { viewCommanderDirector } from "../entities/view/viewCommanderDirector";
|
||||
@Route("api/v1/org/profile")
|
||||
@Tags("Profile")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -103,6 +104,7 @@ export class ProfileController extends Controller {
|
|||
private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave);
|
||||
private posMasterActRepository = AppDataSource.getRepository(PosMasterAct);
|
||||
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
|
||||
private viewCommanderDirectorRepository = AppDataSource.getRepository(viewCommanderDirector);
|
||||
|
||||
/**
|
||||
* report ประวัติแบบย่อ ข้าราชการ
|
||||
|
|
@ -1229,9 +1231,9 @@ export class ProfileController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Post("commander-director")
|
||||
async getProfileCommanderDirector(
|
||||
public async getProfileCommanderDirector(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body() body: { isDirector: boolean; page: number; pageSize: number; keyword: string },
|
||||
@Body() body: { isDirector: boolean; keyword: string; page: number; pageSize: number },
|
||||
) {
|
||||
const posMaster = await this.posMasterRepo.findOne({
|
||||
where: {
|
||||
|
|
@ -1240,221 +1242,75 @@ export class ProfileController extends Controller {
|
|||
},
|
||||
});
|
||||
if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการครองตำแหน่ง");
|
||||
|
||||
let condition: any = {
|
||||
orgRootId: posMaster.orgRootId || "",
|
||||
};
|
||||
if (body.isDirector == true) {
|
||||
const [_posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("current_holder.posType", "posType")
|
||||
.where({
|
||||
orgRootId: posMaster.orgRootId || "",
|
||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||
isDirector: true,
|
||||
current_holderId: Not(IsNull()),
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "CONCAT(current_holder.prefix, current_holder.firstName, ' ', current_holder.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "current_holder.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "current_holder.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "posLevel.posLevelName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "posType.posTypeName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.select([
|
||||
"posMaster.current_holderId",
|
||||
"current_holder.prefix",
|
||||
"current_holder.firstName",
|
||||
"current_holder.lastName",
|
||||
"current_holder.citizenId",
|
||||
"current_holder.position",
|
||||
"current_holder.posLevel",
|
||||
"posLevel.posLevelName",
|
||||
"current_holder.posType",
|
||||
"posType.posTypeName",
|
||||
"posMaster.isDirector",
|
||||
])
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const posMasterActs = await this.posMasterActRepository.find({
|
||||
where: {
|
||||
posMasterId: In(_posMaster.map((x) => x.id)),
|
||||
posMasterChild: {
|
||||
current_holderId: Not(In(_posMaster.map((x) => x.current_holderId))),
|
||||
},
|
||||
},
|
||||
relations: [
|
||||
"posMaster",
|
||||
"posMaster.current_holder",
|
||||
"posMasterChild",
|
||||
"posMasterChild.current_holder",
|
||||
"posMasterChild.current_holder.posLevel",
|
||||
"posMasterChild.current_holder.posType",
|
||||
],
|
||||
});
|
||||
let data = _posMaster.map((_data) => ({
|
||||
id: _data.current_holderId || null,
|
||||
prefix: _data.current_holder?.prefix || "",
|
||||
firstName: _data.current_holder?.firstName || "",
|
||||
lastName: _data.current_holder?.lastName || "",
|
||||
citizenId: _data.current_holder?.citizenId || "",
|
||||
position: _data.current_holder?.position || "",
|
||||
posLevel:
|
||||
_data.current_holder?.posLevel == null
|
||||
? null
|
||||
: _data.current_holder?.posLevel?.posLevelName || "",
|
||||
posType:
|
||||
_data.current_holder?.posType == null
|
||||
? null
|
||||
: _data.current_holder?.posType?.posTypeName || "",
|
||||
isDirector: _data.isDirector || false,
|
||||
actFullName: null,
|
||||
}));
|
||||
posMasterActs.map((x) => {
|
||||
let item: any = {
|
||||
id: x.posMasterChild?.current_holderId || null,
|
||||
prefix: x.posMasterChild?.current_holder?.prefix || "",
|
||||
firstName: x.posMasterChild?.current_holder?.firstName || "",
|
||||
lastName: x.posMasterChild?.current_holder?.lastName || "",
|
||||
citizenId: x.posMasterChild?.current_holder?.citizenId || "",
|
||||
position: x.posMasterChild?.current_holder?.position || "",
|
||||
posLevel: x.posMasterChild?.current_holder?.posLevel?.posLevelName || "",
|
||||
posType: x.posMasterChild?.current_holder?.posType?.posTypeName || "",
|
||||
isDirector: x.posMasterChild?.isDirector || true,
|
||||
actFullName: `${x.posMaster?.current_holder?.prefix || ""}${x.posMaster?.current_holder?.firstName || ""} ${x.posMaster?.current_holder?.lastName || ""}`,
|
||||
};
|
||||
data.push(item);
|
||||
});
|
||||
return new HttpSuccess({ data, total });
|
||||
} else {
|
||||
const [_posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("current_holder.posType", "posType")
|
||||
.where({
|
||||
orgRootId: posMaster.orgRootId || "",
|
||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||
current_holderId: Not(IsNull()),
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "CONCAT(current_holder.prefix, current_holder.firstName, ' ', current_holder.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "current_holder.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "current_holder.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "posLevel.posLevelName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.where(
|
||||
body.keyword != undefined && body.keyword != null && body.keyword != ""
|
||||
? "posType.posTypeName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.select([
|
||||
"posMaster.current_holderId",
|
||||
"current_holder.prefix",
|
||||
"current_holder.firstName",
|
||||
"current_holder.lastName",
|
||||
"current_holder.citizenId",
|
||||
"current_holder.position",
|
||||
"current_holder.posLevel",
|
||||
"posLevel.posLevelName",
|
||||
"current_holder.posType",
|
||||
"posType.posTypeName",
|
||||
"posMaster.isDirector",
|
||||
])
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
let data = _posMaster.map((_data) => ({
|
||||
id: _data.current_holderId || null,
|
||||
prefix: _data.current_holder?.prefix || "",
|
||||
firstName: _data.current_holder?.firstName || "",
|
||||
lastName: _data.current_holder?.lastName || "",
|
||||
citizenId: _data.current_holder?.citizenId || "",
|
||||
position: _data.current_holder?.position || "",
|
||||
posLevel:
|
||||
_data.current_holder?.posLevel == null
|
||||
? null
|
||||
: _data.current_holder?.posLevel?.posLevelName || "",
|
||||
posType:
|
||||
_data.current_holder?.posType == null
|
||||
? null
|
||||
: _data.current_holder?.posType?.posTypeName || "",
|
||||
isDirector: _data.isDirector || false,
|
||||
actFullName: null,
|
||||
}));
|
||||
return new HttpSuccess({ data, total });
|
||||
condition = {
|
||||
orgRootId: posMaster.orgRootId || "",
|
||||
isDirector: true,
|
||||
};
|
||||
}
|
||||
const [lists, total] = await AppDataSource.getRepository(viewCommanderDirector)
|
||||
.createQueryBuilder("viewCommanderDirector")
|
||||
.andWhere(condition)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "CONCAT(viewCommanderDirector.prefix,viewCommanderDirector.firstName,' ',viewCommanderDirector.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewCommanderDirector.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewCommanderDirector.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewCommanderDirector.posLevel LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewCommanderDirector.posType LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewCommanderDirector.actFullName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
return new HttpSuccess({ data: lists, total });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue