This commit is contained in:
Kittapath 2024-04-19 09:44:46 +07:00
parent c4a975b503
commit a9dd103ff8
16 changed files with 1484 additions and 15 deletions

72
package-lock.json generated
View file

@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"@tsoa/runtime": "^6.0.0",
"axios": "^1.6.8",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
@ -520,6 +521,11 @@
"resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz",
"integrity": "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ=="
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/available-typed-arrays": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz",
@ -531,6 +537,16 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/axios": {
"version": "1.6.8",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
"integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@ -967,6 +983,17 @@
"resolved": "https://registry.npmjs.org/colors-console/-/colors-console-1.0.3.tgz",
"integrity": "sha512-Q31K32UwadWqAxs+Iu46gNm4HJqUwrTJT2zen5NnhkKE5w7uqeZQZiuODUOxM/zOtHfiUTkia0io6zbN/VcCUQ=="
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
@ -1112,6 +1139,14 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/denque": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz",
@ -1497,6 +1532,25 @@
"node": ">= 0.8"
}
},
"node_modules/follow-redirects": {
"version": "1.15.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/for-each": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",
@ -1520,6 +1574,19 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -3067,6 +3134,11 @@
"node": ">= 0.10"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/pstree.remy": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",

View file

@ -28,6 +28,7 @@
},
"dependencies": {
"@tsoa/runtime": "^6.0.0",
"axios": "^1.6.8",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",

View file

@ -20,7 +20,7 @@ import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { Like, Not } from "typeorm";
import HttpStatusCode from "../interfaces/http-status";
import { KpiGroup, creatKpiGroup, updateKpiGroup } from "../entities/kpiGroup";
import { KpiGroup, createKpiGroup, updateKpiGroup } from "../entities/kpiGroup";
@Route("api/v1/kpi/group")
@Tags("kpiGroup")
@Security("bearerAuth")
@ -42,7 +42,7 @@ export class kpiGroupController extends Controller {
nameGroupKPI: "string", //ชื่อกลุ่มงาน
})
async createKpiGroup(
@Body() requestBody: creatKpiGroup,
@Body() requestBody: createKpiGroup,
@Request() request: { user: Record<string, any> },
) {
const kpiGroup = Object.assign(new KpiGroup(), requestBody);

View file

@ -30,7 +30,7 @@ import { Like } from "typeorm/browser";
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class kpiController extends Controller {
export class kpiPeriodController extends Controller {
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
/**
*
@ -152,7 +152,7 @@ export class kpiController extends Controller {
async GetKpiPeriodById(@Path() id: string) {
const kpiPeriod = await this.kpiPeriodRepository.findOne({
where: { id: id },
select: ["durationKPI", "startDate", "endDate", "isActive"],
select: ["year", "durationKPI", "startDate", "endDate", "isActive"],
});
if (!kpiPeriod) {
throw new HttpError(
@ -173,15 +173,19 @@ export class kpiController extends Controller {
async listKpiPeriod(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("year") year?: string,
@Query("year") year?: number,
@Query("keyword") keyword?: string,
) {
const [kpiPeriod, total] = await this.kpiPeriodRepository.findAndCount({
// where: {
// durationKPI: Like(`%${keyword}%`),
// },
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
});
const [kpiPeriod, total] = await AppDataSource.getRepository(KpiPeriod)
.createQueryBuilder("kpiPeriod")
.andWhere(
year !== 0 && year != null && year != undefined ? "kpiPeriod.year = :year" : "1=1",
{ year: year },
)
.orderBy("kpiPeriod.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
return new HttpSuccess({ data: kpiPeriod, total });
}
@ -191,7 +195,7 @@ export class kpiController extends Controller {
* @param id
*/
@Delete("{id}")
async deleteKpiPerriod(@Path() id: string) {
async deleteKpiPeriod(@Path() id: string) {
const kpiPeriod = await this.kpiPeriodRepository.findOne({
where: { id: id },
});

View file

@ -0,0 +1,311 @@
import {
Controller,
Get,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
Example,
SuccessResponse,
Response,
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
import { KpiPlan, createKpiPlan, updateKpiPlan } from "../entities/kpiPlan";
import CallAPI from "../interfaces/call-api";
@Route("api/v1/kpi/plan")
@Tags("kpiPlan")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class kpiPlanController extends Controller {
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
/**
*
* @param requestBody
* @param request
*/
@Post()
async createKpiPlan(
@Body() requestBody: createKpiPlan,
@Request() request: { user: Record<string, any> },
) {
const kpiPlan = Object.assign(new KpiPlan(), requestBody);
await new CallAPI()
.PostData(request, "org/find/all", {
node: requestBody.node,
nodeId: requestBody.nodeId,
})
.then((x) => {
kpiPlan.root = x.root;
kpiPlan.rootId = x.rootId;
kpiPlan.rootShortName = x.rootShortName;
kpiPlan.child1 = requestBody.node <= 0 ? null : x.child1;
kpiPlan.child1Id = requestBody.node <= 0 ? null : x.child1Id;
kpiPlan.child1ShortName = requestBody.node <= 0 ? null : x.child1ShortName;
kpiPlan.child2 = requestBody.node <= 1 ? null : x.child2;
kpiPlan.child2Id = requestBody.node <= 1 ? null : x.child2Id;
kpiPlan.child2ShortName = requestBody.node <= 1 ? null : x.child2ShortName;
kpiPlan.child3 = requestBody.node <= 2 ? null : x.child3;
kpiPlan.child3Id = requestBody.node <= 2 ? null : x.child3Id;
kpiPlan.child3ShortName = requestBody.node <= 2 ? null : x.child3ShortName;
kpiPlan.child4 = requestBody.node <= 3 ? null : x.child4;
kpiPlan.child4Id = requestBody.node <= 3 ? null : x.child4Id;
kpiPlan.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName;
})
.catch((x) => {});
await new CallAPI()
.PostData(request, "development/strategy/find/all", {
strategy: requestBody.strategy,
strategyId: requestBody.strategyId,
})
.then((x) => {
kpiPlan.strategyChild1 = x.strategyChild1;
kpiPlan.strategyChild1Id = x.strategyChild1Id;
kpiPlan.strategyChild2 = requestBody.strategy <= 1 ? null : x.strategyChild2;
kpiPlan.strategyChild2Id = requestBody.strategy <= 1 ? null : x.strategyChild2Id;
kpiPlan.strategyChild3 = requestBody.strategy <= 2 ? null : x.strategyChild3;
kpiPlan.strategyChild3Id = requestBody.strategy <= 2 ? null : x.strategyChild3Id;
kpiPlan.strategyChild4 = requestBody.strategy <= 3 ? null : x.strategyChild4;
kpiPlan.strategyChild4Id = requestBody.strategy <= 3 ? null : x.strategyChild4Id;
kpiPlan.strategyChild5 = requestBody.strategy <= 4 ? null : x.strategyChild5;
kpiPlan.strategyChild5Id = requestBody.strategy <= 4 ? null : x.strategyChild5Id;
})
.catch((x) => {});
kpiPlan.round = requestBody.round.trim().toUpperCase();
kpiPlan.createdUserId = request.user.sub;
kpiPlan.createdFullName = request.user.name;
kpiPlan.lastUpdateUserId = request.user.sub;
kpiPlan.lastUpdateFullName = request.user.name;
await this.kpiPlanRepository.save(kpiPlan);
return new HttpSuccess(kpiPlan.id);
}
/**
* API
* @param id
* @param requestBody
* @param request
*/
@Put("{id}")
async updateKpiPlan(
@Path() id: string,
@Body() requestBody: updateKpiPlan,
@Request() request: { user: Record<string, any> },
) {
const kpiPlan = await this.kpiPlanRepository.findOne({
where: { id: id },
});
if (!kpiPlan) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
}
kpiPlan.round = requestBody.round.trim().toUpperCase();
Object.assign(kpiPlan, requestBody);
await new CallAPI()
.PostData(request, "org/find/all", {
node: requestBody.node,
nodeId: requestBody.nodeId,
})
.then((x) => {
kpiPlan.root = x.root;
kpiPlan.rootId = x.rootId;
kpiPlan.rootShortName = x.rootShortName;
kpiPlan.child1 = requestBody.node <= 0 ? null : x.child1;
kpiPlan.child1Id = requestBody.node <= 0 ? null : x.child1Id;
kpiPlan.child1ShortName = requestBody.node <= 0 ? null : x.child1ShortName;
kpiPlan.child2 = requestBody.node <= 1 ? null : x.child2;
kpiPlan.child2Id = requestBody.node <= 1 ? null : x.child2Id;
kpiPlan.child2ShortName = requestBody.node <= 1 ? null : x.child2ShortName;
kpiPlan.child3 = requestBody.node <= 2 ? null : x.child3;
kpiPlan.child3Id = requestBody.node <= 2 ? null : x.child3Id;
kpiPlan.child3ShortName = requestBody.node <= 2 ? null : x.child3ShortName;
kpiPlan.child4 = requestBody.node <= 3 ? null : x.child4;
kpiPlan.child4Id = requestBody.node <= 3 ? null : x.child4Id;
kpiPlan.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName;
})
.catch((x) => {});
await new CallAPI()
.PostData(request, "development/strategy/find/all", {
strategy: requestBody.strategy,
strategyId: requestBody.strategyId,
})
.then((x) => {
kpiPlan.strategyChild1 = x.strategyChild1;
kpiPlan.strategyChild1Id = x.strategyChild1Id;
kpiPlan.strategyChild2 = requestBody.strategy <= 1 ? null : x.strategyChild2;
kpiPlan.strategyChild2Id = requestBody.strategy <= 1 ? null : x.strategyChild2Id;
kpiPlan.strategyChild3 = requestBody.strategy <= 2 ? null : x.strategyChild3;
kpiPlan.strategyChild3Id = requestBody.strategy <= 2 ? null : x.strategyChild3Id;
kpiPlan.strategyChild4 = requestBody.strategy <= 3 ? null : x.strategyChild4;
kpiPlan.strategyChild4Id = requestBody.strategy <= 3 ? null : x.strategyChild4Id;
kpiPlan.strategyChild5 = requestBody.strategy <= 4 ? null : x.strategyChild5;
kpiPlan.strategyChild5Id = requestBody.strategy <= 4 ? null : x.strategyChild5Id;
})
.catch((x) => {});
kpiPlan.createdUserId = request.user.sub;
kpiPlan.createdFullName = request.user.name;
kpiPlan.lastUpdateUserId = request.user.sub;
kpiPlan.lastUpdateFullName = request.user.name;
await this.kpiPlanRepository.save(kpiPlan);
return new HttpSuccess(id);
}
/**
* API
* @param id Guid, *Id
*/
@Get("{id}")
async GetKpiPlanById(@Path() id: string) {
const kpiPlan = await this.kpiPlanRepository.findOne({
where: { id: id },
});
if (!kpiPlan) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
}
let node = null;
let nodeId = null;
if (kpiPlan.child4Id != null) {
node = 4;
nodeId = kpiPlan.child4Id;
} else if (kpiPlan.child3Id != null) {
node = 3;
nodeId = kpiPlan.child3Id;
} else if (kpiPlan.child2Id != null) {
node = 2;
nodeId = kpiPlan.child2Id;
} else if (kpiPlan.child1Id != null) {
node = 1;
nodeId = kpiPlan.child1Id;
} else if (kpiPlan.rootId != null) {
node = 0;
nodeId = kpiPlan.rootId;
}
let strategy = null;
let strategyId = null;
if (kpiPlan.strategyChild5Id != null) {
strategy = 5;
strategyId = kpiPlan.strategyChild5Id;
} else if (kpiPlan.strategyChild4Id != null) {
strategy = 4;
strategyId = kpiPlan.strategyChild4Id;
} else if (kpiPlan.strategyChild3Id != null) {
strategy = 3;
strategyId = kpiPlan.strategyChild3Id;
} else if (kpiPlan.strategyChild2Id != null) {
strategy = 2;
strategyId = kpiPlan.strategyChild2Id;
} else if (kpiPlan.strategyChild1Id != null) {
strategy = 1;
strategyId = kpiPlan.strategyChild1Id;
}
const formattedData = {
id: kpiPlan.id,
year: kpiPlan.year,
round: kpiPlan.round,
including: kpiPlan.including,
includingName: kpiPlan.includingName,
target: kpiPlan.target,
unit: kpiPlan.unit,
weight: kpiPlan.weight,
achievement1: kpiPlan.achievement1,
achievement2: kpiPlan.achievement2,
achievement3: kpiPlan.achievement3,
achievement4: kpiPlan.achievement4,
achievement5: kpiPlan.achievement5,
meaning: kpiPlan.meaning,
formula: kpiPlan.formula,
node: node,
nodeId: nodeId,
orgRevisionId: kpiPlan.orgRevisionId,
strategy: strategy,
strategyId: strategyId,
};
return new HttpSuccess(formattedData);
}
/**
* API list
* @param page
* @param pageSize
* @param keyword
*/
@Get()
async listKpiPlan(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("round") round?: string,
@Query("nodeId") nodeId?: string | null,
@Query("node") node?: number | null,
@Query("keyword") keyword?: string,
) {
const [kpiPlan, total] = await AppDataSource.getRepository(KpiPlan)
.createQueryBuilder("kpiPlan")
.andWhere(
node != undefined && node != null
? node == 4
? "kpiPlan.child4Id LIKE :nodeId"
: node == 3
? "kpiPlan.child3Id LIKE :nodeId"
: node == 2
? "kpiPlan.child2Id LIKE :nodeId"
: node == 1
? "kpiPlan.child1Id LIKE :nodeId"
: "kpiPlan.rootId LIKE :nodeId"
: "1=1",
{
nodeId: `${nodeId}`,
},
)
.andWhere(
round != undefined && round != null && round != "" ? "kpiPlan.round LIKE :round" : "1=1",
{
round: `${round?.trim().toUpperCase()}`,
},
)
.andWhere(keyword != undefined ? "kpiPlan.projectName LIKE :keyword" : "1=1", {
keyword: `%${keyword}%`,
})
.select([
"kpiPlan.id",
"kpiPlan.year",
"kpiPlan.round",
"kpiPlan.including",
"kpiPlan.includingName",
])
.orderBy("kpiPlan.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
return new HttpSuccess({ data: kpiPlan, total });
}
/**
* API
* @param id
*/
@Delete("{id}")
async deleteKpiPlan(@Path() id: string) {
const kpiPlan = await this.kpiPlanRepository.findOne({
where: { id: id },
});
if (!kpiPlan) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
}
await this.kpiPlanRepository.remove(kpiPlan);
return new HttpSuccess();
}
}

View file

@ -0,0 +1,255 @@
import {
Controller,
Get,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
Example,
SuccessResponse,
Response,
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
import { KpiRole, createKpiRole, updateKpiRole } from "../entities/kpiRole";
import CallAPI from "../interfaces/call-api";
@Route("api/v1/kpi/role")
@Tags("kpiRole")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class kpiRoleController extends Controller {
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
/**
*
* @param requestBody
* @param request
*/
@Post()
async createKpiRole(
@Body() requestBody: createKpiRole,
@Request() request: { user: Record<string, any> },
) {
const kpiRole = Object.assign(new KpiRole(), requestBody);
await new CallAPI()
.PostData(request, "org/find/all", {
node: requestBody.node,
nodeId: requestBody.nodeId,
})
.then((x) => {
kpiRole.root = x.root;
kpiRole.rootId = x.rootId;
kpiRole.rootShortName = x.rootShortName;
kpiRole.child1 = requestBody.node <= 0 ? null : x.child1;
kpiRole.child1Id = requestBody.node <= 0 ? null : x.child1Id;
kpiRole.child1ShortName = requestBody.node <= 0 ? null : x.child1ShortName;
kpiRole.child2 = requestBody.node <= 1 ? null : x.child2;
kpiRole.child2Id = requestBody.node <= 1 ? null : x.child2Id;
kpiRole.child2ShortName = requestBody.node <= 1 ? null : x.child2ShortName;
kpiRole.child3 = requestBody.node <= 2 ? null : x.child3;
kpiRole.child3Id = requestBody.node <= 2 ? null : x.child3Id;
kpiRole.child3ShortName = requestBody.node <= 2 ? null : x.child3ShortName;
kpiRole.child4 = requestBody.node <= 3 ? null : x.child4;
kpiRole.child4Id = requestBody.node <= 3 ? null : x.child4Id;
kpiRole.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName;
})
.catch((x) => {});
kpiRole.round = requestBody.round.trim().toUpperCase();
kpiRole.createdUserId = request.user.sub;
kpiRole.createdFullName = request.user.name;
kpiRole.lastUpdateUserId = request.user.sub;
kpiRole.lastUpdateFullName = request.user.name;
await this.kpiRoleRepository.save(kpiRole);
return new HttpSuccess(kpiRole.id);
}
/**
* API
* @param id
* @param requestBody
* @param request
*/
@Put("{id}")
async updateKpiRole(
@Path() id: string,
@Body() requestBody: updateKpiRole,
@Request() request: { user: Record<string, any> },
) {
const kpiRole = await this.kpiRoleRepository.findOne({
where: { id: id },
});
if (!kpiRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
}
kpiRole.round = requestBody.round.trim().toUpperCase();
Object.assign(kpiRole, requestBody);
await new CallAPI()
.PostData(request, "org/find/all", {
node: requestBody.node,
nodeId: requestBody.nodeId,
})
.then((x) => {
kpiRole.root = x.root;
kpiRole.rootId = x.rootId;
kpiRole.rootShortName = x.rootShortName;
kpiRole.child1 = requestBody.node <= 0 ? null : x.child1;
kpiRole.child1Id = requestBody.node <= 0 ? null : x.child1Id;
kpiRole.child1ShortName = requestBody.node <= 0 ? null : x.child1ShortName;
kpiRole.child2 = requestBody.node <= 1 ? null : x.child2;
kpiRole.child2Id = requestBody.node <= 1 ? null : x.child2Id;
kpiRole.child2ShortName = requestBody.node <= 1 ? null : x.child2ShortName;
kpiRole.child3 = requestBody.node <= 2 ? null : x.child3;
kpiRole.child3Id = requestBody.node <= 2 ? null : x.child3Id;
kpiRole.child3ShortName = requestBody.node <= 2 ? null : x.child3ShortName;
kpiRole.child4 = requestBody.node <= 3 ? null : x.child4;
kpiRole.child4Id = requestBody.node <= 3 ? null : x.child4Id;
kpiRole.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName;
})
.catch((x) => {});
kpiRole.createdUserId = request.user.sub;
kpiRole.createdFullName = request.user.name;
kpiRole.lastUpdateUserId = request.user.sub;
kpiRole.lastUpdateFullName = request.user.name;
await this.kpiRoleRepository.save(kpiRole);
return new HttpSuccess(id);
}
/**
* API
* @param id Guid, *Id
*/
@Get("{id}")
async GetKpiRoleById(@Path() id: string) {
const kpiRole = await this.kpiRoleRepository.findOne({
where: { id: id },
});
if (!kpiRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
}
let node = null;
let nodeId = null;
if (kpiRole.child4Id != null) {
node = 4;
nodeId = kpiRole.child4Id;
} else if (kpiRole.child3Id != null) {
node = 3;
nodeId = kpiRole.child3Id;
} else if (kpiRole.child2Id != null) {
node = 2;
nodeId = kpiRole.child2Id;
} else if (kpiRole.child1Id != null) {
node = 1;
nodeId = kpiRole.child1Id;
} else if (kpiRole.rootId != null) {
node = 0;
nodeId = kpiRole.rootId;
}
const formattedData = {
id: kpiRole.id,
year: kpiRole.year,
round: kpiRole.round,
including: kpiRole.including,
includingName: kpiRole.includingName,
target: kpiRole.target,
unit: kpiRole.unit,
weight: kpiRole.weight,
achievement1: kpiRole.achievement1,
achievement2: kpiRole.achievement2,
achievement3: kpiRole.achievement3,
achievement4: kpiRole.achievement4,
achievement5: kpiRole.achievement5,
meaning: kpiRole.meaning,
formula: kpiRole.formula,
node: node,
nodeId: nodeId,
orgRevisionId: kpiRole.orgRevisionId,
};
return new HttpSuccess(formattedData);
}
/**
* API list
* @param page
* @param pageSize
* @param keyword
*/
@Get()
async listKpiRole(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("round") round?: string,
@Query("nodeId") nodeId?: string | null,
@Query("node") node?: number | null,
@Query("keyword") keyword?: string,
) {
const [kpiRole, total] = await AppDataSource.getRepository(KpiRole)
.createQueryBuilder("kpiRole")
.andWhere(
node != undefined && node != null
? node == 4
? "kpiRole.child4Id LIKE :nodeId"
: node == 3
? "kpiRole.child3Id LIKE :nodeId"
: node == 2
? "kpiRole.child2Id LIKE :nodeId"
: node == 1
? "kpiRole.child1Id LIKE :nodeId"
: "kpiRole.rootId LIKE :nodeId"
: "1=1",
{
nodeId: `${nodeId}`,
},
)
.andWhere(
round != undefined && round != null && round != "" ? "kpiRole.round LIKE :round" : "1=1",
{
round: `${round?.trim().toUpperCase()}`,
},
)
.andWhere(keyword != undefined ? "kpiRole.projectName LIKE :keyword" : "1=1", {
keyword: `%${keyword}%`,
})
.select([
"kpiRole.id",
"kpiRole.year",
"kpiRole.round",
"kpiRole.including",
"kpiRole.includingName",
])
.orderBy("kpiRole.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
return new HttpSuccess({ data: kpiRole, total });
}
/**
* API
* @param id
*/
@Delete("{id}")
async deleteKpiRole(@Path() id: string) {
const kpiRole = await this.kpiRoleRepository.findOne({
where: { id: id },
});
if (!kpiRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
}
await this.kpiRoleRepository.remove(kpiRole);
return new HttpSuccess();
}
}

View file

@ -1,6 +1,7 @@
import { Entity, Column, OneToMany, ManyToOne } from "typeorm";
import { Entity, Column, OneToMany, ManyToOne, ManyToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { KpiCapacityDetail } from "./kpiCapacityDetail";
import { KpiLink } from "./kpiLink";
enum CapacityType {
HEAD = "HEAD",
@ -40,6 +41,9 @@ export class KpiCapacity extends EntityBase {
@OneToMany(() => KpiCapacityDetail, (kpiCapacityDetail) => kpiCapacityDetail.kpiCapacitys)
KpiCapacityDetails: KpiCapacityDetail[];
@ManyToMany(() => KpiLink, (kpiLink) => kpiLink.kpiCapacitys)
kpiLinks: KpiLink[];
}
export class createKpiCapacity {
@Column()

View file

@ -1,5 +1,6 @@
import { Entity, Column } from "typeorm";
import { Entity, Column, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { KpiLink } from "./kpiLink";
@Entity("kpiGroup")
export class KpiGroup extends EntityBase {
@ -9,8 +10,11 @@ export class KpiGroup extends EntityBase {
default: null,
})
nameGroupKPI: string;
@OneToMany(() => KpiLink, (kpiLink) => kpiLink.kpiGroup)
kpiLinks: KpiLink[];
}
export class creatKpiGroup {
export class createKpiGroup {
@Column()
nameGroupKPI: string;
}

25
src/entities/kpiLink.ts Normal file
View file

@ -0,0 +1,25 @@
import { Entity, Column, ManyToOne, JoinColumn, ManyToMany, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { KpiGroup } from "./kpiGroup";
import { KpiCapacity } from "./kpiCapacity";
import { Position } from "./position";
@Entity("kpiLink")
export class KpiLink extends EntityBase {
@Column({
nullable: true,
length: 40,
comment: "ไอดีกลุ่มงาน",
})
kpiGroupId: string | null;
@ManyToOne(() => KpiGroup, (kpiGroup) => kpiGroup.kpiLinks)
@JoinColumn({ name: "kpiGroupId" })
kpiGroup: KpiGroup;
@ManyToMany(() => KpiCapacity, (kpiCapacity) => kpiCapacity.kpiLinks)
kpiCapacitys: KpiCapacity[];
@OneToMany(() => Position, (position) => position.kpiLink)
positions: Position[];
}

View file

@ -3,6 +3,12 @@ import { EntityBase } from "./base/Base";
@Entity("kpiPeriod")
export class KpiPeriod extends EntityBase {
@Column({
nullable: true,
comment: "ปีงบประมาณ",
})
year: number;
@Column({
nullable: true,
comment: "รอบการประเมิน",
@ -33,6 +39,8 @@ export class KpiPeriod extends EntityBase {
isActive: boolean;
}
export class createKpiPeriod {
@Column()
year: number;
@Column()
durationKPI: string;
@Column()
@ -44,6 +52,8 @@ export class createKpiPeriod {
}
export class updateKpiPeriod {
@Column()
year: number;
@Column()
durationKPI: string;
@Column()

371
src/entities/kpiPlan.ts Normal file
View file

@ -0,0 +1,371 @@
import { Entity, Column, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { KpiLink } from "./kpiLink";
@Entity("kpiPlan")
export class KpiPlan extends EntityBase {
@Column({
nullable: true,
comment: "ปีงบประมาณ",
})
year: number;
@Column({
nullable: true,
comment: "รอบการประเมิน",
default: null,
})
round: string;
@Column({
nullable: true,
comment: "รหัสตัวชี้วัด",
default: null,
})
including: string;
@Column({
nullable: true,
comment: "ชื่อตัวชี้วัด",
default: null,
})
includingName: string;
@Column({
nullable: true,
comment: "ค่าเป้าหมาย",
default: null,
})
target: string;
@Column({
nullable: true,
comment: "หน่วยนับ",
default: null,
})
unit: number;
@Column({
nullable: true,
comment: "น้ำหนัก",
default: null,
})
weight: number;
@Column({
nullable: true,
comment: "ผลสำเร็จของงาน 1",
default: null,
})
achievement1: string;
@Column({
nullable: true,
comment: "ผลสำเร็จของงาน 2",
default: null,
})
achievement2: string;
@Column({
nullable: true,
comment: "ผลสำเร็จของงาน 3",
default: null,
})
achievement3: string;
@Column({
nullable: true,
comment: "ผลสำเร็จของงาน 4",
default: null,
})
achievement4: string;
@Column({
nullable: true,
comment: "ผลสำเร็จของงาน 5",
default: null,
})
achievement5: string;
@Column({
nullable: true,
comment: "นิยามหรือความหมาย",
default: null,
})
meaning: string;
@Column({
nullable: true,
comment: "สูตรคำนวณ",
default: null,
})
formula: string;
@Column({
nullable: true,
comment: "id หน่วยงาน",
default: null,
})
rootId: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน",
default: null,
})
root: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน",
default: null,
})
rootShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child1",
default: null,
})
child1Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child1",
default: null,
})
child1: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child1",
default: null,
})
child1ShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child2",
default: null,
})
child2Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child2",
default: null,
})
child2: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child2",
default: null,
})
child2ShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child3",
default: null,
})
child3Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child3",
default: null,
})
child3: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child3",
default: null,
})
child3ShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child4",
default: null,
})
child4Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child4",
default: null,
})
child4: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child4",
default: null,
})
child4ShortName: string;
@Column({
nullable: true,
comment: "id revision",
default: null,
})
orgRevisionId: string;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง strategyChild1",
default: null,
})
strategyChild1Id: string;
@Column({
nullable: true,
comment: "ชื่อ strategyChild1",
default: null,
})
strategyChild1: string;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง strategyChild2",
default: null,
})
strategyChild2Id: string;
@Column({
nullable: true,
comment: "ชื่อ strategyChild2",
default: null,
})
strategyChild2: string;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง strategyChild3",
default: null,
})
strategyChild3Id: string;
@Column({
nullable: true,
comment: "ชื่อ strategyChild3",
default: null,
})
strategyChild3: string;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง strategyChild4",
default: null,
})
strategyChild4Id: string;
@Column({
nullable: true,
comment: "ชื่อ strategyChild4",
default: null,
})
strategyChild4: string;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง strategyChild5",
default: null,
})
strategyChild5Id: string;
@Column({
nullable: true,
comment: "ชื่อ strategyChild5",
default: null,
})
strategyChild5: string;
}
export class createKpiPlan {
@Column()
year: number | null;
@Column()
round: string;
@Column()
including: string | null;
@Column()
includingName: string | null;
@Column()
target: string | null;
@Column()
unit: number | null;
@Column()
weight: number | null;
@Column()
achievement1: string | null;
@Column()
achievement2: string | null;
@Column()
achievement3: string | null;
@Column()
achievement4: string | null;
@Column()
achievement5: string | null;
@Column()
meaning: string | null;
@Column()
formula: string | null;
@Column()
node: number;
@Column()
nodeId: string | null;
@Column()
orgRevisionId: string;
@Column()
strategy: number;
@Column()
strategyId: string | null;
}
export class updateKpiPlan {
@Column()
year: number | null;
@Column()
round: string;
@Column()
including: string | null;
@Column()
includingName: string | null;
@Column()
target: string | null;
@Column()
unit: number | null;
@Column()
weight: number | null;
@Column()
achievement1: string | null;
@Column()
achievement2: string | null;
@Column()
achievement3: string | null;
@Column()
achievement4: string | null;
@Column()
achievement5: string | null;
@Column()
meaning: string | null;
@Column()
formula: string | null;
@Column()
node: number;
@Column()
nodeId: string | null;
@Column()
orgRevisionId: string;
@Column()
strategy: number;
@Column()
strategyId: string | null;
}

299
src/entities/kpiRole.ts Normal file
View file

@ -0,0 +1,299 @@
import { Entity, Column, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { KpiLink } from "./kpiLink";
@Entity("kpiRole")
export class KpiRole extends EntityBase {
@Column({
nullable: true,
comment: "ตำแหน่ง",
default: null,
})
position: string;
@Column({
nullable: true,
comment: "ปีงบประมาณ",
})
year: number;
@Column({
nullable: true,
comment: "รอบการประเมิน",
default: null,
})
round: string;
@Column({
nullable: true,
comment: "รหัสตัวชี้วัด",
default: null,
})
including: string;
@Column({
nullable: true,
comment: "ชื่อตัวชี้วัด",
default: null,
})
includingName: string;
@Column({
nullable: true,
comment: "ค่าเป้าหมาย",
default: null,
})
target: string;
@Column({
nullable: true,
comment: "หน่วยนับ",
default: null,
})
unit: number;
@Column({
nullable: true,
comment: "น้ำหนัก",
default: null,
})
weight: number;
@Column({
nullable: true,
comment: "ผลสำเร็จของงาน 1",
default: null,
})
achievement1: string;
@Column({
nullable: true,
comment: "ผลสำเร็จของงาน 2",
default: null,
})
achievement2: string;
@Column({
nullable: true,
comment: "ผลสำเร็จของงาน 3",
default: null,
})
achievement3: string;
@Column({
nullable: true,
comment: "ผลสำเร็จของงาน 4",
default: null,
})
achievement4: string;
@Column({
nullable: true,
comment: "ผลสำเร็จของงาน 5",
default: null,
})
achievement5: string;
@Column({
nullable: true,
comment: "id หน่วยงาน",
default: null,
})
rootId: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน",
default: null,
})
root: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน",
default: null,
})
rootShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child1",
default: null,
})
child1Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child1",
default: null,
})
child1: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child1",
default: null,
})
child1ShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child2",
default: null,
})
child2Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child2",
default: null,
})
child2: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child2",
default: null,
})
child2ShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child3",
default: null,
})
child3Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child3",
default: null,
})
child3: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child3",
default: null,
})
child3ShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child4",
default: null,
})
child4Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child4",
default: null,
})
child4: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child4",
default: null,
})
child4ShortName: string;
@Column({
nullable: true,
comment: "id revision",
default: null,
})
orgRevisionId: string;
@Column({
nullable: true,
comment: "นิยามหรือความหมาย",
default: null,
})
meaning: string;
@Column({
nullable: true,
comment: "สูตรคำนวณ",
default: null,
})
formula: string;
}
export class createKpiRole {
@Column()
position: string | null;
@Column()
year: number | null;
@Column()
round: string;
@Column()
including: string | null;
@Column()
includingName: string | null;
@Column()
target: string | null;
@Column()
unit: number | null;
@Column()
weight: number | null;
@Column()
achievement1: string | null;
@Column()
achievement2: string | null;
@Column()
achievement3: string | null;
@Column()
achievement4: string | null;
@Column()
achievement5: string | null;
@Column()
node: number;
@Column()
nodeId: string | null;
@Column()
orgRevisionId: string;
@Column()
meaning: string | null;
@Column()
formula: string | null;
}
export class updateKpiRole {
@Column()
position: string | null;
@Column()
year: number | null;
@Column()
round: string;
@Column()
including: string | null;
@Column()
includingName: string | null;
@Column()
target: string | null;
@Column()
unit: number | null;
@Column()
weight: number | null;
@Column()
achievement1: string | null;
@Column()
achievement2: string | null;
@Column()
achievement3: string | null;
@Column()
achievement4: string | null;
@Column()
achievement5: string | null;
@Column()
node: number;
@Column()
nodeId: string | null;
@Column()
orgRevisionId: string;
@Column()
meaning: string | null;
@Column()
formula: string | null;
}

24
src/entities/position.ts Normal file
View file

@ -0,0 +1,24 @@
import { Entity, Column, OneToMany, ManyToMany, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { KpiLink } from "./kpiLink";
@Entity("position")
export class Position extends EntityBase {
@Column({
nullable: true,
comment: "ชื่อตำแหน่ง",
default: null,
})
name: string;
@Column({
nullable: true,
length: 40,
comment: "ไอดีเชื่อมโยง",
})
kpiLinkId: string | null;
@ManyToOne(() => KpiLink, (kpiLink) => kpiLink.positions)
@JoinColumn({ name: "kpiLinkId" })
kpiLink: KpiLink;
}

View file

@ -0,0 +1,51 @@
import {
Controller,
Request,
Get,
Post,
Put,
Delete,
Patch,
Route,
Security,
Tags,
Path,
} from "tsoa";
import axios from "axios";
class CallAPI {
//Get
public async GetData(request: any, @Path() path: any) {
const token = request.headers.authorization;
const url = process.env.API + path;
try {
const response = await axios.get(url, {
headers: {
Authorization: `${token}`,
"Content-Type": "application/json",
},
});
return response.data.result;
} catch (error) {
throw error;
}
}
//Post
public async PostData(request: any, @Path() path: any, sendData: any) {
const token = request.headers.authorization;
const url = process.env.API + path;
try {
const response = await axios.post(url, sendData, {
headers: {
Authorization: `${token}`,
"Content-Type": "application/json",
},
});
return response.data.result;
} catch (error) {
throw error;
}
}
}
export default CallAPI;

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableKpiperiodAddYear1713439776331 implements MigrationInterface {
name = 'UpdateTableKpiperiodAddYear1713439776331'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiPeriod\` ADD \`year\` int NULL COMMENT 'ปีงบประมาณ'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiPeriod\` DROP COLUMN \`year\``);
}
}

View file

@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableKpirole1713445319950 implements MigrationInterface {
name = 'UpdateTableKpirole1713445319950'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`kpiRole\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`year\` int NULL COMMENT 'ปีงบประมาณ', \`round\` varchar(255) NULL COMMENT 'รอบการประเมิน', \`including\` varchar(255) NULL COMMENT 'รหัสตัวชี้วัด', \`includingName\` varchar(255) NULL COMMENT 'ชื่อตัวชี้วัด', \`target\` varchar(255) NULL COMMENT 'ค่าเป้าหมาย', \`unit\` int NULL COMMENT 'หน่วยนับ', \`weight\` int NULL COMMENT 'น้ำหนัก', \`achievement1\` varchar(255) NULL COMMENT 'ผลสำเร็จของงาน 1', \`achievement2\` varchar(255) NULL COMMENT 'ผลสำเร็จของงาน 2', \`achievement3\` varchar(255) NULL COMMENT 'ผลสำเร็จของงาน 3', \`achievement4\` varchar(255) NULL COMMENT 'ผลสำเร็จของงาน 4', \`achievement5\` varchar(255) NULL COMMENT 'ผลสำเร็จของงาน 5', \`rootId\` varchar(255) NULL COMMENT 'id หน่วยงาน', \`root\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน', \`rootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน', \`child1Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child1', \`child1\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child1', \`child1ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child1', \`child2Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child2', \`child2\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child2', \`child2ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child2', \`child3Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child3', \`child3\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child3', \`child3ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child3', \`child4Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child4', \`child4\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child4', \`child4ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child4', \`orgRevisionId\` varchar(255) NULL COMMENT 'id revision', \`meaning\` varchar(255) NULL COMMENT 'นิยามหรือความหมาย', \`formula\` varchar(255) NULL COMMENT 'สูตรคำนวณ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`kpiLink\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`kpiGroupId\` varchar(40) NULL COMMENT 'ไอดีกลุ่มงาน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`position\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'ชื่อตำแหน่ง', \`kpiLinkId\` varchar(40) NULL COMMENT 'ไอดีเชื่อมโยง', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`kpiPlan\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`year\` int NULL COMMENT 'ปีงบประมาณ', \`round\` varchar(255) NULL COMMENT 'รอบการประเมิน', \`including\` varchar(255) NULL COMMENT 'รหัสตัวชี้วัด', \`includingName\` varchar(255) NULL COMMENT 'ชื่อตัวชี้วัด', \`target\` varchar(255) NULL COMMENT 'ค่าเป้าหมาย', \`unit\` int NULL COMMENT 'หน่วยนับ', \`weight\` int NULL COMMENT 'น้ำหนัก', \`achievement1\` varchar(255) NULL COMMENT 'ผลสำเร็จของงาน 1', \`achievement2\` varchar(255) NULL COMMENT 'ผลสำเร็จของงาน 2', \`achievement3\` varchar(255) NULL COMMENT 'ผลสำเร็จของงาน 3', \`achievement4\` varchar(255) NULL COMMENT 'ผลสำเร็จของงาน 4', \`achievement5\` varchar(255) NULL COMMENT 'ผลสำเร็จของงาน 5', \`meaning\` varchar(255) NULL COMMENT 'นิยามหรือความหมาย', \`formula\` varchar(255) NULL COMMENT 'สูตรคำนวณ', \`rootId\` varchar(255) NULL COMMENT 'id หน่วยงาน', \`root\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน', \`rootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน', \`child1Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child1', \`child1\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child1', \`child1ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child1', \`child2Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child2', \`child2\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child2', \`child2ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child2', \`child3Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child3', \`child3\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child3', \`child3ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child3', \`child4Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child4', \`child4\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child4', \`child4ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child4', \`orgRevisionId\` varchar(255) NULL COMMENT 'id revision', \`strategyChild1Id\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild1', \`strategyChild1\` varchar(255) NULL COMMENT 'ชื่อ strategyChild1', \`strategyChild2Id\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild2', \`strategyChild2\` varchar(255) NULL COMMENT 'ชื่อ strategyChild2', \`strategyChild3Id\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild3', \`strategyChild3\` varchar(255) NULL COMMENT 'ชื่อ strategyChild3', \`strategyChild4Id\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild4', \`strategyChild4\` varchar(255) NULL COMMENT 'ชื่อ strategyChild4', \`strategyChild5Id\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild5', \`strategyChild5\` varchar(255) NULL COMMENT 'ชื่อ strategyChild5', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`kpiLink\` ADD CONSTRAINT \`FK_f9a726927536e13e4bd715d8a18\` FOREIGN KEY (\`kpiGroupId\`) REFERENCES \`kpiGroup\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`position\` ADD CONSTRAINT \`FK_7794963ed1acf98e9d01efa870f\` FOREIGN KEY (\`kpiLinkId\`) REFERENCES \`kpiLink\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`position\` DROP FOREIGN KEY \`FK_7794963ed1acf98e9d01efa870f\``);
await queryRunner.query(`ALTER TABLE \`kpiLink\` DROP FOREIGN KEY \`FK_f9a726927536e13e4bd715d8a18\``);
await queryRunner.query(`DROP TABLE \`kpiPlan\``);
await queryRunner.query(`DROP TABLE \`position\``);
await queryRunner.query(`DROP TABLE \`kpiLink\``);
await queryRunner.query(`DROP TABLE \`kpiRole\``);
}
}