Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m4s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m4s
* develop: update search org old
This commit is contained in:
commit
c1a12eff60
1 changed files with 455 additions and 226 deletions
|
|
@ -18,7 +18,7 @@ import HttpStatus from "../interfaces/http-status";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import { Profile } from "../entities/Profile";
|
import { Profile } from "../entities/Profile";
|
||||||
import { And, Between, Brackets, In, IsNull, Not } from "typeorm";
|
import { And, Between, Brackets, In, IsNull, LessThanOrEqual, Not } from "typeorm";
|
||||||
import { OrgRevision } from "../entities/OrgRevision";
|
import { OrgRevision } from "../entities/OrgRevision";
|
||||||
import { OrgRoot } from "../entities/OrgRoot";
|
import { OrgRoot } from "../entities/OrgRoot";
|
||||||
import { OrgChild1 } from "../entities/OrgChild1";
|
import { OrgChild1 } from "../entities/OrgChild1";
|
||||||
|
|
@ -34,6 +34,7 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||||
import { EmployeePosDict } from "../entities/EmployeePosDict";
|
import { EmployeePosDict } from "../entities/EmployeePosDict";
|
||||||
import { calculateRetireLaw } from "../interfaces/utils";
|
import { calculateRetireLaw } from "../interfaces/utils";
|
||||||
import Extension from "../interfaces/extension";
|
import Extension from "../interfaces/extension";
|
||||||
|
import { PosMasterHistory } from "../entities/PosMasterHistory";
|
||||||
@Route("api/v1/org/dotnet")
|
@Route("api/v1/org/dotnet")
|
||||||
@Tags("Dotnet")
|
@Tags("Dotnet")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -53,6 +54,7 @@ export class OrganizationDotnetController extends Controller {
|
||||||
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
|
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
private positionRepository = AppDataSource.getRepository(Position);
|
private positionRepository = AppDataSource.getRepository(Position);
|
||||||
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||||
|
private posMasterHistoryRepository = AppDataSource.getRepository(PosMasterHistory);
|
||||||
private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
|
private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
|
||||||
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
|
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
|
||||||
private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict);
|
private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict);
|
||||||
|
|
@ -70,7 +72,7 @@ export class OrganizationDotnetController extends Controller {
|
||||||
citizenId: string;
|
citizenId: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
let citizen = Extension.CheckCitizen(body.citizenId)
|
let citizen = Extension.CheckCitizen(body.citizenId);
|
||||||
return new HttpSuccess(citizen);
|
return new HttpSuccess(citizen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2658,14 +2660,16 @@ export class OrganizationDotnetController extends Controller {
|
||||||
posLevel: profile.posLevel?.posLevelName ?? "",
|
posLevel: profile.posLevel?.posLevelName ?? "",
|
||||||
posType: profile.posType?.posTypeName ?? "",
|
posType: profile.posType?.posTypeName ?? "",
|
||||||
// profileSalary: profile.profileSalary,
|
// profileSalary: profile.profileSalary,
|
||||||
profileSalary: profile.profileSalary?.map((x) => ({
|
profileSalary:
|
||||||
|
profile.profileSalary?.map((x) => ({
|
||||||
...x,
|
...x,
|
||||||
date: x.commandDateAffect ?? new Date()
|
date: x.commandDateAffect ?? new Date(),
|
||||||
})) ?? [],
|
})) ?? [],
|
||||||
// profileInsignia: profile.profileInsignias.map((x) => {
|
// profileInsignia: profile.profileInsignias.map((x) => {
|
||||||
// return { ...x, insignia: x.insignia.name };
|
// return { ...x, insignia: x.insignia.name };
|
||||||
// }),
|
// }),
|
||||||
profileInsignia: profile.profileInsignias?.map((x) => ({
|
profileInsignia:
|
||||||
|
profile.profileInsignias?.map((x) => ({
|
||||||
...x,
|
...x,
|
||||||
insigniaId: x.insignia?.id ?? null,
|
insigniaId: x.insignia?.id ?? null,
|
||||||
insignia: x.insignia?.name ?? null,
|
insignia: x.insignia?.name ?? null,
|
||||||
|
|
@ -2970,7 +2974,8 @@ export class OrganizationDotnetController extends Controller {
|
||||||
// profileInsignia: profile.profileInsignias.map((x) => {
|
// profileInsignia: profile.profileInsignias.map((x) => {
|
||||||
// return { ...x, insignia: x.insignia.name };
|
// return { ...x, insignia: x.insignia.name };
|
||||||
// }),
|
// }),
|
||||||
profileInsignia: profile.profileInsignias?.map((x) => ({
|
profileInsignia:
|
||||||
|
profile.profileInsignias?.map((x) => ({
|
||||||
...x,
|
...x,
|
||||||
insigniaId: x.insignia?.id ?? null,
|
insigniaId: x.insignia?.id ?? null,
|
||||||
insignia: x.insignia?.name ?? null,
|
insignia: x.insignia?.name ?? null,
|
||||||
|
|
@ -3189,14 +3194,16 @@ export class OrganizationDotnetController extends Controller {
|
||||||
// profileSalary: profile.profileSalary.map((x) => {
|
// profileSalary: profile.profileSalary.map((x) => {
|
||||||
// return { ...x, date: x.commandDateAffect ?? new Date() };
|
// return { ...x, date: x.commandDateAffect ?? new Date() };
|
||||||
// }),
|
// }),
|
||||||
profileSalary: profile.profileSalary?.map((x) => ({
|
profileSalary:
|
||||||
|
profile.profileSalary?.map((x) => ({
|
||||||
...x,
|
...x,
|
||||||
date: x.commandDateAffect ?? new Date()
|
date: x.commandDateAffect ?? new Date(),
|
||||||
})) ?? [],
|
})) ?? [],
|
||||||
// profileInsignia: profile.profileInsignias.map((x) => {
|
// profileInsignia: profile.profileInsignias.map((x) => {
|
||||||
// return { ...x, insignia: x.insignia.name };
|
// return { ...x, insignia: x.insignia.name };
|
||||||
// }),
|
// }),
|
||||||
profileInsignia: profile.profileInsignias?.map((x) => ({
|
profileInsignia:
|
||||||
|
profile.profileInsignias?.map((x) => ({
|
||||||
...x,
|
...x,
|
||||||
insigniaId: x.insignia?.id ?? null,
|
insigniaId: x.insignia?.id ?? null,
|
||||||
insignia: x.insignia?.name ?? null,
|
insignia: x.insignia?.name ?? null,
|
||||||
|
|
@ -5988,4 +5995,226 @@ export class OrganizationDotnetController extends Controller {
|
||||||
});
|
});
|
||||||
return new HttpSuccess(mapProfile);
|
return new HttpSuccess(mapProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* รายชื่อขรก. ตามสิทธิ์ admin
|
||||||
|
*
|
||||||
|
* @summary รายชื่อขรก. ตามสิทธิ์ admin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post("officer-by-admin-rolev2")
|
||||||
|
async GetOfficersByAdminRoleV2(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body()
|
||||||
|
body: {
|
||||||
|
node: number;
|
||||||
|
nodeId: string;
|
||||||
|
role: string;
|
||||||
|
isRetirement?: boolean;
|
||||||
|
reqNode?: number;
|
||||||
|
reqNodeId?: string;
|
||||||
|
date?: Date;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
let typeCondition: any = {};
|
||||||
|
if (body.role === "CHILD" || body.role === "PARENT" || body.role === "BROTHER") {
|
||||||
|
if (body.role === "CHILD") {
|
||||||
|
switch (body.node) {
|
||||||
|
case 0:
|
||||||
|
typeCondition = {
|
||||||
|
rootDnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
typeCondition = {
|
||||||
|
child1DnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
typeCondition = {
|
||||||
|
child2DnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
typeCondition = {
|
||||||
|
child3DnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
typeCondition = {
|
||||||
|
child4DnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
typeCondition = {};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (body.role === "BROTHER") {
|
||||||
|
switch (body.node) {
|
||||||
|
case 0:
|
||||||
|
typeCondition = {
|
||||||
|
rootDnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
typeCondition = {
|
||||||
|
rootDnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
typeCondition = {
|
||||||
|
child1DnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
typeCondition = {
|
||||||
|
child2DnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
typeCondition = {
|
||||||
|
child3DnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
typeCondition = {};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (body.role === "PARENT") {
|
||||||
|
typeCondition = {
|
||||||
|
rootDnaId: body.nodeId,
|
||||||
|
child1DnaId: Not(IsNull()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else if (body.role === "OWNER" || body.role === "ROOT") {
|
||||||
|
switch (body.reqNode) {
|
||||||
|
case 0:
|
||||||
|
typeCondition = {
|
||||||
|
rootDnaId: body.reqNodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
typeCondition = {
|
||||||
|
child1DnaId: body.reqNodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
typeCondition = {
|
||||||
|
child2DnaId: body.reqNodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
typeCondition = {
|
||||||
|
child3DnaId: body.reqNodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
typeCondition = {
|
||||||
|
child4DnaId: body.reqNodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
typeCondition = {};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (body.role === "NORMAL") {
|
||||||
|
switch (body.node) {
|
||||||
|
case 0:
|
||||||
|
typeCondition = {
|
||||||
|
rootDnaId: body.nodeId,
|
||||||
|
child1DnaId: IsNull(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
typeCondition = {
|
||||||
|
child1DnaId: body.nodeId,
|
||||||
|
child2DnaId: IsNull(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
typeCondition = {
|
||||||
|
child2DnaId: body.nodeId,
|
||||||
|
child3DnaId: IsNull(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
typeCondition = {
|
||||||
|
child3DnaId: body.nodeId,
|
||||||
|
child4DnaId: IsNull(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
typeCondition = {
|
||||||
|
child4DnaId: body.nodeId,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
typeCondition = {};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const date = body.date ? new Date(body.date) : new Date();
|
||||||
|
// set เวลาเป็น 23:59:59 ของวันนั้น
|
||||||
|
date.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
|
let profile = await this.posMasterHistoryRepository.find({
|
||||||
|
where: {
|
||||||
|
...typeCondition,
|
||||||
|
createdAt: LessThanOrEqual(date),
|
||||||
|
firstName: Not("") && Not(IsNull()),
|
||||||
|
lastName: Not("") && Not(IsNull()),
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
firstName: "ASC",
|
||||||
|
lastName: "ASC",
|
||||||
|
createdAt: "DESC", // ให้ createdAt ล่าสุดอยู่ข้างบน
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// group by firstName + lastName แล้วเลือก create_at ล่าสุด
|
||||||
|
const grouped = new Map<string, PosMasterHistory>();
|
||||||
|
for (const item of profile) {
|
||||||
|
const key = `${item.firstName}-${item.lastName}`;
|
||||||
|
if (!grouped.has(key)) {
|
||||||
|
grouped.set(key, item);
|
||||||
|
} else {
|
||||||
|
// ถ้าเจอซ้ำ ให้เลือก createdAt ล่าสุด
|
||||||
|
const exist = grouped.get(key);
|
||||||
|
if (exist && item.createdAt > exist.createdAt) {
|
||||||
|
grouped.set(key, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const profile_ = await Promise.all(
|
||||||
|
Array.from(grouped.values()).map(async (item: PosMasterHistory) => {
|
||||||
|
let profile = await this.profileRepo.findOne({
|
||||||
|
where: { id: item.profileId },
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: item.id,
|
||||||
|
prefix: item.prefix,
|
||||||
|
firstName: item.firstName,
|
||||||
|
lastName: item.lastName,
|
||||||
|
citizenId: profile?.citizenId ?? null,
|
||||||
|
dateStart: profile?.dateStart ?? null,
|
||||||
|
dateAppoint: profile?.dateAppoint ?? null,
|
||||||
|
keycloak: profile?.keycloak ?? null,
|
||||||
|
posNo: item.shortName,
|
||||||
|
position: item.position,
|
||||||
|
positionLevel: item.posLevel,
|
||||||
|
positionType: item.posType,
|
||||||
|
// oc: Oc,
|
||||||
|
orgRootId: item.rootDnaId,
|
||||||
|
orgChild1Id: item.child1DnaId,
|
||||||
|
orgChild2Id: item.child2DnaId,
|
||||||
|
orgChild3Id: item.child3DnaId,
|
||||||
|
orgChild4Id: item.child4DnaId,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return new HttpSuccess(profile_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue