no message
This commit is contained in:
parent
b4f11cef1f
commit
80a245a033
4 changed files with 358 additions and 91 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Body, Controller, Get, Path, Post, Request, Route, Security, Tags } from "tsoa";
|
||||
import { Body, Controller, Get, Path, Post, Put, Request, Route, Security, Tags } from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
|
|
@ -15,10 +15,12 @@ import { MetaWorkflow } from "../entities/MetaWorkflow";
|
|||
import { MetaState } from "../entities/MetaState";
|
||||
import { MetaStateOperator } from "../entities/MetaStateOperator";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { In, IsNull, Not } from "typeorm";
|
||||
import { Brackets, In, IsNull, Not } from "typeorm";
|
||||
import { Assign } from "../entities/Assign";
|
||||
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||
import { getAllJSDocTagsOfKind } from "typescript";
|
||||
import { viewDirectorActing } from "../entities/view/viewDirectorActing";
|
||||
import { viewDirector } from "../entities/view/viewDirector";
|
||||
|
||||
@Route("api/v1/org/workflow")
|
||||
@Tags("Workflow")
|
||||
|
|
@ -715,32 +717,33 @@ export class WorkflowController extends Controller {
|
|||
*
|
||||
*
|
||||
*/
|
||||
@Get("commander/{type}")
|
||||
async getProfilePlacement(@Request() req: RequestWithUser, @Path() type: string) {
|
||||
@Put("commander/{type}")
|
||||
async getProfilePlacement(
|
||||
@Request() request: RequestWithUser,
|
||||
@Path() type: string,
|
||||
@Body()
|
||||
body: {
|
||||
isAct: boolean;
|
||||
keyword: string;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
},
|
||||
) {
|
||||
const posMasterUser = await this.posMasterRepo.findOne({
|
||||
where: {
|
||||
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
current_holder: { keycloak: req.user.sub },
|
||||
current_holder: { keycloak: request.user.sub },
|
||||
},
|
||||
relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"],
|
||||
});
|
||||
if (!posMasterUser || !posMasterUser.orgRootId)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบตำแหน่งผู้ใช้งาน");
|
||||
let _posMasters = [];
|
||||
let sortPosmaster: any = {
|
||||
|
||||
let condition: any = {
|
||||
where: {
|
||||
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
isDirector: true,
|
||||
current_holderId: Not(IsNull()),
|
||||
orgRootId: posMasterUser.orgRootId,
|
||||
},
|
||||
relations: [
|
||||
"current_holder",
|
||||
"current_holder.posLevel",
|
||||
"current_holder.posType",
|
||||
"positions",
|
||||
"positions.posExecutive",
|
||||
],
|
||||
};
|
||||
|
||||
if (type.trim().toLowerCase() == "OPERATE") {
|
||||
|
|
@ -755,24 +758,15 @@ export class WorkflowController extends Controller {
|
|||
(posMasterUser.current_holder.posType.posTypeName == "วิชาการ" &&
|
||||
posMasterUser.current_holder.posLevel.posLevelName == "ชำนาญการ")
|
||||
) {
|
||||
sortPosmaster = {
|
||||
condition = {
|
||||
where: {
|
||||
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
isDirector: true,
|
||||
current_holderId: Not(IsNull()),
|
||||
orgRootId: posMasterUser.orgRootId,
|
||||
orgChild1Id: IsNull(),
|
||||
orgChild2Id: IsNull(),
|
||||
orgChild3Id: IsNull(),
|
||||
orgChild4Id: IsNull(),
|
||||
},
|
||||
relations: [
|
||||
"current_holder",
|
||||
"current_holder.posLevel",
|
||||
"current_holder.posType",
|
||||
"positions",
|
||||
"positions.posExecutive",
|
||||
],
|
||||
};
|
||||
} else if (
|
||||
(posMasterUser.current_holder.posType.posTypeName == "ทั่วไป" &&
|
||||
|
|
@ -782,80 +776,133 @@ export class WorkflowController extends Controller {
|
|||
(posMasterUser.current_holder.posType.posTypeName == "อำนวยการ" &&
|
||||
posMasterUser.current_holder.posLevel.posLevelName == "ต้น")
|
||||
) {
|
||||
sortPosmaster = {
|
||||
condition = {
|
||||
where: {
|
||||
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
isDirector: true,
|
||||
current_holderId: Not(IsNull()),
|
||||
orgRoot: {
|
||||
isDeputy: true,
|
||||
},
|
||||
isDeputy: true,
|
||||
orgChild1Id: IsNull(),
|
||||
orgChild2Id: IsNull(),
|
||||
orgChild3Id: IsNull(),
|
||||
orgChild4Id: IsNull(),
|
||||
},
|
||||
relations: [
|
||||
"current_holder",
|
||||
"current_holder.posLevel",
|
||||
"current_holder.posType",
|
||||
"positions",
|
||||
"positions.posExecutive",
|
||||
],
|
||||
};
|
||||
} else {
|
||||
}
|
||||
}
|
||||
const posMasters = await this.posMasterRepo.find(sortPosmaster);
|
||||
_posMasters = posMasters.map((data) => ({
|
||||
id: data.current_holderId || null,
|
||||
prefix: data.current_holder?.prefix || null,
|
||||
firstName: data.current_holder?.firstName || null,
|
||||
lastName: data.current_holder?.lastName || null,
|
||||
position: data.current_holder?.position || null,
|
||||
posLevel: data.current_holder?.posLevel?.posLevelName || null,
|
||||
posType: data.current_holder?.posType?.posTypeName || null,
|
||||
posExecutiveName:
|
||||
data.positions?.filter((x) => x.positionIsSelected == true)[0]?.posExecutive
|
||||
?.posExecutiveName || null,
|
||||
actFullName: null,
|
||||
}));
|
||||
const posMasterActs = await this.posMasterActRepo.find({
|
||||
where: {
|
||||
posMasterId: In(posMasters.map((x) => x.id)),
|
||||
posMasterChild: {
|
||||
current_holderId: Not(In(posMasters.map((x) => x.current_holderId))),
|
||||
},
|
||||
},
|
||||
relations: [
|
||||
"posMaster",
|
||||
"posMaster.current_holder",
|
||||
"posMasterChild",
|
||||
"posMasterChild.positions",
|
||||
"posMasterChild.positions.posExecutive",
|
||||
"posMasterChild.current_holder",
|
||||
"posMasterChild.current_holder.posLevel",
|
||||
"posMasterChild.current_holder.posType",
|
||||
],
|
||||
});
|
||||
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 || "",
|
||||
position: x.posMasterChild?.current_holder?.position || "",
|
||||
posLevel: x.posMasterChild?.current_holder?.posLevel?.posLevelName || "",
|
||||
posType: x.posMasterChild?.current_holder?.posType?.posTypeName || "",
|
||||
posExecutiveName:
|
||||
x.posMasterChild?.positions?.filter((x) => x.positionIsSelected == true)[0]?.posExecutive
|
||||
?.posExecutiveName || "",
|
||||
actFullName: `${x.posMaster?.current_holder?.prefix || ""}${x.posMaster?.current_holder?.firstName || ""} ${x.posMaster?.current_holder?.lastName || ""}`,
|
||||
};
|
||||
_posMasters.push(item);
|
||||
});
|
||||
|
||||
return new HttpSuccess(_posMasters);
|
||||
if (body.isAct == true) {
|
||||
const [lists, total] = await AppDataSource.getRepository(viewDirectorActing)
|
||||
.createQueryBuilder("viewDirectorActing")
|
||||
.andWhere(condition)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "CONCAT(viewDirectorActing.prefix,viewDirectorActing.firstName,' ',viewDirectorActing.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewDirectorActing.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewDirectorActing.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewDirectorActing.posLevel LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewDirectorActing.posType LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewDirectorActing.actFullName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
return new HttpSuccess({ data: lists, total });
|
||||
} else {
|
||||
const [lists, total] = await AppDataSource.getRepository(viewDirector)
|
||||
.createQueryBuilder("viewDirector")
|
||||
.andWhere(condition)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "CONCAT(viewDirector.prefix,viewDirector.firstName,' ',viewDirector.lastName) LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewDirector.citizenId LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewDirector.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewDirector.posLevel LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "viewDirector.posType 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