From 33fc5bb82868c83148f411937f5287e4c876be9c Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 4 Jul 2025 17:08:29 +0700 Subject: [PATCH 1/4] =?UTF-8?q?Fix=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=87?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=20=E0=B8=81.=E0=B8=9E.7/=E0=B8=81.=E0=B8=81.?= =?UTF-8?q?1=20Issue=20#1436?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 4 ++++ src/controllers/ProfileEmployeeController.ts | 4 ++++ src/controllers/ProfileEmployeeTempController.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 9cc51e44..a51651ba 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1153,6 +1153,7 @@ export class ProfileController extends Controller { "commandNo", "positionCee", "amount", + "amountSpecial", "remark", ], where: { @@ -1176,6 +1177,8 @@ export class ProfileController extends Controller { : null, salary: item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, + special: + item.amountSpecial != null ? Extension.ToThaiNumber(item.amountSpecial.toLocaleString()) : null, rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, refAll: item.remark ? Extension.ToThaiNumber(item.remark) : null, positionLevel: item.positionLevel @@ -1202,6 +1205,7 @@ export class ProfileController extends Controller { position: "-", posNo: "-", salary: "-", + special: "-", rank: "-", refAll: "-", positionLevel: "-", diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index e76b6d37..9c9ad18d 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -1150,6 +1150,7 @@ export class ProfileEmployeeController extends Controller { "commandNo", "positionCee", "amount", + "amountSpecial", "remark", ], where: { @@ -1173,6 +1174,8 @@ export class ProfileEmployeeController extends Controller { : null, salary: item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, + special: + item.amountSpecial != null ? Extension.ToThaiNumber(item.amountSpecial.toLocaleString()) : null, rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, refAll: item.remark ? Extension.ToThaiNumber(item.remark) : null, positionLevel: item.positionLevel @@ -1199,6 +1202,7 @@ export class ProfileEmployeeController extends Controller { position: "-", posNo: "-", salary: "-", + special: "-", rank: "-", refAll: "-", positionLevel: "-", diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index a2e735b2..aa990fd9 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -670,6 +670,7 @@ export class ProfileEmployeeTempController extends Controller { "positionSalaryAmount", "commandNo", "amount", + "amountSpecial", "remark", ], where: { profileEmployeeId: id }, @@ -686,6 +687,8 @@ export class ProfileEmployeeTempController extends Controller { PosNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, Salary: item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, + Special: + item.amountSpecial != null ? Extension.ToThaiNumber(item.amountSpecial.toLocaleString()) : null, Rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, RefAll: item.remark ? Extension.ToThaiNumber(item.remark) : null, PositionLevel: @@ -709,6 +712,7 @@ export class ProfileEmployeeTempController extends Controller { Position: "-", PosNo: "-", Salary: "-", + Special: "-", Rank: "-", RefAll: "-", PositionLevel: "-", From 4fdd5e7d7d8d8b4a71ade880fcee2902851c6141 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 9 Jul 2025 12:58:03 +0700 Subject: [PATCH 2/4] =?UTF-8?q?Fix=20API=20List=E0=B8=A3=E0=B8=B2=E0=B8=A2?= =?UTF-8?q?=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=82=E0=B8=A3=E0=B8=81?= =?UTF-8?q?.=20=E0=B8=95=E0=B8=B2=E0=B8=A1=E0=B8=AA=E0=B8=B4=E0=B8=97?= =?UTF-8?q?=E0=B8=98=E0=B8=B4=E0=B9=8C=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationDotnetController.ts | 88 ++++++++++++++----- 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index a1ac4736..ae5129b6 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -4121,19 +4121,39 @@ export class OrganizationDotnetController extends Controller { if (body.role === "OWNER" || body.role === "CHILD") { switch (node) { case 0: - typeCondition = { orgRootId: body.nodeId }; + typeCondition = { + orgRoot: { + ancestorDNA: body.nodeId + } + }; break; case 1: - typeCondition = { orgChild1Id: body.nodeId }; + typeCondition = { + orgChild1: { + ancestorDNA: body.nodeId + } + }; break; case 2: - typeCondition = { orgChild2Id: body.nodeId }; + typeCondition = { + orgChild2: { + ancestorDNA: body.nodeId + } + }; break; case 3: - typeCondition = { orgChild3Id: body.nodeId }; + typeCondition = { + orgChild3: { + ancestorDNA: body.nodeId + } + }; break; case 4: - typeCondition = { orgChild4Id: body.nodeId }; + typeCondition = { + orgChild4: { + ancestorDNA: body.nodeId + } + }; break; case null: typeCondition = {}; @@ -4150,26 +4170,41 @@ export class OrganizationDotnetController extends Controller { switch (node) { case 0: typeCondition = { - orgRootId: body.nodeId, - orgChild1Id: IsNull(), + orgRoot: { + ancestorDNA: body.nodeId + }, + orgChild1: IsNull() }; break; case 1: typeCondition = { - orgChild1Id: body.nodeId, - orgChild2Id: IsNull(), + orgChild1: { + ancestorDNA: body.nodeId + }, + orgChild2: IsNull() }; break; case 2: typeCondition = { - orgChild2Id: body.nodeId, - orgChild3Id: IsNull(), + orgChild2: { + ancestorDNA: body.nodeId + }, + orgChild3: IsNull() }; break; case 3: typeCondition = { - orgChild3Id: body.nodeId, - orgChild4Id: IsNull(), + orgChild3: { + ancestorDNA: body.nodeId + }, + orgChild4: IsNull() + }; + break; + case 4: + typeCondition = { + orgChild4: { + ancestorDNA: body.nodeId + }, }; break; default: @@ -4211,7 +4246,7 @@ export class OrganizationDotnetController extends Controller { }); } let findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, }); if (body.revisionId) { @@ -4221,7 +4256,7 @@ export class OrganizationDotnetController extends Controller { } const profile_ = await Promise.all( - profile.map((item: Profile) => { + profile.map(async(item: Profile) => { const shortName = item.current_holders.length == 0 ? null @@ -4250,17 +4285,25 @@ export class OrganizationDotnetController extends Controller { const Oc = item.current_holders.length == 0 ? null - : body.node == 4 && item.current_holders[0].orgChild4 != null + : (node == 4 || node == null) && item.current_holders[0].orgChild4 != null ? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 3 && item.current_holders[0].orgChild3 != null + : (node == 3 || node == null) && item.current_holders[0].orgChild3 != null ? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 2 && item.current_holders[0].orgChild2 != null + : (node == 2 || node == null) && item.current_holders[0].orgChild2 != null ? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 1 && item.current_holders[0].orgChild1 != null + : (node == 1 || node == null) && item.current_holders[0].orgChild1 != null ? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 0 && item.current_holders[0].orgRoot != null + : (node == 0 || node == null) && item.current_holders[0].orgRoot != null ? `${item.current_holders[0].orgRoot.orgRootName}` : null; + + let _posMaster = await this.posMasterRepository.findOne({ + where: { + orgRevisionId: findRevision?.id, + current_holderId: item.id + } + }); + return { id: item.id, prefix: item.prefix, @@ -4273,6 +4316,11 @@ export class OrganizationDotnetController extends Controller { positionLevel: item.posLevel?.posLevelName ?? null, positionType: item.posType?.posTypeName ?? null, oc: Oc, + orgRootId: _posMaster?.orgRootId, + orgChild1Id: _posMaster?.orgChild1Id, + orgChild2Id: _posMaster?.orgChild2Id, + orgChild3Id: _posMaster?.orgChild3Id, + orgChild4Id: _posMaster?.orgChild4Id }; }), ); From 9cda6e176e70eda58cb63831c196ae1b4ba41832 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 9 Jul 2025 14:26:42 +0700 Subject: [PATCH 3/4] =?UTF-8?q?api=20list=20=E0=B8=A3=E0=B8=B2=E0=B8=A2?= =?UTF-8?q?=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=95=E0=B8=B2=E0=B8=A1?= =?UTF-8?q?=E0=B8=AA=E0=B8=B4=E0=B8=97=E0=B8=98=E0=B8=B4=E0=B9=8C=20admin?= =?UTF-8?q?=20=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=20order=20&=20=E0=B9=81?= =?UTF-8?q?=E0=B8=81=E0=B9=89=E0=B8=82=E0=B8=AD=E0=B8=87=E0=B8=A5=E0=B8=B9?= =?UTF-8?q?=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationDotnetController.ts | 154 ++++++++++++++---- 1 file changed, 125 insertions(+), 29 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index ae5129b6..332a6153 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -26,6 +26,7 @@ import { Position } from "../entities/Position"; import { Insignia } from "../entities/Insignia"; import { CreateProfileInsignia, ProfileInsignia } from "../entities/ProfileInsignia"; import { PosMaster } from "../entities/PosMaster"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosDict } from "../entities/EmployeePosDict"; import { calculateRetireLaw } from "../interfaces/utils"; import Extension from "../interfaces/extension"; @@ -44,6 +45,7 @@ export class OrganizationDotnetController extends Controller { private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); private positionRepository = AppDataSource.getRepository(Position); private posMasterRepository = AppDataSource.getRepository(PosMaster); + private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict); @@ -4164,7 +4166,9 @@ export class OrganizationDotnetController extends Controller { } } else if (body.role === "ROOT") { typeCondition = { - orgRootId: body.nodeId + orgRoot: { + ancestorDNA: body.nodeId + }, }; } else if (body.role === "NORMAL") { switch (node) { @@ -4225,6 +4229,26 @@ export class OrganizationDotnetController extends Controller { "current_holders.orgChild3", "current_holders.orgChild4", ], + order: { + current_holders: { + orgRoot: { + orgRootOrder: "ASC", + }, + orgChild1: { + orgChild1Order: "ASC", + }, + orgChild2: { + orgChild2Order: "ASC", + }, + orgChild3: { + orgChild3Order: "ASC", + }, + orgChild4: { + orgChild4Order: "ASC", + }, + posMasterNo: "ASC", + } + } }); if (body.isRetirement) { profile = await this.profileRepo.find({ @@ -4246,7 +4270,7 @@ export class OrganizationDotnetController extends Controller { }); } let findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } }); if (body.revisionId) { @@ -4285,15 +4309,15 @@ export class OrganizationDotnetController extends Controller { const Oc = item.current_holders.length == 0 ? null - : (node == 4 || node == null) && item.current_holders[0].orgChild4 != null + : item.current_holders[0].orgChild4 != null ? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : (node == 3 || node == null) && item.current_holders[0].orgChild3 != null + : item.current_holders[0].orgChild3 != null ? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : (node == 2 || node == null) && item.current_holders[0].orgChild2 != null + : item.current_holders[0].orgChild2 != null ? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : (node == 1 || node == null) && item.current_holders[0].orgChild1 != null + : item.current_holders[0].orgChild1 != null ? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : (node == 0 || node == null) && item.current_holders[0].orgRoot != null + : item.current_holders[0].orgRoot != null ? `${item.current_holders[0].orgRoot.orgRootName}` : null; @@ -4659,19 +4683,39 @@ export class OrganizationDotnetController extends Controller { if (body.role === "OWNER" || body.role === "CHILD") { switch (node) { case 0: - typeCondition = { orgRootId: body.nodeId }; + typeCondition = { + orgRoot: { + ancestorDNA: body.nodeId + } + }; break; case 1: - typeCondition = { orgChild1Id: body.nodeId }; + typeCondition = { + orgChild1: { + ancestorDNA: body.nodeId + } + }; break; case 2: - typeCondition = { orgChild2Id: body.nodeId }; + typeCondition = { + orgChild2: { + ancestorDNA: body.nodeId + } + }; break; case 3: - typeCondition = { orgChild3Id: body.nodeId }; + typeCondition = { + orgChild3: { + ancestorDNA: body.nodeId + } + }; break; case 4: - typeCondition = { orgChild4Id: body.nodeId }; + typeCondition = { + orgChild4: { + ancestorDNA: body.nodeId + } + }; break; case null: typeCondition = {}; @@ -4682,32 +4726,49 @@ export class OrganizationDotnetController extends Controller { } } else if (body.role === "ROOT") { typeCondition = { - orgRootId: body.nodeId + orgRoot: { + ancestorDNA: body.nodeId + }, }; } else if (body.role === "NORMAL") { switch (node) { case 0: typeCondition = { - orgRootId: body.nodeId, - orgChild1Id: IsNull(), + orgRoot: { + ancestorDNA: body.nodeId + }, + orgChild1: IsNull() }; break; case 1: typeCondition = { - orgChild1Id: body.nodeId, - orgChild2Id: IsNull(), + orgChild1: { + ancestorDNA: body.nodeId + }, + orgChild2: IsNull() }; break; case 2: typeCondition = { - orgChild2Id: body.nodeId, - orgChild3Id: IsNull(), + orgChild2: { + ancestorDNA: body.nodeId + }, + orgChild3: IsNull() }; break; case 3: typeCondition = { - orgChild3Id: body.nodeId, - orgChild4Id: IsNull(), + orgChild3: { + ancestorDNA: body.nodeId + }, + orgChild4: IsNull() + }; + break; + case 4: + typeCondition = { + orgChild4: { + ancestorDNA: body.nodeId + }, }; break; default: @@ -4728,6 +4789,26 @@ export class OrganizationDotnetController extends Controller { "current_holders.orgChild3", "current_holders.orgChild4", ], + order: { + current_holders: { + orgRoot: { + orgRootOrder: "ASC", + }, + orgChild1: { + orgChild1Order: "ASC", + }, + orgChild2: { + orgChild2Order: "ASC", + }, + orgChild3: { + orgChild3Order: "ASC", + }, + orgChild4: { + orgChild4Order: "ASC", + }, + posMasterNo: "ASC", + } + } }); if (body.isRetirement) { profile = await this.profileEmpRepo.find({ @@ -4749,7 +4830,7 @@ export class OrganizationDotnetController extends Controller { }); } let findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } }); if (body.revisionId) { @@ -4759,7 +4840,7 @@ export class OrganizationDotnetController extends Controller { } const profile_ = await Promise.all( - profile.map((item: ProfileEmployee) => { + profile.map(async(item: ProfileEmployee) => { const shortName = item.current_holders.length == 0 ? null @@ -4788,17 +4869,25 @@ export class OrganizationDotnetController extends Controller { const Oc = item.current_holders.length == 0 ? null - : body.node == 4 && item.current_holders[0].orgChild4 != null + : item.current_holders[0].orgChild4 != null ? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 3 && item.current_holders[0].orgChild3 != null + : item.current_holders[0].orgChild3 != null ? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 2 && item.current_holders[0].orgChild2 != null + : item.current_holders[0].orgChild2 != null ? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 1 && item.current_holders[0].orgChild1 != null + : item.current_holders[0].orgChild1 != null ? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 0 && item.current_holders[0].orgRoot != null + : item.current_holders[0].orgRoot != null ? `${item.current_holders[0].orgRoot.orgRootName}` : null; + + let _posMaster = await this.empPosMasterRepository.findOne({ + where: { + orgRevisionId: findRevision?.id, + current_holderId: item.id + } + }); + return { id: item.id, prefix: item.prefix, @@ -4808,9 +4897,16 @@ export class OrganizationDotnetController extends Controller { keycloak: item.keycloak, posNo: shortName, position: item.position, - positionLevel: item.posLevel?.posLevelName ?? null, + positionLevel: item.posType?.posTypeShortName && item.posLevel?.posLevelName + ? `${item.posType?.posTypeShortName} ${item.posLevel?.posLevelName}` + : null, positionType: item.posType?.posTypeName ?? null, oc: Oc, + orgRootId: _posMaster?.orgRootId, + orgChild1Id: _posMaster?.orgChild1Id, + orgChild2Id: _posMaster?.orgChild2Id, + orgChild3Id: _posMaster?.orgChild3Id, + orgChild4Id: _posMaster?.orgChild4Id, }; }), ); From 23aeb8864a8da2af110941190594e8e36285ce4c Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 11 Jul 2025 10:34:43 +0700 Subject: [PATCH 4/4] =?UTF-8?q?Fix=20=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=84?= =?UTF-8?q?=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B9=81=E0=B8=95?= =?UTF-8?q?=E0=B9=88=E0=B8=A3=E0=B8=B9=E0=B8=9B=E0=B8=A0=E0=B8=B2=E0=B8=9E?= =?UTF-8?q?=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20+=20=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=AA=E0=B8=B4=E0=B8=97=E0=B8=98=E0=B8=B4=E0=B9=8C=E0=B9=81?= =?UTF-8?q?=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=88?= =?UTF-8?q?=E0=B8=B3=E0=B8=95=E0=B8=B2=E0=B8=A1=E0=B8=AA=E0=B8=B4=E0=B8=97?= =?UTF-8?q?=E0=B8=98=E0=B8=B4=E0=B9=8C=E0=B9=80=E0=B8=88=E0=B9=89=E0=B9=88?= =?UTF-8?q?=E0=B8=B2=E0=B8=AB=E0=B8=99=E0=B9=89=E0=B8=B2=E0=B8=97=E0=B8=B5?= =?UTF-8?q?=E0=B9=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 46 ++++++- .../OrganizationDotnetController.ts | 115 +++++++++++++++--- src/entities/Profile.ts | 1 + 3 files changed, 147 insertions(+), 15 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 72da68dc..9ab6e468 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -89,6 +89,7 @@ import { OrgRoot } from "../entities/OrgRoot"; import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster"; import { ProfileInsignia, CreateProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory"; +import { ProfileAvatar } from "../entities/ProfileAvatar"; @Route("api/v1/org/command") @Tags("Command") @Security("bearerAuth") @@ -141,6 +142,7 @@ export class CommandController extends Controller { private orgRootRepository = AppDataSource.getRepository(OrgRoot); private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); + private avatarRepository = AppDataSource.getRepository(ProfileAvatar); /** * API list รายการคำสั่ง @@ -5510,7 +5512,7 @@ export class CommandController extends Controller { let profile: any = await this.profileRepository.findOne({ where: { citizenId: item.bodyProfile.citizenId /*, isActive: true */ }, - relations: ["roleKeycloaks", "profileInsignias"], + relations: ["roleKeycloaks", "profileInsignias", "profileAvatars"], }); let _oldInsigniaIds: string[] = []; if (!profile) { @@ -5961,6 +5963,48 @@ export class CommandController extends Controller { await this.insigniaHistoryRepo.save(history, { data: req }); } } + // เพิ่มรูปภาพโปรไฟล์ + if (item.bodyProfile.objectRefId) { + const _profileAvatar = new ProfileAvatar(); + Object.assign(_profileAvatar, { + ...meta, + profileId: profile.id, + profileEmployeeId: undefined + }); + if (profile.profileAvatars && profile.profileAvatars.length > 0) { + await Promise.all( + profile.profileAvatars.map(async (item: any) => { + item.isActive = false; + await this.avatarRepository.save(item); + }), + ); + } + await this.avatarRepository.save(_profileAvatar); + let avatar = `ทะเบียนประวัติ/โปรไฟล์/${profile.id}`; + let fileName = `profile-${_profileAvatar.id}`; + _profileAvatar.isActive = true; + _profileAvatar.avatar = avatar; + _profileAvatar.avatarName = fileName; + await this.avatarRepository.save(_profileAvatar, { data: req }); + profile.avatar = avatar; + profile.avatarName = fileName; + await this.profileRepository.save(profile, { data: req }); + const checkAvatar = await this.avatarRepository.findOne({ + where: { avatar: avatar, avatarName: fileName } + }) + if (checkAvatar && checkAvatar.profileId == null) { + checkAvatar.profileId = profile.id + await this.avatarRepository.save(checkAvatar); + } + //duplicate รูปภาพโปรไฟล์โดยอิงจากรูปภาพเดิม + await new CallAPI() + .PostData(req, `/salary/file/avatar/${item.bodyProfile.objectRefId}`, { + prefix: avatar, + fileName: fileName, + }) + .then(() => {}) + .catch(() => {}); + } } }), ); diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 332a6153..8693c955 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -190,10 +190,103 @@ export class OrganizationDotnetController extends Controller { citizenId?: string | null; firstName?: string | null; lastName?: string | null; + role?: string | null; + nodeId?: string | null; + node?: number | null; }, ) { - const profileRepository = AppDataSource.getRepository(ProfileEmployee); - const queryBuilder = profileRepository + // const profileRepository = AppDataSource.getRepository(ProfileEmployee); + // const queryBuilder = profileRepository + // .createQueryBuilder("profile") + // .leftJoinAndSelect("profile.posLevel", "posLevel") + // .leftJoinAndSelect("profile.posType", "posType") + // .leftJoinAndSelect("profile.profileSalary", "profileSalary") + // .leftJoinAndSelect("profile.current_holders", "current_holders") + // .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") + // .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") + // .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") + // .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") + // .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") + // .orderBy("profileSalary.order", "DESC"); + + // if (body.citizenId || body.firstName || body.lastName) { + // queryBuilder.where( + // new Brackets((qb) => { + // if (body.citizenId) { + // qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` }); + // } + // if (body.firstName) { + // qb.orWhere("profile.firstName LIKE :firstName", { firstName: `%${body.firstName}%` }); + // } + // if (body.lastName) { + // qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` }); + // } + // }), + // ); + // } + + // const profileEmp = await queryBuilder.getMany(); + + let condition = "1=1"; + let conditionParams = {}; + if (body.role === "CHILD") { + switch (body.node) { + case 0: + condition = "orgRoot.ancestorDNA = :nodeId"; + break; + case 1: + condition = "orgChild1.ancestorDNA = :nodeId"; + break; + case 2: + condition = "orgChild2.ancestorDNA = :nodeId"; + break; + case 3: + condition = "orgChild3.ancestorDNA = :nodeId"; + break; + case 4: + condition = "orgChild4.ancestorDNA = :nodeId"; + break; + default: + condition = "1=1"; + break; + } + conditionParams = { nodeId: body.nodeId }; + } + else if (body.role === "ROOT") { + condition = "orgRoot.ancestorDNA = :nodeId"; + conditionParams = { nodeId: body.nodeId }; + } + else if (body.role === "NORMAL") { + switch (body.node) { + case 0: + condition = "orgRoot.ancestorDNA = :nodeId AND current_holders.orgChild1 IS NULL"; + break; + case 1: + condition = "orgChild1.ancestorDNA = :nodeId AND current_holders.orgChild2 IS NULL"; + break; + case 2: + condition = "orgChild2.ancestorDNA = :nodeId AND current_holders.orgChild3 IS NULL"; + break; + case 3: + condition = "orgChild3.ancestorDNA = :nodeId AND current_holders.orgChild4 IS NULL"; + break; + case 4: + condition = "orgChild4.ancestorDNA = :nodeId"; + break; + default: + condition = "1=1"; + break; + } + conditionParams = { nodeId: body.nodeId }; + } + + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + } + const profileEmp = await this.profileEmpRepo .createQueryBuilder("profile") .leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posType", "posType") @@ -204,10 +297,8 @@ export class OrganizationDotnetController extends Controller { .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") - .orderBy("profileSalary.order", "DESC"); - - if (body.citizenId || body.firstName || body.lastName) { - queryBuilder.where( + .where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: findRevision.id }) + .andWhere( new Brackets((qb) => { if (body.citizenId) { qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` }); @@ -219,14 +310,10 @@ export class OrganizationDotnetController extends Controller { qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` }); } }), - ); - } - - const profileEmp = await queryBuilder.getMany(); - - const findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, - }); + ) + .andWhere(condition, conditionParams) + .orderBy("profileSalary.order", "DESC") + .getMany() const profileEmp_ = await Promise.all( profileEmp.map((item: ProfileEmployee) => { diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 9dec5a63..034ff2f6 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -857,6 +857,7 @@ export class CreateProfileAllFields { currentZipCode: string | null; amount?: Double | null; amountSpecial?: Double | null; + objectRefId?: string | null; } export type UpdateProfile = {