This commit is contained in:
AdisakKanthawilang 2025-02-17 14:46:25 +07:00
parent 188a028bec
commit a05e6178fa
2 changed files with 43 additions and 44 deletions

View file

@ -122,7 +122,7 @@ export class ImportDataController extends Controller {
// } // }
const existingProfile = await this.profileRepo.findOne({ const existingProfile = await this.profileRepo.findOne({
where: { citizenId: item.ID }, where: { citizenId: item.id.toString() },
}); });
if (existingProfile) { if (existingProfile) {
profile.id = existingProfile.id; profile.id = existingProfile.id;
@ -152,7 +152,7 @@ export class ImportDataController extends Controller {
} }
let dateRetire = new Date(item.BORN); let dateRetire = new Date(item.BORN);
profile.citizenId = item.ID == "" ? "" : item.ID; profile.citizenId = item.id.toString() == "" ? "" : item.id.toString();
profile.rank = profile.rank =
item.RANK_NAME == "" || item.RANK_NAME == "" ||
item.RANK_NAME == "นาย" || item.RANK_NAME == "นาย" ||
@ -1817,7 +1817,7 @@ export class ImportDataController extends Controller {
rowCount++; rowCount++;
const existingProfile = await this.profileRepo.findOne({ const existingProfile = await this.profileRepo.findOne({
where: { citizenId: item.ID }, where: { citizenId: item.id.toString() },
}); });
if (existingProfile == null) { if (existingProfile == null) {
continue; continue;

View file

@ -16,6 +16,7 @@ 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"; import { viewProfileEvaluation } from "../entities/view/viewProfileEvaluation";
import { viewProfileEmployeeEvaluation } from "../entities/view/viewProfileEmployeeEvaluation";
@Route("api/v1/org/unauthorize") @Route("api/v1/org/unauthorize")
@Tags("OrganizationUnauthorize") @Tags("OrganizationUnauthorize")
@ -30,6 +31,7 @@ export class OrganizationUnauthorizeController extends Controller {
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); private viewProfileEvaluationRepo = AppDataSource.getRepository(viewProfileEvaluation);
private viewProfileEmployeeEvaluationRepo = AppDataSource.getRepository(viewProfileEmployeeEvaluation);
/** /**
* API (unauthorize) * API (unauthorize)
@ -1200,24 +1202,23 @@ export class OrganizationUnauthorizeController extends Controller {
// default: // default:
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// } // }
let lists = null;
const lists = await this.viewProfileEvaluationRepo.find({ lists = await this.viewProfileEvaluationRepo.find({
// where:{ // where:{
// ...condition // ...condition
// } // }
}) })
// if(conType == "EMPLOYEE"){ if(conType == "EMPLOYEE"){
// const lists = await this.viewProfileEmployeeEvaluationRepo.find({ lists = await this.viewProfileEmployeeEvaluationRepo.find({})
// }) }
// }
const groupData: any = {}; const groupData: any = {};
const year = new Date().getFullYear(); const year = new Date().getFullYear();
const years = [year, year - 1, year - 2, year - 3, year - 4]; const years = [year, year - 1, year - 2, year - 3, year - 4];
lists.forEach((item: any) => { lists.forEach((item: any) => {
if (!groupData[item.profileId]) { if (!groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId]) {
groupData[item.profileId] = { groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId] = {
profileId: item.profileId, profileId: conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId,
yearAPR1: "-", periodAPR1: "-", resultAPR1: "-", yearAPR1: "-", periodAPR1: "-", resultAPR1: "-",
yearOCT1: "-", periodOCT1: "-", resultOCT1: "-", yearOCT1: "-", periodOCT1: "-", resultOCT1: "-",
yearAPR2: "-", periodAPR2: "-", resultAPR2: "-", yearAPR2: "-", periodAPR2: "-", resultAPR2: "-",
@ -1230,7 +1231,6 @@ export class OrganizationUnauthorizeController extends Controller {
yearOCT5: "-", periodOCT5: "-", resultOCT5: "-" yearOCT5: "-", periodOCT5: "-", resultOCT5: "-"
}; };
} }
const yearIndex = years.indexOf(parseInt(item.year)); const yearIndex = years.indexOf(parseInt(item.year));
if (yearIndex !== -1) { if (yearIndex !== -1) {
const yearSuffix = yearIndex + 1; const yearSuffix = yearIndex + 1;
@ -1238,40 +1238,39 @@ export class OrganizationUnauthorizeController extends Controller {
const periodKey = `period${item.period}${yearSuffix}`; const periodKey = `period${item.period}${yearSuffix}`;
const resultKey = `result${item.period}${yearSuffix}`; const resultKey = `result${item.period}${yearSuffix}`;
groupData[item.profileId][yearKey] = item.year; groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId][yearKey] = item.year;
groupData[item.profileId][periodKey] = item.period; groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId][periodKey] = item.period;
groupData[item.profileId][resultKey] = item.result; groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId][resultKey] = item.result;
} }
}); });
const formattedResults = Object.values(groupData).map((x: any) => ({
const formattedResults = Object.values(groupData).map((item: any) => ({ profileId: x.profileId,
profileId: item.profileId, yearAPR1: x.yearAPR1,
yearAPR1: item.yearAPR1, periodAPR1: x.periodAPR1,
periodAPR1: item.periodAPR1, resultAPR1: x.resultAPR1,
resultAPR1: item.resultAPR1, yearOCT1: x.yearOCT1,
yearOCT1: item.yearOCT1, periodOCT1: x.periodOCT1,
periodOCT1: item.periodOCT1, resultOCT1: x.resultOCT1,
resultOCT1: item.resultOCT1, yearAPR2: x.yearAPR2,
yearAPR2: item.yearAPR2, periodAPR2: x.periodAPR2,
periodAPR2: item.periodAPR2, resultAPR2: x.resultAPR2,
resultAPR2: item.resultAPR2, yearOCT2: x.yearOCT2,
yearOCT2: item.yearOCT2, periodOCT2: x.periodOCT2,
periodOCT2: item.periodOCT2, resultOCT2: x.resultOCT2,
resultOCT2: item.resultOCT2, yearAPR3: x.yearAPR3,
yearAPR3: item.yearAPR3, periodAPR3: x.periodAPR3,
periodAPR3: item.periodAPR3, resultAPR3: x.resultAPR3,
resultAPR3: item.resultAPR3, yearOCT3: x.yearOCT3,
yearOCT3: item.yearOCT3, periodOCT3: x.periodOCT3,
periodOCT3: item.periodOCT3, resultOCT3: x.resultOCT3,
resultOCT3: item.resultOCT3, yearAPR4: x.yearAPR4,
yearAPR4: item.yearAPR4, periodAPR4: x.periodAPR4,
periodAPR4: item.periodAPR4, resultAPR4: x.resultAPR4,
resultAPR4: item.resultAPR4, yearOCT4: x.yearOCT4,
yearOCT4: item.yearOCT4, periodOCT4: x.periodOCT4,
periodOCT4: item.periodOCT4, resultOCT4: x.resultOCT4,
resultOCT4: item.resultOCT4,
})); }));
return new HttpSuccess(formattedResults); return new HttpSuccess(formattedResults);
} }