Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2025-06-04 15:01:23 +07:00
commit ebcd94a701
20 changed files with 134 additions and 42 deletions

View file

@ -78,6 +78,7 @@ async function main() {
const profileSalaryController = new ProfileSalaryController();
await profileSalaryController.cronjobTenurePositionOfficer();
await profileSalaryController.cronjobTenureLevelOfficer();
await profileSalaryController.cronjobTenureExecutivePositionOfficer();
await profileSalaryController.cronjobTenurePositionEmployee();
await profileSalaryController.cronjobTenureLevelEmployee();
} catch (error) {

View file

@ -2213,7 +2213,6 @@ export class CommandController extends Controller {
commandRecive.remarkVertical = item.remarkVertical == null ? _null : item.remarkVertical;
commandRecive.remarkHorizontal =
item.remarkHorizontal == null ? _null : item.remarkHorizontal;
commandRecive.order = order;
commandRecive.commandId = command.id;
commandRecive.createdUserId = request.user.sub;
commandRecive.createdFullName = request.user.name;
@ -2659,7 +2658,7 @@ export class CommandController extends Controller {
);
}
}
if (["C-PM-10"].includes(commandCode)) {
if (["C-PM-10", "C-PM-40"].includes(commandCode)) {
await Promise.all(
requestBody.persons.map(async (item: any) => {
const _posMasterDirector = await this.posMasterRepository.findOne({
@ -6358,8 +6357,8 @@ export class CommandController extends Controller {
? Extension.ToThaiShortDate(item.CommandExcecuteDate)
: "-",
dateEnd: "-",
RemarkVertical: item.RemarkVertical,
RemarkHorizontal: item.RemarkHorizontal,
RemarkVertical: item.RemarkVertical ? Extension.ToThaiNumber(item.RemarkVertical) : "-",
RemarkHorizontal: item.RemarkHorizontal ? Extension.ToThaiNumber(item.RemarkHorizontal) : "-",
order:
posMasterAct.posMasterOrder == null
? "-"

View file

@ -408,13 +408,13 @@ export class PosMasterActController extends Controller {
let conditionGroup = "";
if (body.type.trim().toUpperCase() == "GROUP1.1") {
conditionGroup =
"(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ชำนาญงาน') OR (posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ปฏิบัติงาน') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ปฏิบัติการ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ชำนาญการ')";
"(posTypeAct.posTypeName = 'ทั่วไป' AND posLevelAct.posLevelName = 'ชำนาญงาน') OR (posTypeAct.posTypeName = 'ทั่วไป' AND posLevelAct.posLevelName = 'ปฏิบัติงาน') OR (posTypeAct.posTypeName = 'วิชาการ' AND posLevelAct.posLevelName = 'ปฏิบัติการ') OR (posTypeAct.posTypeName = 'วิชาการ' AND posLevelAct.posLevelName = 'ชำนาญการ')";
} else if (body.type.trim().toUpperCase() == "GROUP1.2") {
conditionGroup =
"(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'อาวุโส') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ชำนาญการพิเศษ') OR (posType.posTypeName = 'อำนวยการ' AND posLevel.posLevelName = 'ต้น')";
"(posTypeAct.posTypeName = 'ทั่วไป' AND posLevelAct.posLevelName = 'อาวุโส') OR (posTypeAct.posTypeName = 'วิชาการ' AND posLevelAct.posLevelName = 'ชำนาญการพิเศษ') OR (posTypeAct.posTypeName = 'อำนวยการ' AND posLevelAct.posLevelName = 'ต้น')";
} else if (body.type.trim().toUpperCase() == "GROUP2") {
conditionGroup =
"(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ทักษะพิเศษ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'เชี่ยวชาญ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ทรงคุณวุฒิ') OR (posType.posTypeName = 'อำนวยการ' AND posLevel.posLevelName = 'สูง') OR (posType.posTypeName = 'บริหาร' AND posLevel.posLevelName = 'ต้น') OR (posType.posTypeName = 'บริหาร' AND posLevel.posLevelName = 'สูง')";
"(posTypeAct.posTypeName = 'ทั่วไป' AND posLevelAct.posLevelName = 'ทักษะพิเศษ') OR (posTypeAct.posTypeName = 'วิชาการ' AND posLevelAct.posLevelName = 'เชี่ยวชาญ') OR (posTypeAct.posTypeName = 'วิชาการ' AND posLevelAct.posLevelName = 'ทรงคุณวุฒิ') OR (posTypeAct.posTypeName = 'อำนวยการ' AND posLevelAct.posLevelName = 'สูง') OR (posTypeAct.posTypeName = 'บริหาร' AND posLevelAct.posLevelName = 'ต้น') OR (posTypeAct.posTypeName = 'บริหาร' AND posLevelAct.posLevelName = 'สูง')";
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "กลุ่มเป้าหมายไม่ถูกต้อง");
}
@ -431,6 +431,10 @@ export class PosMasterActController extends Controller {
.leftJoinAndSelect("posMasterChild.positions", "positions")
.leftJoinAndSelect("positions.posType", "posType")
.leftJoinAndSelect("positions.posLevel", "posLevel")
.leftJoinAndSelect("posMasterAct.posMaster", "posMaster")
.leftJoinAndSelect("posMaster.positions", "positionActs")
.leftJoinAndSelect("positionActs.posType", "posTypeAct")
.leftJoinAndSelect("positionActs.posLevel", "posLevelAct")
.leftJoinAndSelect("posMasterChild.orgRevision", "orgRevision")
.andWhere("posMasterChild.orgRootId LIKE :orgRootId", {
orgRootId: body.type.trim().toUpperCase() == "GROUP1.1" ? body.rootId : `%%`,
@ -444,12 +448,13 @@ export class PosMasterActController extends Controller {
orgRevisionIsDraft: false,
})
.andWhere("positions.positionIsSelected = :isSelected", { isSelected: true })
.andWhere("positionActs.positionIsSelected = :isSelected", { isSelected: true })
.andWhere(
new Brackets((qb) => {
qb.andWhere(conditionGroup);
}),
)
.orderBy("posMasterChild.posMasterOrder", "ASC")
.orderBy("posMasterAct.posMasterOrder", "ASC")
.select([
"posMasterAct.id",
"posMasterChild.posMasterNo",

View file

@ -27,8 +27,11 @@ import { TenurePositionOfficer } from "../entities/TenurePositionOfficer";
import { TenureLevelOfficer } from "../entities/TenureLevelOfficer";
import { TenurePositionEmployee } from "../entities/TenurePositionEmployee";
import { TenureLevelEmployee } from "../entities/TenureLevelEmployee";
import { TenurePositionExecutiveOfficer } from "../entities/TenurePositionExecutiveOfficer";
import { Command } from "../entities/Command";
import { OrgRoot } from "../entities/OrgRoot";
import { OrgRevision } from "../entities/OrgRevision";
import { Position } from "../entities/Position";
@Route("api/v1/org/profile/salary")
@Tags("ProfileSalary")
@Security("bearerAuth")
@ -41,8 +44,11 @@ export class ProfileSalaryController extends Controller {
private positionEmployeeRepo = AppDataSource.getRepository(TenurePositionEmployee);
private levelOfficerRepo = AppDataSource.getRepository(TenureLevelOfficer);
private levelEmployeeRepo = AppDataSource.getRepository(TenureLevelEmployee);
private positionExecutiveOfficerRepo = AppDataSource.getRepository(TenurePositionExecutiveOfficer);
private commandRepository = AppDataSource.getRepository(Command);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private positionRepo = AppDataSource.getRepository(Position);
@Get("TenurePositionOfficer")
public async cronjobTenurePositionOfficer() {
@ -229,6 +235,64 @@ export class ProfileSalaryController extends Controller {
return new HttpSuccess();
}
@Get("TenurePositionExecutiveOfficer")
public async cronjobTenureExecutivePositionOfficer() {
await this.positionExecutiveOfficerRepo.clear();
const profile = await this.profileRepo.find();
const orgRevision = await this.orgRevisionRepository.findOne({
select: ["id"],
where: {
orgRevisionIsDraft: false,
orgRevisionIsCurrent: true,
},
});
for await (const x of profile) {
const position = await this.positionRepo.findOne({
where: {
positionIsSelected: true,
posMaster: {
orgRevisionId: orgRevision?.id,
current_holderId: x.id,
},
},
order: { createdAt: "DESC" },
relations: {
posExecutive: true,
},
});
const positionExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?)", [x.id]);
const _position = positionExecutive.length > 0 ? positionExecutive[0] : [];
const mapPosition =
_position.length > 1
? _position.slice(1).map((curr: any, index: number) => ({
days_diff: curr.days_diff,
positionExecutive: _position[index]?.positionExecutive,
}))
: [];
const _posExecutiveName = position?.posExecutive?.posExecutiveName;
const calDayDiff = mapPosition
.filter((curr: any) => _posExecutiveName && curr.positionExecutive == _posExecutiveName)
.reduce(
(acc: any, curr: any) => {
acc.days_diff += Number(curr.days_diff) || 0;
acc.positionExecutive = curr.positionExecutive;
return acc;
},
{ days_diff: 0, positionExecutive: null },
);
const mapData: any = {
profileId: x.id,
positionExecutiveName: calDayDiff.positionExecutive,
days_diff: calDayDiff.days_diff,
Years: (calDayDiff.days_diff / 365.2524).toFixed(4),
Months: ((calDayDiff.days_diff / 30.4375) % 12).toFixed(4),
Days: (calDayDiff.days_diff % 30.4375).toFixed(4),
};
await this.positionExecutiveOfficerRepo.save(mapData);
}
return new HttpSuccess();
}
@Get("user")
public async getSalaryUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });

View file

@ -151,7 +151,7 @@ export class ReportController extends Controller {
} else if (tenureType != "" && tenureType == "level") {
tenureTypeCondition = "registryOfficer.levelYears BETWEEN :tenureMin AND :tenureMax";
} else if (tenureType != "" && tenureType == "posExecutive") {
tenureTypeCondition = "registryOfficer.levelYears BETWEEN :tenureMin AND :tenureMax";
tenureTypeCondition = "registryOfficer.posExecutiveYears BETWEEN :tenureMin AND :tenureMax";
}
const [lists, total] = await AppDataSource.getRepository(viewRegistryOfficer)

View file

@ -21,6 +21,7 @@ import { PosMasterAct } from "../entities/PosMasterAct";
import { viewDirectorActing } from "../entities/view/viewDirectorActing";
import { viewDirector } from "../entities/view/viewDirector";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
@Route("api/v1/org/workflow")
@Tags("Workflow")
@ -38,6 +39,7 @@ export class WorkflowController extends Controller {
private metaStateRepo = AppDataSource.getRepository(MetaState);
private metaStateOperatorRepo = AppDataSource.getRepository(MetaStateOperator);
private posMasterRepo = AppDataSource.getRepository(PosMaster);
private posMasterEmpRepo = AppDataSource.getRepository(EmployeePosMaster);
private posMasterActRepo = AppDataSource.getRepository(PosMasterAct);
private assignRepo = AppDataSource.getRepository(Assign);
@ -806,29 +808,51 @@ export class WorkflowController extends Controller {
page: number;
pageSize: number;
keycloakId?: string | null;
type?: string | null;
},
) {
let posMasterUser: PosMaster = new PosMaster();
let posMasterUser = null;
if (body.keycloakId) {
posMasterUser = (await this.posMasterRepo.findOne({
where: {
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
current_holder: { keycloak: body.keycloakId },
},
relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"],
})) as PosMaster;
if (body.type == "employee") {
posMasterUser = await this.posMasterEmpRepo.findOne({
where: {
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
current_holder: { keycloak: body.keycloakId },
},
relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"],
});
} else {
posMasterUser = await this.posMasterRepo.findOne({
where: {
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
current_holder: { keycloak: body.keycloakId },
},
relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"],
});
}
} else {
posMasterUser = (await this.posMasterRepo.findOne({
where: {
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
current_holder: { keycloak: request.user.sub },
},
relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"],
})) as PosMaster;
if (body.type == "employee") {
posMasterUser = await this.posMasterEmpRepo.findOne({
where: {
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
current_holder: { keycloak: request.user.sub },
},
relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"],
});
} else {
posMasterUser = await this.posMasterRepo.findOne({
where: {
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
current_holder: { keycloak: request.user.sub },
},
relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"],
});
}
}
if (!posMasterUser || !posMasterUser.orgRootId)
if (!posMasterUser || !posMasterUser.orgRootId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบตำแหน่งผู้ใช้งาน");
}
let condition: any = [];
@ -839,7 +863,7 @@ export class WorkflowController extends Controller {
orgChild1Id: IsNull(),
};
if (type.trim().toUpperCase() == "OPERATE") {
if (type.trim().toUpperCase() == "OPERATE" || body.type == "employee") {
condition.push({
isDirector: true,
orgRootId: posMasterUser.orgRootId,

View file

@ -69,7 +69,6 @@ export class ProfileCertificate extends EntityBase {
isUpload: boolean;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -71,7 +71,6 @@ export class ProfileChangeName extends EntityBase {
profileEmployeeId: string;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -67,7 +67,6 @@ export class ProfileChildren extends EntityBase {
profileEmployeeId: string;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -77,7 +77,6 @@ export class ProfileDiscipline extends EntityBase {
isUpload: boolean;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -77,7 +77,6 @@ export class ProfileDuty extends EntityBase {
isUpload: boolean;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -191,7 +191,6 @@ export class ProfileEducation extends EntityBase {
level: number;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -84,7 +84,6 @@ export class ProfileHonor extends EntityBase {
isUpload: boolean;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -132,7 +132,6 @@ export class ProfileInsignia extends EntityBase {
insigniaId: string;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -95,7 +95,6 @@ export class ProfileLeave extends EntityBase {
leaveId: string;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -69,7 +69,6 @@ export class ProfileNopaid extends EntityBase {
isUpload: boolean;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -39,7 +39,6 @@ export class ProfileOther extends EntityBase {
date: Date;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: false,
})

View file

@ -226,9 +226,8 @@ export class ProfileSalary extends EntityBase {
isGovernment: boolean;
@Column({
nullable: false,
comment: "ข้อมูลจาก Entry",
default: null,
default: false,
})
isEntry: boolean;

View file

@ -239,9 +239,8 @@ export class ProfileSalaryTemp extends EntityBase {
isGovernment: boolean;
@Column({
nullable: true,
comment: "ข้อมูลจาก Entry",
default: null,
default: false,
})
isEntry: boolean;

View file

@ -116,6 +116,14 @@ import { ViewColumn, ViewEntity } from "typeorm";
vctlo.Days,
vctlo.profileId
FROM tenureLevelOfficer vctlo
),
PositionExecutiveDate AS (
SELECT
vcteo.Years,
vcteo.Months,
vcteo.Days,
vcteo.profileId
FROM tenurePositionExecutiveOfficer vcteo
)
SELECT
p.id as profileId,
@ -168,7 +176,10 @@ import { ViewColumn, ViewEntity } from "typeorm";
vcto.Days,
vctlo.Years AS levelYears,
vctlo.Months AS levelMonths,
vctlo.Days AS levelDays
vctlo.Days AS levelDays,
vcteo.Years AS posExecutiveYears,
vcteo.Months AS posExecutiveMonths,
vcteo.Days AS posExecutiveDays
FROM profile p
LEFT JOIN posLevel ON p.posLevelId = posLevel.id
LEFT JOIN posType ON p.posTypeId = posType.id
@ -179,6 +190,7 @@ import { ViewColumn, ViewEntity } from "typeorm";
LEFT JOIN Fields fies ON p.id = fies.profileId
LEFT JOIN PositionDate vcto ON p.id = vcto.profileId
LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileId
LEFT JOIN PositionExecutiveDate vcteo ON p.id = vcteo.profileId
`,
})
export class viewRegistryOfficer {