add feild viewProfileEva

This commit is contained in:
AdisakKanthawilang 2025-02-07 18:04:12 +07:00
parent f01ed53d47
commit edd21d8777
2 changed files with 64 additions and 38 deletions

View file

@ -15,6 +15,7 @@ import HttpStatus from "../interfaces/http-status";
import { ProfileAssessment } from "../entities/ProfileAssessment";
import { log } from "console";
import { format } from "path";
import { viewProfileEvaluation } from "../entities/view/viewProfileEvaluation";
@Route("api/v1/org/unauthorize")
@Tags("OrganizationUnauthorize")
@ -28,6 +29,7 @@ export class OrganizationUnauthorizeController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
private profileAssessmentRepo = AppDataSource.getRepository(ProfileAssessment);
private viewProfileEvaluationRepo = AppDataSource.getRepository(viewProfileEvaluation);
/**
* API (unauthorize)
@ -1172,43 +1174,53 @@ export class OrganizationUnauthorizeController extends Controller {
* @summary 5
*
*/
@Get("calculate-Eva/{profileId}")
@Get("calculate-Eva/{node}/{nodeId}")
async calculateEva(
@Path() profileId: string,
@Path() node: string,
@Path() nodeId: string,
) {
// const list = await this.viewProfileEvaluation.findOne({
// where: {
// profileId: profileId,
// },
// });
const lists = await this.viewProfileEvaluationRepo.find({
// where:{
// profileId: profileId
// }
})
const formattedResults: any = {};
const year = new Date().getFullYear();
const years = [year, year - 1, year - 2, year - 3, year - 4];
lists.forEach((item: any) => {
if (!formattedResults[item.profileId]) {
formattedResults[item.profileId] = {
profileId: item.profileId,
yearAPR1: "-", periodAPR1: "-", resultAPR1: "-",
yearOCT1: "-", periodOCT1: "-", resultOCT1: "-",
yearAPR2: "-", periodAPR2: "-", resultAPR2: "-",
yearOCT2: "-", periodOCT2: "-", resultOCT2: "-",
yearAPR3: "-", periodAPR3: "-", resultAPR3: "-",
yearOCT3: "-", periodOCT3: "-", resultOCT3: "-",
yearAPR4: "-", periodAPR4: "-", resultAPR4: "-",
yearOCT4: "-", periodOCT4: "-", resultOCT4: "-",
yearAPR5: "-", periodAPR5: "-", resultAPR5: "-",
yearOCT5: "-", periodOCT5: "-", resultOCT5: "-"
};
}
const yearIndex = years.indexOf(parseInt(item.year));
if (yearIndex !== -1) {
const yearSuffix = yearIndex + 1;
const yearKey = `year${item.period}${yearSuffix}`;
const periodKey = `period${item.period}${yearSuffix}`;
const resultKey = `result${item.period}${yearSuffix}`;
formattedResults[item.profileId][yearKey] = item.year;
formattedResults[item.profileId][periodKey] = item.period;
formattedResults[item.profileId][resultKey] = item.result;
}
});
// const formattedData = list.map((item: any) => {
// const year = new Date().getFullYear();
// const result: any = {};
// for (let i = 1; i <= 5; i++) {
// const currentYear = year - (i - 1);
// const periodKey = `periodAPR${i}`;
// const resultKey = `resultAPR${i}`;
// result[`yearAPR${i}`] = item.year === currentYear ? item.year : "-";
// result[periodKey] = item.period ? item.period : "-";
// result[resultKey] = item.result ? item.result : "-";
// const octYear = year - (i - 1);
// const octPeriodKey = `periodOCT${i}`;
// const octResultKey = `resultOCT${i}`;
// result[`yearOCT${i}`] = item.year === octYear ? item.year : "-";
// result[octPeriodKey] = item.period ? item.period : "-";
// result[octResultKey] = item.result ? item.result : "-";
// }
// return result;
// });
return new HttpSuccess();
return new HttpSuccess(formattedResults);
}

View file

@ -2,12 +2,16 @@ import { ViewColumn, ViewEntity } from "typeorm";
@ViewEntity({
expression: `SELECT
\`profileId\`, \`period\`, \`year\`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result
FROM \`profileAssessment\`
\`profileId\`,\`period\`,\`year\`,\`posMaster\`.\`orgRootId\`,\`posMaster\`.\`orgChild1Id\`,\`posMaster\`.\`orgChild2Id\`,\`posMaster\`.\`orgChild3Id\`,\`posMaster\`.\`orgChild4Id\`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result
FROM\`profileAssessment\`
LEFT JOIN \`profile\` ON \`profileAssessment\`.\`profileId\` = \`profile\`.\`id\`
LEFT JOIN \`posMaster\` ON \`profile\`.\`id\` = \`posMaster\`.\`current_holderId\`
LEFT JOIN \`orgRevision\` ON \`posMaster\`.\`orgRevisionId\` = \`orgRevision\`.\`id\`
WHERE \`period\` Is not null
GROUP BY \`profileId\`, \`period\`, \`year\`
ORDER BY \`year\` desc , \`period\` asc
`,
AND \`orgRevision\`.\`orgRevisionIsCurrent\` = true
GROUP BY\`profileId\`,\`period\`,\`year\`,\`orgRootId\`,\`orgChild1Id\`,\`orgChild2Id\`,\`orgChild3Id\`,\`orgChild4Id\`
ORDER BY\`year\` desc ,\`period\` asc
`,
})
export class viewProfileEvaluation {
@ViewColumn()
@ -17,6 +21,16 @@ export class viewProfileEvaluation {
@ViewColumn()
year: number;
@ViewColumn()
orgRootId: string;
@ViewColumn()
orgChild1Id: string;
@ViewColumn()
orgChild2Id: string;
@ViewColumn()
orgChild3Id: string;
@ViewColumn()
orgChild4Id: string;
@ViewColumn()
recordCount: number;
@ViewColumn()
totalPointSum: number;