diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 59bae3b0..4d6ac8e6 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -8,8 +8,8 @@ on: env: REGISTRY: docker.frappet.com IMAGE_NAME: ehr/bma-ehr-org-service - DEPLOY_HOST: 192.168.1.80 - COMPOSE_PATH: /home/frappet/docker/bma-ehr + DEPLOY_HOST: 49.0.91.80 + COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-org jobs: # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd release-test: @@ -59,11 +59,11 @@ jobs: host: ${{env.DEPLOY_HOST}} username: frappet password: ${{ secrets.SSH_PASSWORD }} - port: 22 + port: 10102 script: | cd "${{env.COMPOSE_PATH}}" - docker-compose pull - docker-compose up -d + docker compose pull + docker compose up -d echo "${{ steps.gen_ver.outputs.image_ver }}"> success - uses: snow-actions/line-notify@v1.1.0 if: success() diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index aa9841a6..3046cfa7 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -1663,4 +1663,188 @@ export class OrganizationController extends Controller { return new HttpSuccess(); } + + /** + * API Organizational StructChart + * + * @summary Organizational StructChart + * + */ + @Get("struct-chart/{idNode}/{type}")//bright + async structchart(@Path() idNode: string, type: number) { + try { + + let revision: any; + let root: any; + let child1: any; + let child2: any; + let child3: any; + let child4: any; + let totalPositionCount_1: any; + let totalPositionVacant_1: any; + let totalPositionCount_2: any; + let totalPositionVacant_2: any; + let totalPositionCount_3: any; + let totalPositionVacant_3: any; + let totalPositionCount_4: any; + let totalPositionVacant_4: any; + let totalPositionCount_5: any; + let totalPositionVacant_5: any; + + switch (type) { + case 0: { + + revision = await this.orgRevisionRepository.findOne({ + where: { id: idNode }, + }); + if (!revision) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found revision"); + } + totalPositionCount_1 = await this.posMasterRepository.count({ + where: { + orgRevisionId: idNode + } + }); + totalPositionVacant_1 = await this.posMasterRepository.count({ + where: { + orgRevisionId: idNode, + current_holderId: IsNull() && "", + } + }); + root = await this.orgRootRepository.find({ + where: { + orgRevisionId: idNode + }, + }); + + if(root.length > 0){ + child1 = await this.child1Repository.find({ + where: { + // orgRevisionId: idNode, + orgRootId: root.id, + }, + }); + if(child1.length > 0){ + child2 = await this.child2Repository.find({ + where: { + // orgRevisionId: idNode, + // orgRootId: root.id, + orgChild1Id: child1.id + }, + }); + if(child2.length > 0){ + child3 = await this.child3Repository.find({ + where: { + // orgRevisionId: idNode, + // orgRootId: root.id, + // orgChild1Id: child1.id, + orgChild2Id: child2.id + }, + }); + if(child3.length > 0){ + child4 = await this.child4Repository.find({ + where: { + // orgRevisionId: idNode, + // orgRootId: root.id, + // orgChild1Id: child1.id, + // orgChild2Id: child2.id, + orgChild3Id: child3.id, + }, + }); + } + } + } + } + + //Tree + const treeObject = { + deptID: revision.id, + departmentName: revision.orgRevisionName, + totalPositionCount: totalPositionCount_1 == 0 || null ? 0 : totalPositionCount_1, + totalPositionVacant: totalPositionVacant_1 == 0 || null ? 0 : totalPositionVacant_1, + children: root.map((roots:any) => ({ + deptID: roots.id, + departmentName: roots.orgRootName, + + + })), + heads: [ + { + positionID: null, + positionName: null, + positionNum: null, + totalPositionCount: 0, + totalPositionVacant: 0 + } + ], + officer: [ + { + positionID: null, + positionName: null, + positionNum: null, + totalPositionCount: 0, + totalPositionVacant: 0 + } + ] + } + + return new HttpSuccess(treeObject) + + } + case 1: { + root = await this.orgRootRepository.findOne({ + where: { id: idNode }, + }); + if (!root) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId"); + } + break; + } + case 2: { + child1 = await this.child1Repository.findOne({ + where: { id: idNode }, + }); + if (!child1) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id"); + } + break; + } + case 3: { + child2 = await this.child2Repository.findOne({ + where: { id: idNode }, + }); + if (!child2) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id"); + } + break; + } + case 4: { + child3 = await this.child3Repository.findOne({ + where: { id: idNode }, + }); + if (!child3) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id"); + } + break; + } + case 5: { + child4 = await this.child4Repository.findOne({ + where: { id: idNode }, + }); + if (!child4) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4Id"); + } + break; + } + default: + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: "); + } + + // return new HttpSuccess(); + + } catch (error) { + return error; + } + } + } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 72e04ed1..61df770a 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -111,6 +111,55 @@ export class PositionController extends Controller { } } + const chk_posDictName = await this.posDictRepository.findOne({ + where: { posDictName: posDict.posDictName } + }) + if(chk_posDictName){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งในสายงาน: " + chk_posDictName.posDictName + " มีอยู่ในระบบแล้ว"); + } + + const chk_posDictField = await this.posDictRepository.findOne({ + where: { posDictField: posDict.posDictField } + }) + if(chk_posDictField){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "สายงาน: " + chk_posDictField.posDictField + " มีอยู่ในระบบแล้ว"); + } + + const chk_posTypeId = await this.posDictRepository.findOne({ + where: { posTypeId: posDict.posTypeId } + }) + if(chk_posTypeId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งประเภท: " + chk_posTypeId.posTypeId + " มีอยู่ในระบบแล้ว"); + } + + const chk_posLevelId = await this.posDictRepository.findOne({ + where: { posLevelId: posDict.posLevelId } + }) + if(chk_posLevelId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับตำแหน่ง: " + chk_posLevelId.posLevelId + " มีอยู่ในระบบแล้ว"); + } + + const chk_posExecutiveId = await this.posDictRepository.findOne({ + where: { posExecutiveId: String(posDict.posExecutiveId) } + }) + if(chk_posExecutiveId){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งทางการบริหาร: " + chk_posExecutiveId.posExecutiveId + " มีอยู่ในระบบแล้ว"); + } + + const chk_posDictExecutiveField = await this.posDictRepository.findOne({ + where: { posDictExecutiveField: posDict.posDictExecutiveField } + }) + if(chk_posDictExecutiveField){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ด้านทางการบริหาร: " + chk_posDictExecutiveField.posDictExecutiveField + " มีอยู่ในระบบแล้ว"); + } + + const chk_posDictArea= await this.posDictRepository.findOne({ + where: { posDictArea: posDict.posDictArea } + }) + if(chk_posDictArea){ + throw new HttpError(HttpStatusCode.NOT_FOUND, "ด้าน/สาขา: " + chk_posDictArea.posDictArea + " มีอยู่ในระบบแล้ว"); + } + try { posDict.createdUserId = request.user.sub; posDict.createdFullName = request.user.name;