From 9d46cd2e784a5de1cabe65150b5eb7dc6194fd25 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 18 Dec 2024 17:14:30 +0700 Subject: [PATCH] =?UTF-8?q?fix=20bug=20=E0=B8=A3=E0=B8=B0=E0=B8=9A?= =?UTF-8?q?=E0=B8=9A=E0=B8=97=E0=B8=94=E0=B8=A5=E0=B8=AD=E0=B8=87=E0=B8=9B?= =?UTF-8?q?=E0=B8=8F=E0=B8=B4=E0=B8=9A=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=AB?= =?UTF-8?q?=E0=B8=99=E0=B9=89=E0=B8=B2=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=8A=E0=B8=81=E0=B8=B2=E0=B8=A3=20#863?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 44 +------- src/entities/view/viewDirector.ts | 7 +- .../1734516306284-updateViewTable.ts | 105 ++++++++++++++++++ 3 files changed, 112 insertions(+), 44 deletions(-) create mode 100644 src/migration/1734516306284-updateViewTable.ts diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 4fcf2077..1746b521 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1384,14 +1384,6 @@ export class ProfileController extends Controller { 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" @@ -1400,22 +1392,6 @@ export class ProfileController extends Controller { 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" @@ -1479,7 +1455,7 @@ export class ProfileController extends Controller { ) .orWhere( body.keyword != null && body.keyword != "" - ? "viewDirector.citizenId LIKE :keyword" + ? "viewDirector.position LIKE :keyword" : "1=1", { keyword: `%${body.keyword}%`, @@ -1487,28 +1463,12 @@ export class ProfileController extends Controller { ) .orWhere( body.keyword != null && body.keyword != "" - ? "viewDirector.position LIKE :keyword" + ? "viewDirector.actFullName 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}%`, - // }, - // ) .orWhere( body.keyword != null && body.keyword != "" ? "CONCAT(viewDirector.posType, ' (', viewDirector.posLevel, ')') LIKE :keyword" diff --git a/src/entities/view/viewDirector.ts b/src/entities/view/viewDirector.ts index de3953e7..a95b5bba 100644 --- a/src/entities/view/viewDirector.ts +++ b/src/entities/view/viewDirector.ts @@ -27,8 +27,11 @@ import { ViewColumn, ViewEntity } from "typeorm"; \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, CONCAT(\`posMaster\`.\`id\`, \`profile\`.\`id\`) AS \`key\`, - NULL AS \`actFullNameId\`, - NULL AS \`actFullName\` + \`profile\`.\`id\` AS \`actFullNameId\`, + CONCAT(\`profile\`.\`prefix\`, + \`profile\`.\`firstName\`, + ' ', + \`profile\`.\`lastName\`) AS \`actFullName\` FROM ((((((((((\`posMaster\` JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) diff --git a/src/migration/1734516306284-updateViewTable.ts b/src/migration/1734516306284-updateViewTable.ts new file mode 100644 index 00000000..3ce9dee6 --- /dev/null +++ b/src/migration/1734516306284-updateViewTable.ts @@ -0,0 +1,105 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateViewTable1734516306284 implements MigrationInterface { + name = 'UpdateViewTable1734516306284' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_director","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_director\``); + await queryRunner.query(`CREATE VIEW \`view_director\` AS SELECT + \`profile\`.\`id\` AS \`Id\`, + \`profile\`.\`prefix\` AS \`prefix\`, + \`profile\`.\`firstName\` AS \`firstName\`, + \`profile\`.\`lastName\` AS \`lastName\`, + \`profile\`.\`citizenId\` AS \`citizenId\`, + \`profile\`.\`position\` AS \`position\`, + CONCAT((CASE + WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRoot\`.\`orgRootShortName\` + WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1\`.\`orgChild1ShortName\` + WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2\`.\`orgChild2ShortName\` + WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3\`.\`orgChild3ShortName\` + ELSE \`orgChild4\`.\`orgChild4ShortName\` + END), + \`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`posType\`.\`posTypeName\` AS \`posType\`, + \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`, + \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`posMaster\`.\`id\`, \`profile\`.\`id\`) AS \`key\`, + \`profile\`.\`id\` AS \`actFullNameId\`, + CONCAT(\`profile\`.\`prefix\`, + \`profile\`.\`firstName\`, + ' ', + \`profile\`.\`lastName\`) AS \`actFullName\` + FROM + ((((((((((\`posMaster\` + JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) + LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`))) + LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`))) + LEFT JOIN \`orgChild2\` ON ((\`posMaster\`.\`orgChild2Id\` = \`orgChild2\`.\`id\`))) + LEFT JOIN \`orgChild3\` ON ((\`posMaster\`.\`orgChild3Id\` = \`orgChild3\`.\`id\`))) + LEFT JOIN \`orgChild4\` ON ((\`posMaster\`.\`orgChild4Id\` = \`orgChild4\`.\`id\`))) + JOIN \`posLevel\` ON ((\`profile\`.\`posLevelId\` = \`posLevel\`.\`id\`))) + JOIN \`posType\` ON ((\`profile\`.\`posTypeId\` = \`posType\`.\`id\`))) + LEFT JOIN \`position\` ON ((\`posMaster\`.\`id\` = \`position\`.\`posMasterId\`))) + LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`))) + WHERE + (\`position\`.\`positionIsSelected\` = TRUE)`); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_director","SELECT \n `profile`.`id` AS `Id`,\n `profile`.`prefix` AS `prefix`,\n `profile`.`firstName` AS `firstName`,\n `profile`.`lastName` AS `lastName`,\n `profile`.`citizenId` AS `citizenId`,\n `profile`.`position` AS `position`,\n CONCAT((CASE\n WHEN (`posMaster`.`orgChild1Id` IS NULL) THEN `orgRoot`.`orgRootShortName`\n WHEN (`posMaster`.`orgChild2Id` IS NULL) THEN `orgChild1`.`orgChild1ShortName`\n WHEN (`posMaster`.`orgChild3Id` IS NULL) THEN `orgChild2`.`orgChild2ShortName`\n WHEN (`posMaster`.`orgChild4Id` IS NULL) THEN `orgChild3`.`orgChild3ShortName`\n ELSE `orgChild4`.`orgChild4ShortName`\n END),\n `posMaster`.`posMasterNo`) AS `posNo`,\n `posMaster`.`isDirector` AS `isDirector`,\n `posLevel`.`posLevelName` AS `posLevel`,\n `posType`.`posTypeName` AS `posType`,\n `posExecutive`.`posExecutiveName` AS `posExecutiveName`,\n `orgRoot`.`isDeputy` AS `isDeputy`,\n `posMaster`.`orgRootId` AS `orgRootId`,\n `posMaster`.`orgChild1Id` AS `orgChild1Id`,\n `posMaster`.`orgChild2Id` AS `orgChild2Id`,\n `posMaster`.`orgChild3Id` AS `orgChild3Id`,\n `posMaster`.`orgChild4Id` AS `orgChild4Id`,\n CONCAT(`posMaster`.`id`, `profile`.`id`) AS `key`,\n `profile`.`id` AS `actFullNameId`,\n CONCAT(`profile`.`prefix`,\n `profile`.`firstName`,\n ' ',\n `profile`.`lastName`) AS `actFullName`\n FROM\n ((((((((((`posMaster`\n JOIN `profile` ON ((`posMaster`.`current_holderId` = `profile`.`id`)))\n LEFT JOIN `orgRoot` ON ((`posMaster`.`orgRootId` = `orgRoot`.`id`)))\n LEFT JOIN `orgChild1` ON ((`posMaster`.`orgChild1Id` = `orgChild1`.`id`)))\n LEFT JOIN `orgChild2` ON ((`posMaster`.`orgChild2Id` = `orgChild2`.`id`)))\n LEFT JOIN `orgChild3` ON ((`posMaster`.`orgChild3Id` = `orgChild3`.`id`)))\n LEFT JOIN `orgChild4` ON ((`posMaster`.`orgChild4Id` = `orgChild4`.`id`)))\n JOIN `posLevel` ON ((`profile`.`posLevelId` = `posLevel`.`id`)))\n JOIN `posType` ON ((`profile`.`posTypeId` = `posType`.`id`)))\n LEFT JOIN `position` ON ((`posMaster`.`id` = `position`.`posMasterId`)))\n LEFT JOIN `posExecutive` ON ((`position`.`posExecutiveId` = `posExecutive`.`id`)))\n WHERE\n (`position`.`positionIsSelected` = TRUE)"]); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_director","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_director\``); + await queryRunner.query(`CREATE VIEW \`view_director\` AS SELECT + \`profile\`.\`id\` AS \`Id\`, + \`profile\`.\`prefix\` AS \`prefix\`, + \`profile\`.\`firstName\` AS \`firstName\`, + \`profile\`.\`lastName\` AS \`lastName\`, + \`profile\`.\`citizenId\` AS \`citizenId\`, + \`profile\`.\`position\` AS \`position\`, + CONCAT((CASE + WHEN (\`posMaster\`.\`orgChild1Id\` IS NULL) THEN \`orgRoot\`.\`orgRootShortName\` + WHEN (\`posMaster\`.\`orgChild2Id\` IS NULL) THEN \`orgChild1\`.\`orgChild1ShortName\` + WHEN (\`posMaster\`.\`orgChild3Id\` IS NULL) THEN \`orgChild2\`.\`orgChild2ShortName\` + WHEN (\`posMaster\`.\`orgChild4Id\` IS NULL) THEN \`orgChild3\`.\`orgChild3ShortName\` + ELSE \`orgChild4\`.\`orgChild4ShortName\` + END), + \`posMaster\`.\`posMasterNo\`) AS \`posNo\`, + \`posMaster\`.\`isDirector\` AS \`isDirector\`, + \`posLevel\`.\`posLevelName\` AS \`posLevel\`, + \`posType\`.\`posTypeName\` AS \`posType\`, + \`posExecutive\`.\`posExecutiveName\` AS \`posExecutiveName\`, + \`orgRoot\`.\`isDeputy\` AS \`isDeputy\`, + \`posMaster\`.\`orgRootId\` AS \`orgRootId\`, + \`posMaster\`.\`orgChild1Id\` AS \`orgChild1Id\`, + \`posMaster\`.\`orgChild2Id\` AS \`orgChild2Id\`, + \`posMaster\`.\`orgChild3Id\` AS \`orgChild3Id\`, + \`posMaster\`.\`orgChild4Id\` AS \`orgChild4Id\`, + CONCAT(\`posMaster\`.\`id\`, \`profile\`.\`id\`) AS \`key\`, + NULL AS \`actFullNameId\`, + NULL AS \`actFullName\` + FROM + ((((((((((\`posMaster\` + JOIN \`profile\` ON ((\`posMaster\`.\`current_holderId\` = \`profile\`.\`id\`))) + LEFT JOIN \`orgRoot\` ON ((\`posMaster\`.\`orgRootId\` = \`orgRoot\`.\`id\`))) + LEFT JOIN \`orgChild1\` ON ((\`posMaster\`.\`orgChild1Id\` = \`orgChild1\`.\`id\`))) + LEFT JOIN \`orgChild2\` ON ((\`posMaster\`.\`orgChild2Id\` = \`orgChild2\`.\`id\`))) + LEFT JOIN \`orgChild3\` ON ((\`posMaster\`.\`orgChild3Id\` = \`orgChild3\`.\`id\`))) + LEFT JOIN \`orgChild4\` ON ((\`posMaster\`.\`orgChild4Id\` = \`orgChild4\`.\`id\`))) + JOIN \`posLevel\` ON ((\`profile\`.\`posLevelId\` = \`posLevel\`.\`id\`))) + JOIN \`posType\` ON ((\`profile\`.\`posTypeId\` = \`posType\`.\`id\`))) + LEFT JOIN \`position\` ON ((\`posMaster\`.\`id\` = \`position\`.\`posMasterId\`))) + LEFT JOIN \`posExecutive\` ON ((\`position\`.\`posExecutiveId\` = \`posExecutive\`.\`id\`))) + WHERE + (\`position\`.\`positionIsSelected\` = TRUE)`); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_director","SELECT \n `profile`.`id` AS `Id`,\n `profile`.`prefix` AS `prefix`,\n `profile`.`firstName` AS `firstName`,\n `profile`.`lastName` AS `lastName`,\n `profile`.`citizenId` AS `citizenId`,\n `profile`.`position` AS `position`,\n CONCAT((CASE\n WHEN (`posMaster`.`orgChild1Id` IS NULL) THEN `orgRoot`.`orgRootShortName`\n WHEN (`posMaster`.`orgChild2Id` IS NULL) THEN `orgChild1`.`orgChild1ShortName`\n WHEN (`posMaster`.`orgChild3Id` IS NULL) THEN `orgChild2`.`orgChild2ShortName`\n WHEN (`posMaster`.`orgChild4Id` IS NULL) THEN `orgChild3`.`orgChild3ShortName`\n ELSE `orgChild4`.`orgChild4ShortName`\n END),\n `posMaster`.`posMasterNo`) AS `posNo`,\n `posMaster`.`isDirector` AS `isDirector`,\n `posLevel`.`posLevelName` AS `posLevel`,\n `posType`.`posTypeName` AS `posType`,\n `posExecutive`.`posExecutiveName` AS `posExecutiveName`,\n `orgRoot`.`isDeputy` AS `isDeputy`,\n `posMaster`.`orgRootId` AS `orgRootId`,\n `posMaster`.`orgChild1Id` AS `orgChild1Id`,\n `posMaster`.`orgChild2Id` AS `orgChild2Id`,\n `posMaster`.`orgChild3Id` AS `orgChild3Id`,\n `posMaster`.`orgChild4Id` AS `orgChild4Id`,\n CONCAT(`posMaster`.`id`, `profile`.`id`) AS `key`,\n NULL AS `actFullNameId`,\n NULL AS `actFullName`\n FROM\n ((((((((((`posMaster`\n JOIN `profile` ON ((`posMaster`.`current_holderId` = `profile`.`id`)))\n LEFT JOIN `orgRoot` ON ((`posMaster`.`orgRootId` = `orgRoot`.`id`)))\n LEFT JOIN `orgChild1` ON ((`posMaster`.`orgChild1Id` = `orgChild1`.`id`)))\n LEFT JOIN `orgChild2` ON ((`posMaster`.`orgChild2Id` = `orgChild2`.`id`)))\n LEFT JOIN `orgChild3` ON ((`posMaster`.`orgChild3Id` = `orgChild3`.`id`)))\n LEFT JOIN `orgChild4` ON ((`posMaster`.`orgChild4Id` = `orgChild4`.`id`)))\n JOIN `posLevel` ON ((`profile`.`posLevelId` = `posLevel`.`id`)))\n JOIN `posType` ON ((`profile`.`posTypeId` = `posType`.`id`)))\n LEFT JOIN `position` ON ((`posMaster`.`id` = `position`.`posMasterId`)))\n LEFT JOIN `posExecutive` ON ((`position`.`posExecutiveId` = `posExecutive`.`id`)))\n WHERE\n (`position`.`positionIsSelected` = TRUE)"]); + } + +}