no message

This commit is contained in:
kittapath 2024-08-22 17:21:00 +07:00
parent dfd9ebb3c1
commit 483ad486dc
9 changed files with 943 additions and 41 deletions

View file

@ -296,13 +296,114 @@ export class kpiPlanController extends Controller {
return new HttpSuccess(id);
}
/**
* API
* @param id Guid, *Id
*/
@Get("edit/{id}")
async GetKpiPlanByIdEdit(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionGet(request, "SYS_EVA_INDICATOR");
const kpiPlan = await this.kpiPlanRepository.findOne({
where: { id: id },
relations: { kpiPeriod: true },
});
if (!kpiPlan) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้");
}
let node = null;
let nodeId = null;
let nodeName = null;
if (kpiPlan.child4Id != null) {
node = 4;
nodeId = kpiPlan.child4Id;
nodeName = kpiPlan.child4;
} else if (kpiPlan.child3Id != null) {
node = 3;
nodeId = kpiPlan.child3Id;
nodeName = kpiPlan.child3;
} else if (kpiPlan.child2Id != null) {
node = 2;
nodeId = kpiPlan.child2Id;
nodeName = kpiPlan.child2;
} else if (kpiPlan.child1Id != null) {
node = 1;
nodeId = kpiPlan.child1Id;
nodeName = kpiPlan.child1;
} else if (kpiPlan.rootId != null) {
node = 0;
nodeId = kpiPlan.rootId;
nodeName = kpiPlan.root;
}
let strategy = null;
let strategyId = null;
let strategyName = null;
if (kpiPlan.strategyChild5Id != null) {
strategy = 5;
strategyId = kpiPlan.strategyChild5Id;
} else if (kpiPlan.strategyChild4Id != null) {
strategy = 4;
strategyId = kpiPlan.strategyChild4Id;
strategyName = kpiPlan.strategyChild4;
} else if (kpiPlan.strategyChild3Id != null) {
strategy = 3;
strategyId = kpiPlan.strategyChild3Id;
strategyName = kpiPlan.strategyChild3;
} else if (kpiPlan.strategyChild2Id != null) {
strategy = 2;
strategyId = kpiPlan.strategyChild2Id;
strategyName = kpiPlan.strategyChild2;
} else if (kpiPlan.strategyChild1Id != null) {
strategy = 1;
strategyId = kpiPlan.strategyChild1Id;
strategyName = kpiPlan.strategyChild1;
}
const formattedData = {
id: kpiPlan.id,
// year: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.year,
// round: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.durationKPI,
year: kpiPlan.year == null ? null : kpiPlan.year,
round: kpiPlan.period == null ? null : kpiPlan.period,
kpiPeriodId: kpiPlan.kpiPeriodId,
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,
root: kpiPlan.rootId,
child1: kpiPlan.child1Id,
child2: kpiPlan.child2Id,
child3: kpiPlan.child3Id,
child4: kpiPlan.child4Id,
node: node,
nodeId: nodeId,
nodeName: nodeName,
orgRevisionId: kpiPlan.orgRevisionId,
strategy: strategy,
strategyId: strategyId,
strategyName: strategyName,
strategyChild1: kpiPlan.strategyChild1Id,
strategyChild2: kpiPlan.strategyChild2Id,
strategyChild3: kpiPlan.strategyChild3Id,
strategyChild4: kpiPlan.strategyChild4Id,
strategyChild5: kpiPlan.strategyChild5Id,
documentInfoEvidence: kpiPlan.documentInfoEvidence,
};
return new HttpSuccess(formattedData);
}
/**
* API
* @param id Guid, *Id
*/
@Get("{id}")
async GetKpiPlanById(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
const kpiPlan = await this.kpiPlanRepository.findOne({
where: { id: id },
relations: { kpiPeriod: true },
@ -419,6 +520,117 @@ export class kpiPlanController extends Controller {
isAll?: boolean | false;
// isNull?: boolean | false;
},
) {
let condition = "";
let parameters: any = {};
if (requestBody.isAll === false) {
switch (requestBody.node) {
case 0:
condition = "kpiPlan.rootId LIKE :nodeId AND kpiPlan.child1Id IS NULL";
break;
case 1:
condition = "kpiPlan.child1Id LIKE :nodeId AND kpiPlan.child2Id IS NULL";
break;
case 2:
condition = "kpiPlan.child2Id LIKE :nodeId AND kpiPlan.child3Id IS NULL";
break;
case 3:
condition = "kpiPlan.child3Id LIKE :nodeId AND kpiPlan.child4Id IS NULL";
break;
case 4:
condition = "kpiPlan.child4Id LIKE :nodeId";
break;
default:
condition = "1=1";
break;
}
parameters.nodeId = `%${requestBody.nodeId}%`;
} else {
switch (requestBody.node) {
case 0:
condition = "kpiPlan.rootId LIKE :nodeId";
break;
case 1:
condition = "kpiPlan.child1Id LIKE :nodeId";
break;
case 2:
condition = "kpiPlan.child2Id LIKE :nodeId";
break;
case 3:
condition = "kpiPlan.child3Id LIKE :nodeId";
break;
case 4:
condition = "kpiPlan.child4Id LIKE :nodeId";
break;
default:
condition = "1=1";
break;
}
parameters.nodeId = `%${requestBody.nodeId}%`;
}
const [kpiPlan, total] = await AppDataSource.getRepository(KpiPlan)
.createQueryBuilder("kpiPlan")
.leftJoinAndSelect("kpiPlan.kpiPeriod", "kpiPeriod")
.andWhere(condition, parameters)
.andWhere(requestBody.year ? "kpiPlan.year LIKE :year" : "1=1", {
year: `%${requestBody.year}%`,
})
.andWhere(requestBody.period ? "kpiPlan.period LIKE :period" : "1=1", {
period: `%${requestBody.period}%`,
})
.andWhere(
new Brackets((qb) => {
qb.orWhere("kpiPlan.including LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiPlan.includingName LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiPlan.year LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiPlan.period LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
});
}),
)
.select([
"kpiPlan.id",
"kpiPeriod.year",
"kpiPeriod.durationKPI",
"kpiPlan.including",
"kpiPlan.includingName",
"kpiPlan.createdAt",
])
.orderBy("kpiPlan.createdAt", "DESC")
.skip((requestBody.page - 1) * requestBody.pageSize)
.take(requestBody.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: kpiPlan, total });
}
/**
* API list
* @param page
* @param pageSize
* @param keyword
*/
@Post("search-edit")
async listKpiPlanEdit(
@Request() request: RequestWithUser,
@Body()
requestBody: {
page: number;
pageSize: number;
year?: string | null;
period?: string | null;
nodeId?: string | null;
node?: number | null;
keyword?: string | null;
isAll?: boolean | false;
// isNull?: boolean | false;
},
) {
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
let condition = "";