filter รักษาการ

This commit is contained in:
mamoss 2025-07-18 16:33:09 +07:00
parent d9a92eda9d
commit 3ae17c23e2
3 changed files with 52 additions and 80 deletions

View file

@ -23,24 +23,13 @@ import { OrgChild2 } from "../entities/OrgChild2";
import { OrgChild3 } from "../entities/OrgChild3"; import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4"; import { OrgChild4 } from "../entities/OrgChild4";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { PermissionOrg } from "../entities/PermissionOrg"; import { setLogDataDiff } from "../interfaces/utils";
import { checkQueueInProgress, setLogDataDiff } from "../interfaces/utils";
import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq"; import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq";
import { PosMasterAssign } from "../entities/PosMasterAssign";
import { PosMasterAct } from "../entities/PosMasterAct";
import { EmployeePosition } from "../entities/EmployeePosition";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
import { AuthRole } from "../entities/AuthRole";
import { PosType } from "../entities/PosType"; import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
import { promisify } from "util";
const REDIS_HOST = process.env.REDIS_HOST;
const REDIS_PORT = process.env.REDIS_PORT;
@Route("api/v1/org") @Route("api/v1/org")
@Tags("Organization") @Tags("Organization")
@ -51,23 +40,15 @@ const REDIS_PORT = process.env.REDIS_PORT;
) )
export class OrganizationController extends Controller { export class OrganizationController extends Controller {
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private permissionOrgRepository = AppDataSource.getRepository(PermissionOrg);
private orgRootRepository = AppDataSource.getRepository(OrgRoot); private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child1Repository = AppDataSource.getRepository(OrgChild1); private child1Repository = AppDataSource.getRepository(OrgChild1);
private child2Repository = AppDataSource.getRepository(OrgChild2); private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3); private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4); private child4Repository = AppDataSource.getRepository(OrgChild4);
private posMasterRepository = AppDataSource.getRepository(PosMaster); private posMasterRepository = AppDataSource.getRepository(PosMaster);
private posMasterActRepository = AppDataSource.getRepository(PosMasterAct);
private posMasterAssignRepository = AppDataSource.getRepository(PosMasterAssign);
private positionRepository = AppDataSource.getRepository(Position);
private profileRepo = AppDataSource.getRepository(Profile); private profileRepo = AppDataSource.getRepository(Profile);
private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
private employeePositionRepository = AppDataSource.getRepository(EmployeePosition);
private employeeTempPosMasterRepository = AppDataSource.getRepository(EmployeeTempPosMaster);
private posTypeRepository = AppDataSource.getRepository(PosType); private posTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel); private posLevelRepository = AppDataSource.getRepository(PosLevel);
private redis = require("redis");
/** /**
* API * API
@ -187,7 +168,7 @@ export class OrganizationController extends Controller {
} }
return new HttpError( return new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"Failed to process the draft. Please try again later." "Failed to process the draft. Please try again later.",
); );
} }
} }
@ -3225,30 +3206,25 @@ export class OrganizationController extends Controller {
*/ */
@Get("get/publish") @Get("get/publish")
async runPublish(@Request() request: RequestWithUser) { async runPublish(@Request() request: RequestWithUser) {
try{ try {
// CheckQueueInProgress // CheckQueueInProgress
// console.log("🚀 ตรวจสอบว่ามีงานอยู่ในคิว"); // console.log("🚀 ตรวจสอบว่ามีงานอยู่ในคิว");
// const [isBusyDraft, isBusyPublish] = await Promise.all([ // const [isBusyDraft, isBusyPublish] = await Promise.all([
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`), // checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`), // checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
// ]); // ]);
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft); // console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish); // console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
// if (isBusyDraft || isBusyPublish) { // if (isBusyDraft || isBusyPublish) {
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error") // console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
// throw new HttpError( // throw new HttpError(
// HttpStatusCode.CONFLICT, // HttpStatusCode.CONFLICT,
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน", // "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
// ); // );
// } // }
const today = new Date(); const today = new Date();
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day today.setHours(0, 0, 0, 0); // Set time to the beginning of the day
const orgRevisionPublish = await this.orgRevisionRepository
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
const orgRevisionDraft = await this.orgRevisionRepository const orgRevisionDraft = await this.orgRevisionRepository
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")
@ -3287,7 +3263,7 @@ export class OrganizationController extends Controller {
} }
return new HttpError( return new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"Failed to process the publish. Please try again later." "Failed to process the publish. Please try again later.",
); );
} }
} }
@ -3301,12 +3277,6 @@ export class OrganizationController extends Controller {
const tomorrow = new Date(today); const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1); tomorrow.setDate(tomorrow.getDate() + 1);
const orgRevisionPublish = await this.orgRevisionRepository
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
const orgRevisionDraft = await this.orgRevisionRepository const orgRevisionDraft = await this.orgRevisionRepository
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = true") .where("orgRevision.orgRevisionIsDraft = true")
@ -7563,6 +7533,8 @@ export class OrganizationController extends Controller {
orgRoot: { isCommission: true }, orgRoot: { isCommission: true },
isDirector: true, isDirector: true,
current_holderId: Not(IsNull()), current_holderId: Not(IsNull()),
posMasterActs: { statusReport: "DONE" },
posMasterActChilds: { statusReport: "DONE" },
}, },
order: { posMasterOrder: "ASC", posMasterActChilds: { posMasterOrder: "ASC" } }, order: { posMasterOrder: "ASC", posMasterActChilds: { posMasterOrder: "ASC" } },
relations: [ relations: [

View file

@ -4554,7 +4554,7 @@ export class PositionController extends Controller {
) { ) {
await new permission().PermissionGet(request, "SYS_ACTING"); await new permission().PermissionGet(request, "SYS_ACTING");
const posMasterMain = await this.posMasterRepository.findOne({ const posMasterMain = await this.posMasterRepository.findOne({
where: { id: body.posmasterId }, where: { id: body.posmasterId, posMasterActs: { statusReport: "DONE" } },
relations: ["posMasterActs"], relations: ["posMasterActs"],
}); });
if (posMasterMain == null) { if (posMasterMain == null) {
@ -5050,19 +5050,21 @@ export class PositionController extends Controller {
: `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'` : `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'`
: "1=1", : "1=1",
) )
.andWhere(checkChildConditions) .andWhere(checkChildConditions)
.andWhere(typeCondition) .andWhere(typeCondition)
.andWhere(revisionCondition) .andWhere(revisionCondition)
.andWhere({ current_holderId: IsNull() }); .andWhere({ current_holderId: IsNull() });
}), }),
) )
.orWhere( .orWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.andWhere(`posMaster.conditionReason LIKE '%${body.keyword}%' AND posMaster.conditionReason IS NOT NULL`) qb.andWhere(
.andWhere(checkChildConditions) `posMaster.conditionReason LIKE '%${body.keyword}%' AND posMaster.conditionReason IS NOT NULL`,
.andWhere(typeCondition) )
.andWhere(revisionCondition) .andWhere(checkChildConditions)
.andWhere({ current_holderId: IsNull() }); .andWhere(typeCondition)
.andWhere(revisionCondition)
.andWhere({ current_holderId: IsNull() });
}), }),
) )
.orderBy("orgRoot.orgRootOrder", "ASC") .orderBy("orgRoot.orgRootOrder", "ASC")

View file

@ -1178,7 +1178,9 @@ export class ProfileController extends Controller {
salary: salary:
item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null,
special: special:
item.amountSpecial != null ? Extension.ToThaiNumber(item.amountSpecial.toLocaleString()) : null, item.amountSpecial != null
? Extension.ToThaiNumber(item.amountSpecial.toLocaleString())
: null,
rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
refAll: item.remark ? Extension.ToThaiNumber(item.remark) : null, refAll: item.remark ? Extension.ToThaiNumber(item.remark) : null,
positionLevel: item.positionLevel positionLevel: item.positionLevel
@ -7667,7 +7669,7 @@ export class ProfileController extends Controller {
"current_holders.orgChild4", "current_holders.orgChild4",
"profileSalary", "profileSalary",
"profileEducations", "profileEducations",
"profileActpositions" "profileActpositions",
], ],
order: { order: {
// profileSalary: { // profileSalary: {
@ -7677,8 +7679,8 @@ export class ProfileController extends Controller {
level: "ASC", level: "ASC",
}, },
profileActpositions: { profileActpositions: {
createdAt: "ASC" createdAt: "ASC",
} },
}, },
}); });
if (!profile) { if (!profile) {
@ -7816,30 +7818,25 @@ export class ProfileController extends Controller {
// ); // );
const data = await Promise.all( const data = await Promise.all(
profile.profileActpositions profile.profileActpositions
.filter(x => x.status) .filter((x) => x.status)
.map(async (item) => { .map(async (item) => {
const commandRef = await this.commandReciveRepository.findOne({ const commandRef = await this.commandReciveRepository.findOne({
where: { commandId: item.commandId } where: { commandId: item.commandId },
}); });
const posMasterActs = await this.posMasterActRepository.findOne({ const posMasterActs = await this.posMasterActRepository.findOne({
where: { where: {
id: commandRef?.refId, id: commandRef?.refId,
posMaster: { posMaster: {
orgRevisionId: orgRevisionPublish.id, orgRevisionId: orgRevisionPublish.id,
} },
statusReport: "DONE",
}, },
relations: [ relations: ["posMaster", "posMaster.current_holder"],
"posMaster",
"posMaster.current_holder"
],
}); });
const _profileAct = await this.profileRepo.findOne({ const _profileAct = await this.profileRepo.findOne({
where: { id: posMasterActs?.posMaster.current_holderId ?? "" }, where: { id: posMasterActs?.posMaster.current_holderId ?? "" },
relations: [ relations: ["posLevel", "posType"],
"posLevel", });
"posType"
]
})
return { return {
id: item.id, id: item.id,
posMasterOrder: posMasterActs?.posMasterOrder, posMasterOrder: posMasterActs?.posMasterOrder,
@ -7852,8 +7849,8 @@ export class ProfileController extends Controller {
posType: _profileAct?.posType.posTypeName ?? null, posType: _profileAct?.posType.posTypeName ?? null,
position: item.position ?? null, position: item.position ?? null,
posNo: item.posNo ?? null, posNo: item.posNo ?? null,
} };
}) }),
); );
const permissionProflile = await this.permissionProflileRepository.findOne({ const permissionProflile = await this.permissionProflileRepository.findOne({
relations: ["orgRootTree"], relations: ["orgRootTree"],
@ -8122,7 +8119,8 @@ export class ProfileController extends Controller {
? `${profile.profileEducations[0].degree ?? ""} ${profile.profileEducations[0].field ?? ""}` ? `${profile.profileEducations[0].degree ?? ""} ${profile.profileEducations[0].field ?? ""}`
: "", : "",
dateAppoint: profile.dateAppoint, dateAppoint: profile.dateAppoint,
avatarUrl: profile.avatar && profile.avatarName ? `${profile.avatar}/${profile.avatarName}` : null avatarUrl:
profile.avatar && profile.avatarName ? `${profile.avatar}/${profile.avatarName}` : null,
}; };
if (_profile.child4Id != null) { if (_profile.child4Id != null) {