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

@ -277,6 +277,92 @@ export class kpiCapacityController extends Controller {
return new HttpSuccess(kpiCapacity);
}
/**
* API
*
* @summary
*
* @param {string} id Guid, *Id
*/
@Get("edit/{id}")
@Example({
type: "HEAD",
name: "ชื่อสมรรถนะ",
description: "คำจำกัดความ",
kpiCapacityDetails: [
{
level: 1,
description: "คำอธิบายระดับ",
},
],
})
async GetKpiCapacityByIdEdit(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionGet(request, "SYS_EVA_COMPETENCY");
const kpiCapacity = await this.kpiCapacityRepository.findOne({
where: { id: id },
select: ["type", "name", "description"],
});
if (!kpiCapacity) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายการสมรรถนะนี้");
}
const kpiCapacityDetails = await this.kpiCapacityDetailRepository.find({
where: { kpiCapacityId: id },
select: ["level", "description"],
order: { level: "ASC" },
});
const mapData = {
type: kpiCapacity.type,
name: kpiCapacity.name,
description: kpiCapacity.description,
capacityDetails: kpiCapacityDetails,
};
return new HttpSuccess(mapData);
}
/**
* API
*
* @summary
*
*/
@Get("edit")
async listKpiCapacityEdit(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("type") type?: string,
@Query("keyword") keyword?: string,
) {
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
const [kpiCapacity, total] = await AppDataSource.getRepository(KpiCapacity)
.createQueryBuilder("kpiCapacity")
.leftJoinAndSelect("kpiCapacity.kpiCapacityDetails", "kpiCapacityDetail")
.andWhere(
keyword == undefined
? "1=1"
: [{ name: Like(`%${keyword}%`) }, { description: Like(`%${keyword}%`) }],
)
.andWhere(type == undefined ? "1=1" : { type: type })
.orderBy("kpiCapacity.createdAt", "ASC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const mapFormula = kpiCapacity.map((item) => ({
id: item.id,
type: item.type,
name: item.name,
description: item.description,
capacityDetails: item.kpiCapacityDetails.map((detail) => {
return {
id: detail.id,
description: detail.description,
level: detail.level,
capacityId: detail.kpiCapacityId,
};
}),
}));
return new HttpSuccess({ data: mapFormula, total });
}
/**
* API
*
@ -297,7 +383,6 @@ export class kpiCapacityController extends Controller {
],
})
async GetKpiCapacityById(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
const kpiCapacity = await this.kpiCapacityRepository.findOne({
where: { id: id },
select: ["type", "name", "description"],
@ -333,7 +418,6 @@ export class kpiCapacityController extends Controller {
@Query("type") type?: string,
@Query("keyword") keyword?: string,
) {
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
const [kpiCapacity, total] = await AppDataSource.getRepository(KpiCapacity)
.createQueryBuilder("kpiCapacity")
.leftJoinAndSelect("kpiCapacity.kpiCapacityDetails", "kpiCapacityDetail")

View file

@ -68,8 +68,8 @@ export class kpiEvaluationController extends Controller {
/**
* API list
*/
@Get()
async listKpiEvaluation(
@Get("edit")
async listKpiEvaluationEdit(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@ -100,4 +100,39 @@ export class kpiEvaluationController extends Controller {
}));
return new HttpSuccess({ data: formatted, total });
}
/**
* API list
*/
@Get()
async listKpiEvaluation(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
let whereClause: any = {};
if (keyword !== undefined && keyword !== "") {
whereClause = {
where: [{ description: Like(`%${keyword}%`) }],
};
whereClause.where.push({ level: Like(`%${keyword}%`) });
}
const [kpiEvaluation, total] = await this.kpiEvaluationRepository.findAndCount({
...whereClause,
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
order: {
level: "DESC",
},
});
const formatted = kpiEvaluation.map((item) => ({
id: item.id,
level: item.level,
description: item.description,
}));
return new HttpSuccess({ data: formatted, total });
}
}

View file

@ -106,6 +106,56 @@ export class kpiGroupController extends Controller {
return new HttpSuccess(id);
}
/**
* API
* @param id
*/
@Get("edit/{id}")
@Example({
nameGroupKPI: "string", //ชื่อกลุ่มงาน
})
async KpiGroupByIdEdit(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionGet(request, "SYS_EVA_COMPETENCY");
const kpiGroup = await this.kpiGroupRepository.findOne({
where: { id: id },
select: ["nameGroupKPI"],
});
if (!kpiGroup) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้");
}
return new HttpSuccess(kpiGroup);
}
/**
* API list
* @param page
* @param pageSize
*/
@Get("edit")
async listKpiGroupEdit(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
let whereClause: any = {};
if (keyword !== undefined && keyword !== "") {
whereClause = {
where: [{ nameGroupKPI: Like(`%${keyword}%`) }],
};
}
const [kpiGroup, total] = await this.kpiGroupRepository.findAndCount({
...whereClause,
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
order: { createdAt: "ASC" },
});
return new HttpSuccess({ data: kpiGroup, total });
}
/**
* API
* @param id
@ -115,7 +165,6 @@ export class kpiGroupController extends Controller {
nameGroupKPI: "string", //ชื่อกลุ่มงาน
})
async KpiGroupById(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
const kpiGroup = await this.kpiGroupRepository.findOne({
where: { id: id },
select: ["nameGroupKPI"],
@ -156,7 +205,6 @@ export class kpiGroupController extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
let whereClause: any = {};
if (keyword !== undefined && keyword !== "") {

View file

@ -172,9 +172,9 @@ export class kpiLinkController extends Controller {
* API
* @param id
*/
@Get("{id}")
async KpiLinkById(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
@Get("edit/{id}")
async KpiLinkByIdEdit(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionGet(request, "SYS_EVA_COMPETENCY");
const kpiLink = await this.kpiLinkRepository.findOne({
where: { id: id },
relations: ["positions", "kpiCapacitys", "kpiGroup"],
@ -202,38 +202,13 @@ export class kpiLinkController extends Controller {
};
return new HttpSuccess(formattedResponse);
}
/**
* API
* @param id
*/
@Delete("{id}")
async deleteKpiLink(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_EVA_COMPETENCY");
const kpiLink = await this.kpiLinkRepository.findOne({
where: { id: id },
relations: ["kpiCapacitys"],
});
if (!kpiLink) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
}
kpiLink.kpiCapacitys = [];
await this.kpiLinkRepository.save(kpiLink, { data: request });
await this.positionRepository.delete({ kpiLinkId: id });
await this.kpiLinkRepository.delete({ id: id });
return new HttpSuccess();
}
/**
* API list
* @param page
* @param pageSize
*/
@Get()
async listKpiLink(
@Get("edit")
async listKpiLinkEdit(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@ -281,6 +256,134 @@ export class kpiLinkController extends Controller {
});
}
const formattedResponse = kpiLink.map((item) => ({
id: item.id,
groupName: item.kpiGroup.nameGroupKPI,
groupId: item.kpiGroup.id,
positions: item.positions.map((position) => ({
id: position.id,
name: position.name,
})),
capacitys: item.kpiCapacitys.map((capacity) => ({
id: capacity.id,
name: capacity.name,
type: capacity.type,
description: capacity.description,
})),
}));
return new HttpSuccess({ data: formattedResponse, total });
}
/**
* API
* @param id
*/
@Get("{id}")
async KpiLinkById(@Request() request: RequestWithUser, @Path() id: string) {
const kpiLink = await this.kpiLinkRepository.findOne({
where: { id: id },
relations: ["positions", "kpiCapacitys", "kpiGroup"],
order: {
createdAt: "ASC",
},
});
if (!kpiLink) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
}
const formattedResponse = {
id: kpiLink.id,
groupName: kpiLink.kpiGroup.nameGroupKPI,
groupId: kpiLink.kpiGroup.id,
positions: kpiLink.positions.map((position) => ({
id: position.id,
name: position.name,
})),
capacitys: kpiLink.kpiCapacitys.map((capacity) => ({
id: capacity.id,
name: capacity.name,
type: capacity.type,
description: capacity.description,
})),
};
return new HttpSuccess(formattedResponse);
}
/**
* API
* @param id
*/
@Delete("{id}")
async deleteKpiLink(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_EVA_COMPETENCY");
const kpiLink = await this.kpiLinkRepository.findOne({
where: { id: id },
relations: ["kpiCapacitys"],
});
if (!kpiLink) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
}
kpiLink.kpiCapacitys = [];
await this.kpiLinkRepository.save(kpiLink, { data: request });
await this.positionRepository.delete({ kpiLinkId: id });
await this.kpiLinkRepository.delete({ id: id });
return new HttpSuccess();
}
/**
* API list
* @param page
* @param pageSize
*/
@Get()
async listKpiLink(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
const [_kpiLink, _total] = await AppDataSource.getRepository(KpiLink)
.createQueryBuilder("kpiLink")
.leftJoinAndSelect("kpiLink.kpiGroup", "kpiGroup")
.leftJoinAndSelect("kpiLink.positions", "positions")
.leftJoinAndSelect("kpiLink.kpiCapacitys", "kpiCapacitys")
.andWhere(
new Brackets((qb) => {
qb.orWhere("kpiGroup.nameGroupKPI LIKE :keyword", { keyword: `%${keyword}%` })
.orWhere("positions.name LIKE :keyword", { keyword: `%${keyword}%` })
.orWhere("kpiCapacitys.name LIKE :keyword", { keyword: `%${keyword}%` });
}),
)
.getManyAndCount();
if (_total === 0) {
return new HttpSuccess({
data: [],
total: 0,
});
}
const [kpiLink, total] = await AppDataSource.getRepository(KpiLink)
.createQueryBuilder("kpiLink")
.leftJoinAndSelect("kpiLink.kpiGroup", "kpiGroup")
.leftJoinAndSelect("kpiLink.positions", "positions")
.leftJoinAndSelect("kpiLink.kpiCapacitys", "kpiCapacitys")
.andWhere("kpiLink.id In (:id)", {
id: _kpiLink.map((x) => x.id),
})
.skip((page - 1) * pageSize)
.take(pageSize)
.orderBy("kpiLink.createdAt", "ASC")
.getManyAndCount();
if (_total === 0) {
return new HttpSuccess({
data: [],
total: 0,
});
}
const formattedResponse = kpiLink.map((item) => ({
id: item.id,
groupName: item.kpiGroup.nameGroupKPI,

View file

@ -202,6 +202,7 @@ export class kpiPeriodController extends Controller {
@Query("year") year?: number,
@Query("keyword") keyword?: string,
) {
await new permission().PermissionDelete(request, "SYS_KPI_ROUND");
const [kpiPeriod, total] = await AppDataSource.getRepository(KpiPeriod)
.createQueryBuilder("kpiPeriod")
.andWhere(
@ -255,7 +256,6 @@ export class kpiPeriodController extends Controller {
@Query("year") year?: number,
@Query("keyword") keyword?: string,
) {
await new permission().PermissionDelete(request, "SYS_KPI_ROUND");
const [kpiPeriod, total] = await AppDataSource.getRepository(KpiPeriod)
.createQueryBuilder("kpiPeriod")
.andWhere(

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 = "";

View file

@ -273,13 +273,84 @@ export class kpiRoleController extends Controller {
return new HttpSuccess(id);
}
/**
* API
* @param id Guid, *Id
*/
@Get("edit/{id}")
async GetKpiRoleByIdEdit(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionGet(request, "SYS_EVA_INDICATOR");
const kpiRole = await this.kpiRoleRepository.findOne({
where: { id: id },
relations: { kpiPeriod: true },
});
if (!kpiRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
}
let node = null;
let nodeId = null;
let nodeName = null;
if (kpiRole.child4Id != null) {
node = 4;
nodeId = kpiRole.child4Id;
nodeName = kpiRole.child4;
} else if (kpiRole.child3Id != null) {
node = 3;
nodeId = kpiRole.child3Id;
nodeName = kpiRole.child3;
} else if (kpiRole.child2Id != null) {
node = 2;
nodeId = kpiRole.child2Id;
nodeName = kpiRole.child2;
} else if (kpiRole.child1Id != null) {
node = 1;
nodeId = kpiRole.child1Id;
nodeName = kpiRole.child1;
} else if (kpiRole.rootId != null) {
node = 0;
nodeId = kpiRole.rootId;
nodeName = kpiRole.root;
}
const formattedData = {
id: kpiRole.id,
// year: kpiRole.kpiPeriod == null ? null : kpiRole.kpiPeriod.year,
// round: kpiRole.kpiPeriod == null ? null : kpiRole.kpiPeriod.durationKPI,
year: kpiRole.year == null ? null : kpiRole.year,
round: kpiRole.period == null ? null : kpiRole.period,
kpiPeriodId: kpiRole.kpiPeriodId,
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,
root: kpiRole.rootId,
child1: kpiRole.child1Id,
child2: kpiRole.child2Id,
child3: kpiRole.child3Id,
child4: kpiRole.child4Id,
node: node,
nodeId: nodeId,
nodeName: nodeName,
orgRevisionId: kpiRole.orgRevisionId,
position: kpiRole.position,
documentInfoEvidence: kpiRole.documentInfoEvidence,
};
return new HttpSuccess(formattedData);
}
/**
* API
* @param id Guid, *Id
*/
@Get("{id}")
async GetKpiRoleById(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
const kpiRole = await this.kpiRoleRepository.findOne({
where: { id: id },
relations: { kpiPeriod: true },
@ -367,6 +438,135 @@ export class kpiRoleController extends Controller {
isAll?: boolean | false;
// isNull?: boolean | false;
},
) {
let condition = "";
let parameters: any = {};
if (requestBody.isAll === false) {
switch (requestBody.node) {
case 0:
condition = "kpiRole.rootId LIKE :nodeId AND kpiRole.child1Id IS NULL";
break;
case 1:
condition = "kpiRole.child1Id LIKE :nodeId AND kpiRole.child2Id IS NULL";
break;
case 2:
condition = "kpiRole.child2Id LIKE :nodeId AND kpiRole.child3Id IS NULL";
break;
case 3:
condition = "kpiRole.child3Id LIKE :nodeId AND kpiRole.child4Id IS NULL";
break;
case 4:
condition = "kpiRole.child4Id LIKE :nodeId";
break;
default:
condition = "1=1";
break;
}
parameters.nodeId = `%${requestBody.nodeId}%`;
} else {
switch (requestBody.node) {
case 0:
condition = "kpiRole.rootId LIKE :nodeId";
break;
case 1:
condition = "kpiRole.child1Id LIKE :nodeId";
break;
case 2:
condition = "kpiRole.child2Id LIKE :nodeId";
break;
case 3:
condition = "kpiRole.child3Id LIKE :nodeId";
break;
case 4:
condition = "kpiRole.child4Id LIKE :nodeId";
break;
default:
condition = "1=1";
break;
}
parameters.nodeId = `%${requestBody.nodeId}%`;
}
// if (requestBody.year && requestBody.period && requestBody.isNull === true) {
// condition += ` AND (kpiRole.year LIKE :year OR kpiRole.year IS NULL) AND (kpiRole.period LIKE :period OR kpiRole.period IS NULL)`;
// parameters.year = `%${requestBody.year}%`;
// parameters.period = `%${requestBody.period}%`;
// }
const [kpiRole, total] = await AppDataSource.getRepository(KpiRole)
.createQueryBuilder("kpiRole")
.leftJoinAndSelect("kpiRole.kpiPeriod", "kpiPeriod")
.andWhere(condition, parameters)
// .andWhere(
// requestBody.year && requestBody.period
// ? "kpiRole.year LIKE :year AND kpiRole.period LIKE :period"
// : "1=1",
// {
// year: `%${requestBody.year}%`,
// period: `%${requestBody.period}%`,
// },
// )
.andWhere(requestBody.year ? "kpiRole.year LIKE :year" : "1=1", {
year: `%${requestBody.year}%`,
})
.andWhere(requestBody.period ? "kpiRole.period LIKE :period" : "1=1", {
period: `%${requestBody.period}%`,
})
.andWhere(requestBody.position != undefined ? "kpiRole.position LIKE :position" : "1=1", {
position: `%${requestBody.position}%`,
})
.andWhere(
new Brackets((qb) => {
qb.orWhere("kpiRole.including LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiRole.includingName LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiRole.year LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiRole.period LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
});
}),
)
.select([
"kpiRole.id",
"kpiPeriod.year",
"kpiPeriod.durationKPI",
"kpiRole.including",
"kpiRole.includingName",
"kpiRole.createdAt",
])
.orderBy("kpiRole.createdAt", "DESC")
.skip((requestBody.page - 1) * requestBody.pageSize)
.take(requestBody.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: kpiRole, total });
}
/**
* API list
* @param page
* @param pageSize
* @param keyword
*/
@Post("search-edit")
async listKpiRoleEdit(
@Request() request: RequestWithUser,
@Body()
requestBody: {
page: number;
pageSize: number;
year?: string | null;
period?: string | null;
nodeId?: string | null;
node?: number | null;
position?: string | null;
keyword?: string | null;
isAll?: boolean | false;
// isNull?: boolean | false;
},
) {
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
let condition = "";

View file

@ -117,13 +117,51 @@ export class kpiSpecialController extends Controller {
return new HttpSuccess(id);
}
/**
* API Special
* @param id Guid, *Id Special
*/
@Get("edit/{id}")
async GetKpiSpecialByIdEdit(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionGet(request, "SYS_EVA_INDICATOR");
const KpiSpecial = await this.kpiSpecialRepository.findOne({
where: { id: id },
});
if (!KpiSpecial) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัด Specialนี้");
}
const mapData = {
id: KpiSpecial.id,
period: KpiSpecial.period,
year: KpiSpecial.year,
including: KpiSpecial.including,
includingName: KpiSpecial.includingName,
target: KpiSpecial.target,
unit: KpiSpecial.unit,
weight: KpiSpecial.weight,
point: KpiSpecial.point,
summary: KpiSpecial.summary,
documentInfoEvidence: KpiSpecial.documentInfoEvidence,
startDate: KpiSpecial.startDate,
endDate: KpiSpecial.endDate,
achievement1: KpiSpecial.achievement1,
achievement2: KpiSpecial.achievement2,
achievement3: KpiSpecial.achievement3,
achievement4: KpiSpecial.achievement4,
achievement5: KpiSpecial.achievement5,
meaning: KpiSpecial.meaning,
formula: KpiSpecial.formula,
};
return new HttpSuccess(mapData);
}
/**
* API Special
* @param id Guid, *Id Special
*/
@Get("{id}")
async GetKpiSpecialById(@Request() request: RequestWithUser, @Path() id: string) {
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
const KpiSpecial = await this.kpiSpecialRepository.findOne({
where: { id: id },
});
@ -173,6 +211,70 @@ export class kpiSpecialController extends Controller {
period?: string | null;
keyword?: string | null;
},
) {
// let condition: any = {};
// if (requestBody.keyword !== undefined && requestBody.keyword !== "") {
// condition = {
// where: [
// {
// including: Like(`%${requestBody.keyword}%`),
// includingName: Like(`%${requestBody.keyword}%`),
// },
// ],
// };
// }
const [kpiSpecial, total] = await AppDataSource.getRepository(KpiSpecial)
.createQueryBuilder("kpiSpecial")
// .andWhere(condition)
.andWhere(requestBody.year ? "kpiSpecial.year LIKE :year" : "1=1", {
year: `%${requestBody.year}%`,
})
.andWhere(requestBody.period ? "kpiSpecial.period LIKE :period" : "1=1", {
period: `%${requestBody.period}%`,
})
.andWhere(
new Brackets((qb) => {
qb.orWhere("kpiSpecial.including LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
}).orWhere("kpiSpecial.includingName LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
});
}),
)
.select([
"kpiSpecial.id",
"kpiSpecial.year",
"kpiSpecial.period",
"kpiSpecial.including",
"kpiSpecial.includingName",
"kpiSpecial.createdAt",
])
.orderBy("kpiSpecial.createdAt", "DESC")
.skip((requestBody.page - 1) * requestBody.pageSize)
.take(requestBody.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: kpiSpecial, total });
}
/**
* API list Special
* @param page
* @param pageSize
* @param keyword
*/
@Post("search-edit")
async listKpiSpecialEdit(
@Request() request: RequestWithUser,
@Body()
requestBody: {
page: number;
pageSize: number;
year?: string | null;
period?: string | null;
keyword?: string | null;
},
) {
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
// let condition: any = {};

View file

@ -202,7 +202,7 @@ export class KpiUserEvaluationController extends Controller {
*/
@Post("list")
async listKpiListEvaluation(
@Request() request: { user: Record<string, any> },
@Request() request: RequestWithUser,
@Body()
requestBody: {
page: number;
@ -215,6 +215,124 @@ export class KpiUserEvaluationController extends Controller {
evaluating?: boolean | null;
},
) {
await new permission().PermissionDelete(request, "SYS_KPI_LIST");
let conditionFullName =
"CONCAT(kpiUserEvaluation.prefix, kpiUserEvaluation.firstName, ' ', kpiUserEvaluation.lastName) LIKE :keyword";
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)
.createQueryBuilder("kpiUserEvaluation")
.andWhere(requestBody.kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", {
kpiPeriodId: requestBody.kpiPeriodId,
})
.andWhere(
requestBody.status != null && requestBody.status != undefined
? "evaluationstatus LIKE :status"
: "1=1",
{
status:
requestBody.status == null || requestBody.status == undefined
? null
: requestBody.status.trim().toUpperCase(),
},
)
.andWhere(
requestBody.results != null && requestBody.results != undefined
? "evaluationResults LIKE :results"
: "1=1",
{
results:
requestBody.results == null || requestBody.results == undefined
? null
: requestBody.results.trim().toUpperCase(),
},
)
.andWhere(
new Brackets((qb) => {
qb.orWhere("kpiUserEvaluation.prefix LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiUserEvaluation.firstName LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiUserEvaluation.lastName LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiUserEvaluation.org LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiUserEvaluation.position LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiUserEvaluation.posTypeName LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere("kpiUserEvaluation.posLevelName LIKE :keyword", {
keyword: `%${requestBody.keyword}%`,
})
.orWhere(conditionFullName, {
keyword: `%${requestBody.keyword}%`,
});
}),
)
.orderBy("kpiUserEvaluation.createdAt", "ASC")
.skip((requestBody.page - 1) * requestBody.pageSize)
.take(requestBody.pageSize)
.getManyAndCount();
const mapData = kpiUserEvaluation.map((item) => {
const fullNameParts = [item.child4, item.child3, item.child2, item.child1, item.org];
const organization = fullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
return {
id: item.id,
profileId: item.profileId,
prefix: item.prefix,
firstname: item.firstName,
lastname: item.lastName,
kpiPeriodId: item.kpiPeriodId,
evaluationStatus: item.evaluationStatus,
evaluationResults: item.evaluationResults,
createdAt: item.createdAt,
evaluatorId: item.evaluatorId,
commanderId: item.commanderId,
commanderHighId: item.commanderHighId,
root: item.org ? item.org : null,
rootId: item.orgId ? item.orgId : null,
position: item.position ? item.position : null,
// posTypeId: item.posTypeId,
posTypeName: item.posTypeName ? item.posTypeName : null,
// posLevelId: item.posLevelId,
posLevelName: item.posLevelName ? item.posLevelName : null,
organization: organization ? organization : null,
};
});
return new HttpSuccess({ data: mapData, total });
}
/**
* API
*
* @summary
*
*/
@Post("list-announce")
async listKpiListEvaluationAnnounce(
@Request() request: RequestWithUser,
@Body()
requestBody: {
page: number;
pageSize: number;
kpiPeriodId?: string;
keyword?: string;
status?: string | null;
results?: string | null;
reqedit?: string | null;
evaluating?: boolean | null;
},
) {
await new permission().PermissionDelete(request, "SYS_RESULT");
let conditionFullName =
"CONCAT(kpiUserEvaluation.prefix, kpiUserEvaluation.firstName, ' ', kpiUserEvaluation.lastName) LIKE :keyword";
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)