add feild viewProfileEva
This commit is contained in:
parent
f01ed53d47
commit
edd21d8777
2 changed files with 64 additions and 38 deletions
|
|
@ -15,6 +15,7 @@ import HttpStatus from "../interfaces/http-status";
|
||||||
import { ProfileAssessment } from "../entities/ProfileAssessment";
|
import { ProfileAssessment } from "../entities/ProfileAssessment";
|
||||||
import { log } from "console";
|
import { log } from "console";
|
||||||
import { format } from "path";
|
import { format } from "path";
|
||||||
|
import { viewProfileEvaluation } from "../entities/view/viewProfileEvaluation";
|
||||||
|
|
||||||
@Route("api/v1/org/unauthorize")
|
@Route("api/v1/org/unauthorize")
|
||||||
@Tags("OrganizationUnauthorize")
|
@Tags("OrganizationUnauthorize")
|
||||||
|
|
@ -28,6 +29,7 @@ export class OrganizationUnauthorizeController extends Controller {
|
||||||
private profileRepo = AppDataSource.getRepository(Profile);
|
private profileRepo = AppDataSource.getRepository(Profile);
|
||||||
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
|
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
private profileAssessmentRepo = AppDataSource.getRepository(ProfileAssessment);
|
private profileAssessmentRepo = AppDataSource.getRepository(ProfileAssessment);
|
||||||
|
private viewProfileEvaluationRepo = AppDataSource.getRepository(viewProfileEvaluation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API รายชื่อราชการที่เลื่อนเงินเดือน (unauthorize)
|
* API รายชื่อราชการที่เลื่อนเงินเดือน (unauthorize)
|
||||||
|
|
@ -1172,43 +1174,53 @@ export class OrganizationUnauthorizeController extends Controller {
|
||||||
* @summary ผลการประเมิน 5 ปีย้อนหลังนับจากปีปัจจุบัน
|
* @summary ผลการประเมิน 5 ปีย้อนหลังนับจากปีปัจจุบัน
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("calculate-Eva/{profileId}")
|
@Get("calculate-Eva/{node}/{nodeId}")
|
||||||
async calculateEva(
|
async calculateEva(
|
||||||
@Path() profileId: string,
|
@Path() node: string,
|
||||||
|
@Path() nodeId: string,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// const list = await this.viewProfileEvaluation.findOne({
|
const lists = await this.viewProfileEvaluationRepo.find({
|
||||||
// where: {
|
// where:{
|
||||||
// profileId: profileId,
|
// 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) => {
|
return new HttpSuccess(formattedResults);
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,16 @@ import { ViewColumn, ViewEntity } from "typeorm";
|
||||||
|
|
||||||
@ViewEntity({
|
@ViewEntity({
|
||||||
expression: `SELECT
|
expression: `SELECT
|
||||||
\`profileId\`, \`period\`, \`year\`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result
|
\`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\`
|
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
|
WHERE \`period\` Is not null
|
||||||
GROUP BY \`profileId\`, \`period\`, \`year\`
|
AND \`orgRevision\`.\`orgRevisionIsCurrent\` = true
|
||||||
ORDER BY \`year\` desc , \`period\` asc
|
GROUP BY\`profileId\`,\`period\`,\`year\`,\`orgRootId\`,\`orgChild1Id\`,\`orgChild2Id\`,\`orgChild3Id\`,\`orgChild4Id\`
|
||||||
`,
|
ORDER BY\`year\` desc ,\`period\` asc
|
||||||
|
`,
|
||||||
})
|
})
|
||||||
export class viewProfileEvaluation {
|
export class viewProfileEvaluation {
|
||||||
@ViewColumn()
|
@ViewColumn()
|
||||||
|
|
@ -17,6 +21,16 @@ export class viewProfileEvaluation {
|
||||||
@ViewColumn()
|
@ViewColumn()
|
||||||
year: number;
|
year: number;
|
||||||
@ViewColumn()
|
@ViewColumn()
|
||||||
|
orgRootId: string;
|
||||||
|
@ViewColumn()
|
||||||
|
orgChild1Id: string;
|
||||||
|
@ViewColumn()
|
||||||
|
orgChild2Id: string;
|
||||||
|
@ViewColumn()
|
||||||
|
orgChild3Id: string;
|
||||||
|
@ViewColumn()
|
||||||
|
orgChild4Id: string;
|
||||||
|
@ViewColumn()
|
||||||
recordCount: number;
|
recordCount: number;
|
||||||
@ViewColumn()
|
@ViewColumn()
|
||||||
totalPointSum: number;
|
totalPointSum: number;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue