filter by dna

This commit is contained in:
Moss 2025-06-12 19:30:57 +07:00
parent 2178caa0c1
commit 309f295391

View file

@ -79,29 +79,41 @@ export class EvaluationController {
@Get("performance/user") @Get("performance/user")
async listPerformance(@Request() request: RequestWithUser) { async listPerformance(@Request() request: RequestWithUser) {
const list = await AppDataSource.getRepository(Evaluation) const list = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation") .createQueryBuilder("evaluation")
.where("evaluation.userId = :userId", { userId: request.user.sub }) .where("evaluation.userId = :userId", { userId: request.user.sub })
.andWhere("evaluation.step = :step", { step: "DONE" }) .andWhere("evaluation.step = :step", { step: "DONE" })
.andWhere("evaluation.evaluationResult IN (:...evaluationResult)", { .andWhere("evaluation.evaluationResult IN (:...evaluationResult)", {
evaluationResult: ["PASS", "NOTPASS"], evaluationResult: ["PASS", "NOTPASS"],
}) })
.select([ .select([
"evaluation.id", "evaluation.id",
"evaluation.type", "evaluation.type",
"evaluation.subject", "evaluation.subject",
"evaluation.evaluationResult", "evaluation.evaluationResult",
"evaluation.lastUpdatedAt", "evaluation.lastUpdatedAt",
]) ])
.orderBy("evaluation.lastUpdatedAt", "ASC") .orderBy("evaluation.lastUpdatedAt", "ASC")
.getMany(); .getMany();
const performance = list.map((item) => ({ const performance = list.map((item) => ({
id: item.id, id: item.id,
year: item.lastUpdatedAt?Extension.ToThaiYear(item.lastUpdatedAt.getFullYear()):null, year: item.lastUpdatedAt ? Extension.ToThaiYear(item.lastUpdatedAt.getFullYear()) : null,
type: item.type == "EXPERT" ? "ชำนาญการ" : item.type == "EXPERTISE" ? "เชียวชาญ" : item.type == "SPECIAL_EXPERT" ? "ชำนาญการพิเศษ": null, type:
subject: item.subject?item.subject[0]:null, item.type == "EXPERT"
evaluationResult: item.evaluationResult == "PASS" ? "ผ่าน" : item.evaluationResult == "NOTPASS" ? "ไม่ผ่าน" : null, ? "ชำนาญการ"
})); : item.type == "EXPERTISE"
? "เชียวชาญ"
: item.type == "SPECIAL_EXPERT"
? "ชำนาญการพิเศษ"
: null,
subject: item.subject ? item.subject[0] : null,
evaluationResult:
item.evaluationResult == "PASS"
? "ผ่าน"
: item.evaluationResult == "NOTPASS"
? "ไม่ผ่าน"
: null,
}));
return new HttpSuccess(performance); return new HttpSuccess(performance);
} }
@ -134,6 +146,12 @@ export class EvaluationController {
try { try {
// await new permission().PermissionList(request, "SYS_EVA_REQ"); // await new permission().PermissionList(request, "SYS_EVA_REQ");
let _data = await new permission().PermissionOrgList(request, "SYS_EVA_REQ"); let _data = await new permission().PermissionOrgList(request, "SYS_EVA_REQ");
await new CallAPI()
.PostData(request, "/org/finddna", _data)
.then((x) => {
_data = x;
})
.catch((x) => {});
const [evaluation, total] = await AppDataSource.getRepository(Evaluation) const [evaluation, total] = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation") .createQueryBuilder("evaluation")
.andWhere( .andWhere(
@ -350,17 +368,20 @@ export class EvaluationController {
} }
} }
/** /**
* API get template * API get template
* *
* @summary get template (ADMIN) * @summary get template (ADMIN)
* *
* @param {string} id id * @param {string} id id
*/ */
@Get("get-announce-template/{id}") @Get("get-announce-template/{id}")
async getAnnounceTemp(@Path() id: string, @Request() request: RequestWithUser) { async getAnnounceTemp(@Path() id: string, @Request() request: RequestWithUser) {
try { try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } , select: ["id","detailAnnounceStep5Body","detailAnnounceStep5Footer"]}); const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: ["id", "detailAnnounceStep5Body", "detailAnnounceStep5Footer"],
});
if (!evaluation) { if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน");
} }
@ -370,7 +391,7 @@ export class EvaluationController {
throw error; throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error); } else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
/** /**
* step * step
@ -510,24 +531,31 @@ export class EvaluationController {
if (!evaluation) { if (!evaluation) {
return `not found data`; return `not found data`;
} }
let _code = requestBody.type == "EXPERT" ? "ST05-1" : requestBody.type == "EXPERTISE" ? "ST05-1" : requestBody.type == "SPECIAL_EXPERT" ? "ST05-2" : "ST05-1"; let _code =
requestBody.type == "EXPERT"
? "ST05-1"
: requestBody.type == "EXPERTISE"
? "ST05-1"
: requestBody.type == "SPECIAL_EXPERT"
? "ST05-2"
: "ST05-1";
const announceTemplate5 = await this.announceTemplateRepository.findOne({ const announceTemplate5 = await this.announceTemplateRepository.findOne({
where:{ where: {
code : _code code: _code,
}, },
select: ["detailBody","detailFooter"] select: ["detailBody", "detailFooter"],
}) });
const before = null; const before = null;
await new CallAPI() await new CallAPI()
.GetData(request, `/org/profile/keycloak/commander/${request.user.sub}`) .GetData(request, `/org/profile/keycloak/commander/${request.user.sub}`)
.then(async (x) => { .then(async (x) => {
evaluation.rootDnaId = x.rootDnaId; evaluation.rootDnaId = x.rootDnaId;
evaluation.child1DnaId = x.child1DnaId; evaluation.child1DnaId = x.child1DnaId;
evaluation.child2DnaId = x.child2DnaId; evaluation.child2DnaId = x.child2DnaId;
evaluation.child3DnaId = x.child3DnaId; evaluation.child3DnaId = x.child3DnaId;
evaluation.child4DnaId = x.child4DnaId; evaluation.child4DnaId = x.child4DnaId;
}) })
.catch(); .catch();
evaluation.step = "PREPARE_DOC_V1"; evaluation.step = "PREPARE_DOC_V1";
evaluation.type = requestBody.type == "EXPERT" ? "EXPERT" : "SPECIAL_EXPERT"; evaluation.type = requestBody.type == "EXPERT" ? "EXPERT" : "SPECIAL_EXPERT";
evaluation.fullName = requestBody.fullName; evaluation.fullName = requestBody.fullName;
@ -538,10 +566,16 @@ export class EvaluationController {
evaluation.lastUpdateFullName = request.user.name; evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date(); evaluation.lastUpdatedAt = new Date();
evaluation.userId = request.user.sub; evaluation.userId = request.user.sub;
evaluation.detailAnnounceStep5Body = announceTemplate5?.detailBody??_null; evaluation.detailAnnounceStep5Body = announceTemplate5?.detailBody ?? _null;
evaluation.detailAnnounceStep5Footer = announceTemplate5?.detailFooter??_null; evaluation.detailAnnounceStep5Footer = announceTemplate5?.detailFooter ?? _null;
evaluation.positionArea = requestBody.positionArea && requestBody.positionArea !== "" ? requestBody.positionArea : _null; evaluation.positionArea =
evaluation.posExecutive = requestBody.posExecutive && requestBody.posExecutive !== "" ? requestBody.posExecutive : _null; requestBody.positionArea && requestBody.positionArea !== ""
? requestBody.positionArea
: _null;
evaluation.posExecutive =
requestBody.posExecutive && requestBody.posExecutive !== ""
? requestBody.posExecutive
: _null;
await this.evaluationRepository.save(evaluation, { data: request }); await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation }); setLogDataDiff(request, { before, after: evaluation });
@ -730,7 +764,7 @@ export class EvaluationController {
portfolio.evaluation = evaluation; portfolio.evaluation = evaluation;
await this.portfolioRepository.save(portfolio, { data: request }); await this.portfolioRepository.save(portfolio, { data: request });
setLogDataDiff(request, { before, after: portfolio }); setLogDataDiff(request, { before, after: portfolio });
}); });
//Performance //Performance
if (requestBody.performances != null) if (requestBody.performances != null)
@ -749,7 +783,7 @@ export class EvaluationController {
performance.evaluation = evaluation; performance.evaluation = evaluation;
await this.performanceRepository.save(performance, { data: request }); await this.performanceRepository.save(performance, { data: request });
setLogDataDiff(request, { before, after: performance }); setLogDataDiff(request, { before, after: performance });
}); });
//EvaluationLogs //EvaluationLogs
const evaluationLogs = new EvaluationLogs(); const evaluationLogs = new EvaluationLogs();
@ -1807,21 +1841,20 @@ export class EvaluationController {
}) })
.catch((x) => {}); .catch((x) => {});
await Promise.all( await Promise.all(
_director.map((director:any) => { _director.map((director: any) => {
return new CallAPI() return new CallAPI()
.PostData(request, "/placement/noti/keycloak", { .PostData(request, "/placement/noti/keycloak", {
subject: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 1`, subject: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 1`,
body: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 1`, body: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 1`,
receiverUserId: director.keycloak, receiverUserId: director.keycloak,
payload: "", payload: "",
isSendMail: true, isSendMail: true,
isSendInbox: true, isSendInbox: true,
isSendNotification: true, isSendNotification: true,
}) })
.then((x) => { .then((x) => {})
}) .catch((x) => {});
.catch((x) => {}); }),
})
); );
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
@ -2115,39 +2148,43 @@ export class EvaluationController {
} }
} }
/** /**
* API template * API template
* *
* @summary template (ADMIN) * @summary template (ADMIN)
* *
* @param {string} id id * @param {string} id id
*/ */
@Put("edit-announce-template/{id}") @Put("edit-announce-template/{id}")
async editAnnounceTemp(@Path() id: string, @Request() request: RequestWithUser, @Body() body: {detailBody: string, detailFooter: string}) { async editAnnounceTemp(
try { @Path() id: string,
await new permission().PermissionUpdate(request, "SYS_EVA_REQ"); @Request() request: RequestWithUser,
@Body() body: { detailBody: string; detailFooter: string },
) {
try {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ where: { id } }); const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) { if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
} }
const before = structuredClone(evaluation); const before = structuredClone(evaluation);
evaluation.detailAnnounceStep5Body = body.detailBody; evaluation.detailAnnounceStep5Body = body.detailBody;
evaluation.detailAnnounceStep5Footer = body.detailFooter; evaluation.detailAnnounceStep5Footer = body.detailFooter;
evaluation.lastUpdateUserId = request.user.sub; evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name; evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date(); evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request }); await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation }); setLogDataDiff(request, { before, after: evaluation });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
if (error instanceof HttpError) { if (error instanceof HttpError) {
throw error; throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error); } else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} }
} }
/** /**
* API * API
@ -2951,19 +2988,19 @@ export class EvaluationController {
if (!evaluation) { if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
} }
const _null:any = null; const _null: any = null;
evaluation.author = body.author; evaluation.author = body.author;
evaluation.subject = body.subject; evaluation.subject = body.subject;
evaluation.commanderFullname = body.commanderFullname; evaluation.commanderFullname = body.commanderFullname;
evaluation.commanderOrg = body.commanderOrg??_null; evaluation.commanderOrg = body.commanderOrg ?? _null;
evaluation.commanderOrgOld = body.commanderOrgOld??_null; evaluation.commanderOrgOld = body.commanderOrgOld ?? _null;
evaluation.commanderPosition = body.commanderPosition; evaluation.commanderPosition = body.commanderPosition;
evaluation.commanderPositionOld = body.commanderPositionOld??_null; evaluation.commanderPositionOld = body.commanderPositionOld ?? _null;
evaluation.commanderAboveFullname = body.commanderAboveFullname; evaluation.commanderAboveFullname = body.commanderAboveFullname;
evaluation.commanderAboveOrg = body.commanderAboveOrg??_null; evaluation.commanderAboveOrg = body.commanderAboveOrg ?? _null;
evaluation.commanderAboveOrgOld = body.commanderAboveOrgOld??_null; evaluation.commanderAboveOrgOld = body.commanderAboveOrgOld ?? _null;
evaluation.commanderAbovePosition = body.commanderAbovePosition; evaluation.commanderAbovePosition = body.commanderAbovePosition;
evaluation.commanderAbovePositionOld = body.commanderAbovePositionOld??_null; evaluation.commanderAbovePositionOld = body.commanderAbovePositionOld ?? _null;
evaluation.lastUpdateUserId = request.user.sub; evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name; evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date(); evaluation.lastUpdatedAt = new Date();
@ -3024,20 +3061,20 @@ export class EvaluationController {
if (!evaluation) { if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
} }
const _null:any = null; const _null: any = null;
evaluation.authorDoc2 = body.authorDoc2; evaluation.authorDoc2 = body.authorDoc2;
evaluation.subjectDoc2 = body.subjectDoc2; evaluation.subjectDoc2 = body.subjectDoc2;
evaluation.assignedPosition = body.assignedPosition; evaluation.assignedPosition = body.assignedPosition;
evaluation.commanderFullnameDoc2 = body.commanderFullnameDoc2; evaluation.commanderFullnameDoc2 = body.commanderFullnameDoc2;
evaluation.commanderOrgDoc2 = body.commanderOrgDoc2??_null; evaluation.commanderOrgDoc2 = body.commanderOrgDoc2 ?? _null;
evaluation.commanderOrgOldDoc2 = body.commanderOrgOldDoc2??_null; evaluation.commanderOrgOldDoc2 = body.commanderOrgOldDoc2 ?? _null;
evaluation.commanderPositionDoc2 = body.commanderPositionDoc2; evaluation.commanderPositionDoc2 = body.commanderPositionDoc2;
evaluation.commanderPositionOldDoc2 = body.commanderPositionOldDoc2??_null; evaluation.commanderPositionOldDoc2 = body.commanderPositionOldDoc2 ?? _null;
evaluation.commanderAboveFullnameDoc2 = body.commanderAboveFullnameDoc2; evaluation.commanderAboveFullnameDoc2 = body.commanderAboveFullnameDoc2;
evaluation.commanderAboveOrgDoc2 = body.commanderAboveOrgDoc2??_null; evaluation.commanderAboveOrgDoc2 = body.commanderAboveOrgDoc2 ?? _null;
evaluation.commanderAboveOrgOldDoc2 = body.commanderAboveOrgOldDoc2??_null; evaluation.commanderAboveOrgOldDoc2 = body.commanderAboveOrgOldDoc2 ?? _null;
evaluation.commanderAbovePositionDoc2 = body.commanderAbovePositionDoc2; evaluation.commanderAbovePositionDoc2 = body.commanderAbovePositionDoc2;
evaluation.commanderAbovePositionOldDoc2 = body.commanderAbovePositionOldDoc2??_null; evaluation.commanderAbovePositionOldDoc2 = body.commanderAbovePositionOldDoc2 ?? _null;
evaluation.isUpdated = true; evaluation.isUpdated = true;
evaluation.lastUpdateUserId = request.user.sub; evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name; evaluation.lastUpdateFullName = request.user.name;