cdhแก้คิวรี่ให้เร็วขึ้น สร้าง workflow

This commit is contained in:
mamoss 2025-10-09 23:24:04 +07:00
parent fd17f366b8
commit 847d9c302f
2 changed files with 241 additions and 265 deletions

View file

@ -73,29 +73,10 @@ export class OrganizationDotnetController extends Controller {
role?: string | null;
nodeId?: string | null;
node?: number | null;
page: number;
pageSize: number;
},
) {
// const profileRepository = AppDataSource.getRepository(Profile);
// const queryBuilder = profileRepository
// .createQueryBuilder("profile")
// .leftJoinAndSelect("profile.posLevel", "posLevel")
// .leftJoinAndSelect("profile.posType", "posType")
// if (body.citizenId || body.firstName || body.lastName) {
// queryBuilder.where(
// new Brackets((qb) => {
// if (body.citizenId) {
// qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` });
// }
// if (body.firstName) {
// qb.orWhere("profile.firstName LIKE :firstName", { firstName: `%${body.firstName}%` });
// }
// if (body.lastName) {
// qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` });
// }
// }),
// );
// }
// const profiles = await queryBuilder.getMany();
let condition = "1=1";
let conditionParams = {};
if (body.role === "CHILD") {
@ -156,7 +137,7 @@ export class OrganizationDotnetController extends Controller {
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const profiles = await this.profileRepo
const [profiles, total] = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
@ -170,20 +151,22 @@ export class OrganizationDotnetController extends Controller {
.andWhere(
new Brackets((qb) => {
if (body.citizenId) {
qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` });
qb.andWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` });
}
if (body.firstName) {
qb.orWhere("profile.firstName LIKE :firstName", { firstName: `%${body.firstName}%` });
qb.andWhere("profile.firstName LIKE :firstName", { firstName: `%${body.firstName}%` });
}
if (body.lastName) {
qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` });
qb.andWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` });
}
}),
)
.andWhere(condition, conditionParams)
.getMany();
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
return new HttpSuccess(profiles);
return new HttpSuccess({ data: profiles, total: total });
}
/**
@ -202,40 +185,10 @@ export class OrganizationDotnetController extends Controller {
role?: string | null;
nodeId?: string | null;
node?: number | null;
page: number;
pageSize: number;
},
) {
// const profileRepository = AppDataSource.getRepository(ProfileEmployee);
// const queryBuilder = profileRepository
// .createQueryBuilder("profile")
// .leftJoinAndSelect("profile.posLevel", "posLevel")
// .leftJoinAndSelect("profile.posType", "posType")
// .leftJoinAndSelect("profile.profileSalary", "profileSalary")
// .leftJoinAndSelect("profile.current_holders", "current_holders")
// .leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
// .leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
// .leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
// .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
// .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
// .orderBy("profileSalary.order", "DESC");
// if (body.citizenId || body.firstName || body.lastName) {
// queryBuilder.where(
// new Brackets((qb) => {
// if (body.citizenId) {
// qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` });
// }
// if (body.firstName) {
// qb.orWhere("profile.firstName LIKE :firstName", { firstName: `%${body.firstName}%` });
// }
// if (body.lastName) {
// qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` });
// }
// }),
// );
// }
// const profileEmp = await queryBuilder.getMany();
let condition = "1=1";
let conditionParams = {};
if (body.role === "CHILD") {
@ -296,7 +249,7 @@ export class OrganizationDotnetController extends Controller {
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const profileEmp = await this.profileEmpRepo
const [profileEmp, total] = await this.profileEmpRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
@ -311,110 +264,112 @@ export class OrganizationDotnetController extends Controller {
.andWhere(
new Brackets((qb) => {
if (body.citizenId) {
qb.orWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` });
qb.andWhere("profile.citizenId LIKE :citizenId", { citizenId: `%${body.citizenId}%` });
}
if (body.firstName) {
qb.orWhere("profile.firstName LIKE :firstName", { firstName: `%${body.firstName}%` });
qb.andWhere("profile.firstName LIKE :firstName", { firstName: `%${body.firstName}%` });
}
if (body.lastName) {
qb.orWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` });
qb.andWhere("profile.lastName LIKE :lastName", { lastName: `%${body.lastName}%` });
}
}),
)
.andWhere(condition, conditionParams)
.orderBy("profileSalary.order", "DESC")
.getMany();
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
const profileEmp_ = await Promise.all(
profileEmp.map((item: ProfileEmployee) => {
const rootName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot
?.orgRootName;
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild3 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: null;
return {
oc: rootName,
id: item.id,
createdAt: item.createdAt,
createdUserId: item.createdUserId,
lastUpdatedAt: item.lastUpdatedAt,
lastUpdateUserId: item.lastUpdateUserId,
createdFullName: item.createdFullName,
lastUpdateFullName: item.lastUpdateFullName,
avatar: item.avatar,
avatarName: item.avatarName,
rank: item.rank,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
citizenId: item.citizenId,
position: item.position,
posLevelId: item.posLevelId,
posTypeId: item.posTypeId,
email: item.email,
phone: item.phone,
keycloak: item.keycloak,
isProbation: item.isProbation,
isLeave: item.isLeave,
leaveReason: item.leaveReason,
dateLeave: item.dateLeave,
dateRetire: item.dateRetire,
dateAppoint: item.dateAppoint,
dateRetireLaw: item.dateRetireLaw,
dateStart: item.dateStart,
govAgeAbsent: item.govAgeAbsent,
govAgePlus: item.govAgePlus,
birthDate: item.birthDate ?? new Date(),
reasonSameDate: item.reasonSameDate,
ethnicity: item.ethnicity,
telephoneNumber: item.phone,
nationality: item.nationality,
gender: item.gender,
relationship: item.relationship,
religion: item.religion,
bloodGroup: item.bloodGroup,
registrationAddress: item.registrationAddress,
registrationProvinceId: item.registrationProvinceId,
registrationDistrictId: item.registrationDistrictId,
registrationSubDistrictId: item.registrationSubDistrictId,
registrationZipCode: item.registrationZipCode,
currentAddress: item.currentAddress,
currentProvinceId: item.currentProvinceId,
currentDistrictId: item.currentDistrictId,
currentSubDistrictId: item.currentSubDistrictId,
currentZipCode: item.currentZipCode,
posLevel: item.posLevel,
posType: item.posType,
posNo: shortName,
};
}),
);
return new HttpSuccess(profileEmp_);
// const profileEmp_ = await Promise.all(
// profileEmp.map((item: ProfileEmployee) => {
// const rootName =
// item.current_holders.length == 0
// ? null
// : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot
// ?.orgRootName;
// const shortName =
// item.current_holders.length == 0
// ? null
// : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
// item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
// null
// ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
// : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
// item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
// ?.orgChild3 != null
// ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
// : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
// item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
// ?.orgChild2 != null
// ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
// : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
// item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
// ?.orgChild1 != null
// ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
// : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
// null &&
// item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
// ?.orgRoot != null
// ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
// : null;
// return {
// oc: rootName,
// id: item.id,
// createdAt: item.createdAt,
// createdUserId: item.createdUserId,
// lastUpdatedAt: item.lastUpdatedAt,
// lastUpdateUserId: item.lastUpdateUserId,
// createdFullName: item.createdFullName,
// lastUpdateFullName: item.lastUpdateFullName,
// avatar: item.avatar,
// avatarName: item.avatarName,
// rank: item.rank,
// prefix: item.prefix,
// firstName: item.firstName,
// lastName: item.lastName,
// citizenId: item.citizenId,
// position: item.position,
// posLevelId: item.posLevelId,
// posTypeId: item.posTypeId,
// email: item.email,
// phone: item.phone,
// keycloak: item.keycloak,
// isProbation: item.isProbation,
// isLeave: item.isLeave,
// leaveReason: item.leaveReason,
// dateLeave: item.dateLeave,
// dateRetire: item.dateRetire,
// dateAppoint: item.dateAppoint,
// dateRetireLaw: item.dateRetireLaw,
// dateStart: item.dateStart,
// govAgeAbsent: item.govAgeAbsent,
// govAgePlus: item.govAgePlus,
// birthDate: item.birthDate ?? new Date(),
// reasonSameDate: item.reasonSameDate,
// ethnicity: item.ethnicity,
// telephoneNumber: item.phone,
// nationality: item.nationality,
// gender: item.gender,
// relationship: item.relationship,
// religion: item.religion,
// bloodGroup: item.bloodGroup,
// registrationAddress: item.registrationAddress,
// registrationProvinceId: item.registrationProvinceId,
// registrationDistrictId: item.registrationDistrictId,
// registrationSubDistrictId: item.registrationSubDistrictId,
// registrationZipCode: item.registrationZipCode,
// currentAddress: item.currentAddress,
// currentProvinceId: item.currentProvinceId,
// currentDistrictId: item.currentDistrictId,
// currentSubDistrictId: item.currentSubDistrictId,
// currentZipCode: item.currentZipCode,
// posLevel: item.posLevel,
// posType: item.posType,
// posNo: shortName,
// };
// }),
// );
return new HttpSuccess({ data: profileEmp, total: total });
}
/**