diff --git a/src/controllers/KpiPlanController.ts b/src/controllers/KpiPlanController.ts index b482844..e0b08fc 100644 --- a/src/controllers/KpiPlanController.ts +++ b/src/controllers/KpiPlanController.ts @@ -618,6 +618,118 @@ export class kpiPlanController extends Controller { return new HttpSuccess({ data: kpiPlan, total }); } + /** + * API list ตัวชี้วัดตามแผนฯ + * @param page + * @param pageSize + * @param keyword + */ + @Post("search-kpi-plan") + async searchKpiPlan( + @Request() request: RequestWithUser, + @Body() + requestBody: { + page: number; + pageSize: number; + year?: string | null; + period?: string | null; + nodeId?: string | null; + node?: number | null; + keyword?: string | null; + isAll?: boolean | false; + // isNull?: boolean | false; + }, + ) { + let _data = await new permission().PermissionList(request, "SYS_KPI_LIST"); + let condition = ""; + let parameters: any = {}; + if (requestBody.isAll === false) { + switch (requestBody.node) { + case 0: + condition = "kpiPlan.rootId LIKE :nodeId AND kpiPlan.child1Id IS NULL"; + break; + case 1: + condition = "kpiPlan.child1Id LIKE :nodeId AND kpiPlan.child2Id IS NULL"; + break; + case 2: + condition = "kpiPlan.child2Id LIKE :nodeId AND kpiPlan.child3Id IS NULL"; + break; + case 3: + condition = "kpiPlan.child3Id LIKE :nodeId AND kpiPlan.child4Id IS NULL"; + break; + case 4: + condition = "kpiPlan.child4Id LIKE :nodeId"; + break; + default: + condition = "1=1"; + break; + } + parameters.nodeId = `%${requestBody.nodeId}%`; + } else { + switch (requestBody.node) { + case 0: + condition = "kpiPlan.rootId LIKE :nodeId"; + break; + case 1: + condition = "kpiPlan.child1Id LIKE :nodeId"; + break; + case 2: + condition = "kpiPlan.child2Id LIKE :nodeId"; + break; + case 3: + condition = "kpiPlan.child3Id LIKE :nodeId"; + break; + case 4: + condition = "kpiPlan.child4Id LIKE :nodeId"; + break; + default: + condition = "1=1"; + break; + } + parameters.nodeId = `%${requestBody.nodeId}%`; + } + const [kpiPlan, total] = await AppDataSource.getRepository(KpiPlan) + .createQueryBuilder("kpiPlan") + .leftJoinAndSelect("kpiPlan.kpiPeriod", "kpiPeriod") + .andWhere(condition, parameters) + .andWhere(requestBody.year ? "kpiPlan.year LIKE :year" : "1=1", { + year: `%${requestBody.year}%`, + }) + .andWhere(requestBody.period ? "kpiPlan.period LIKE :period" : "1=1", { + period: `%${requestBody.period}%`, + }) + .andWhere( + new Brackets((qb) => { + qb.orWhere("kpiPlan.including LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiPlan.includingName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiPlan.year LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiPlan.period LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }); + }), + ) + .select([ + "kpiPlan.id", + "kpiPeriod.year", + "kpiPeriod.durationKPI", + "kpiPlan.including", + "kpiPlan.includingName", + "kpiPlan.createdAt", + ]) + .orderBy("kpiPlan.createdAt", "DESC") + .skip((requestBody.page - 1) * requestBody.pageSize) + .take(requestBody.pageSize) + .getManyAndCount(); + + return new HttpSuccess({ data: kpiPlan, total }); + } + /** * API list ตัวชี้วัดตามแผนฯ * @param page diff --git a/src/controllers/KpiRoleController.ts b/src/controllers/KpiRoleController.ts index 99da223..86df23f 100644 --- a/src/controllers/KpiRoleController.ts +++ b/src/controllers/KpiRoleController.ts @@ -552,6 +552,121 @@ export class kpiRoleController extends Controller { return new HttpSuccess({ data: kpiRole, total }); } + /** + * API list ตัวชี้วัดตามตำแหน่ง + * @param page + * @param pageSize + * @param keyword + */ + @Post("search-kpi-role") + async searchKpiRole( + @Request() request: RequestWithUser, + @Body() + requestBody: { + page: number; + pageSize: number; + year?: string | null; + period?: string | null; + nodeId?: string | null; + node?: number | null; + position?: string | null; + keyword?: string | null; + isAll?: boolean | false; + }, + ) { + let _data = await new permission().PermissionList(request, "SYS_KPI_LIST"); + let condition = ""; + let parameters: any = {}; + if (requestBody.isAll === false) { + switch (requestBody.node) { + case 0: + condition = "kpiRole.rootId LIKE :nodeId AND kpiRole.child1Id IS NULL"; + break; + case 1: + condition = "kpiRole.child1Id LIKE :nodeId AND kpiRole.child2Id IS NULL"; + break; + case 2: + condition = "kpiRole.child2Id LIKE :nodeId AND kpiRole.child3Id IS NULL"; + break; + case 3: + condition = "kpiRole.child3Id LIKE :nodeId AND kpiRole.child4Id IS NULL"; + break; + case 4: + condition = "kpiRole.child4Id LIKE :nodeId"; + break; + default: + condition = "1=1"; + break; + } + parameters.nodeId = `%${requestBody.nodeId}%`; + } else { + switch (requestBody.node) { + case 0: + condition = "kpiRole.rootId LIKE :nodeId"; + break; + case 1: + condition = "kpiRole.child1Id LIKE :nodeId"; + break; + case 2: + condition = "kpiRole.child2Id LIKE :nodeId"; + break; + case 3: + condition = "kpiRole.child3Id LIKE :nodeId"; + break; + case 4: + condition = "kpiRole.child4Id LIKE :nodeId"; + break; + default: + condition = "1=1"; + break; + } + parameters.nodeId = `%${requestBody.nodeId}%`; + } + const [kpiRole, total] = await AppDataSource.getRepository(KpiRole) + .createQueryBuilder("kpiRole") + .leftJoinAndSelect("kpiRole.kpiPeriod", "kpiPeriod") + .andWhere(condition, parameters) + .andWhere(requestBody.year ? "kpiRole.year LIKE :year" : "1=1", { + year: `%${requestBody.year}%`, + }) + .andWhere(requestBody.period ? "kpiRole.period LIKE :period" : "1=1", { + period: `%${requestBody.period}%`, + }) + .andWhere(requestBody.position != undefined ? "kpiRole.position LIKE :position" : "1=1", { + position: `%${requestBody.position}%`, + }) + .andWhere( + new Brackets((qb) => { + qb.orWhere("kpiRole.including LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiRole.includingName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiRole.year LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiRole.period LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }); + }), + ) + .select([ + "kpiRole.id", + "kpiPeriod.year", + "kpiPeriod.durationKPI", + "kpiRole.including", + "kpiRole.includingName", + "kpiRole.createdAt", + ]) + .orderBy("kpiRole.createdAt", "DESC") + .skip((requestBody.page - 1) * requestBody.pageSize) + .take(requestBody.pageSize) + .getManyAndCount(); + + return new HttpSuccess({ data: kpiRole, total }); + } + /** * API list ตัวชี้วัดตามตำแหน่ง * @param page diff --git a/src/controllers/KpiSpecialController.ts b/src/controllers/KpiSpecialController.ts index 574543b..6e626a9 100644 --- a/src/controllers/KpiSpecialController.ts +++ b/src/controllers/KpiSpecialController.ts @@ -261,6 +261,58 @@ export class kpiSpecialController extends Controller { return new HttpSuccess({ data: kpiSpecial, total }); } + /** + * API list ตัวชี้วัด Special + * @param page + * @param pageSize + * @param keyword + */ + @Post("search-kpi-special") + async searchKpiSpecial( + @Request() request: RequestWithUser, + @Body() + requestBody: { + page: number; + pageSize: number; + year?: string | null; + period?: string | null; + keyword?: string | null; + }, + ) { + let _data = await new permission().PermissionList(request, "SYS_KPI_LIST"); + const [kpiSpecial, total] = await AppDataSource.getRepository(KpiSpecial) + .createQueryBuilder("kpiSpecial") + .andWhere(requestBody.year ? "kpiSpecial.year LIKE :year" : "1=1", { + year: `%${requestBody.year}%`, + }) + .andWhere(requestBody.period ? "kpiSpecial.period LIKE :period" : "1=1", { + period: `%${requestBody.period}%`, + }) + .andWhere( + new Brackets((qb) => { + qb.orWhere("kpiSpecial.including LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }).orWhere("kpiSpecial.includingName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }); + }), + ) + .select([ + "kpiSpecial.id", + "kpiSpecial.year", + "kpiSpecial.period", + "kpiSpecial.including", + "kpiSpecial.includingName", + "kpiSpecial.createdAt", + ]) + .orderBy("kpiSpecial.createdAt", "DESC") + .skip((requestBody.page - 1) * requestBody.pageSize) + .take(requestBody.pageSize) + .getManyAndCount(); + + return new HttpSuccess({ data: kpiSpecial, total }); + } + /** * API list ตัวชี้วัด Special * @param page