#2427 and migration
This commit is contained in:
parent
7f3408e2f5
commit
28b5408d5b
6 changed files with 159 additions and 5 deletions
|
|
@ -48,6 +48,7 @@ import {
|
||||||
import { Position } from "../entities/Position";
|
import { Position } from "../entities/Position";
|
||||||
import { PosMaster } from "../entities/PosMaster";
|
import { PosMaster } from "../entities/PosMaster";
|
||||||
import { EmployeePosition } from "../entities/EmployeePosition";
|
import { EmployeePosition } from "../entities/EmployeePosition";
|
||||||
|
import { getPosMasterNo, getOrgFullName } from "../utils/org-formatting";
|
||||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||||
import { ProfileDiscipline } from "../entities/ProfileDiscipline";
|
import { ProfileDiscipline } from "../entities/ProfileDiscipline";
|
||||||
import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory";
|
import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory";
|
||||||
|
|
@ -3660,6 +3661,7 @@ export class CommandController extends Controller {
|
||||||
|
|
||||||
const posMaster = await this.posMasterRepository.findOne({
|
const posMaster = await this.posMasterRepository.findOne({
|
||||||
where: { id: item.posmasterId },
|
where: { id: item.posmasterId },
|
||||||
|
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"],
|
||||||
});
|
});
|
||||||
if (posMaster == null)
|
if (posMaster == null)
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||||
|
|
@ -3715,6 +3717,7 @@ export class CommandController extends Controller {
|
||||||
id: item.positionId,
|
id: item.positionId,
|
||||||
posMasterId: item.posmasterId,
|
posMasterId: item.posmasterId,
|
||||||
},
|
},
|
||||||
|
relations: ["posExecutive"],
|
||||||
});
|
});
|
||||||
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
|
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
|
||||||
if (positionNew != null) {
|
if (positionNew != null) {
|
||||||
|
|
@ -3723,6 +3726,12 @@ export class CommandController extends Controller {
|
||||||
profile.posLevelId = positionNew.posLevelId;
|
profile.posLevelId = positionNew.posLevelId;
|
||||||
profile.posTypeId = positionNew.posTypeId;
|
profile.posTypeId = positionNew.posTypeId;
|
||||||
profile.position = positionNew.positionName;
|
profile.position = positionNew.positionName;
|
||||||
|
profile.positionField = positionNew.positionField ?? null;
|
||||||
|
profile.posExecutive = positionNew.posExecutive?.posExecutiveName ?? null;
|
||||||
|
profile.positionArea = positionNew.positionArea ?? null;
|
||||||
|
profile.positionExecutiveField = positionNew.positionExecutiveField ?? null;
|
||||||
|
profile.posMasterNo = getPosMasterNo(posMaster);
|
||||||
|
profile.org = getOrgFullName(posMaster);
|
||||||
}
|
}
|
||||||
profile.amount = item.amount ?? null;
|
profile.amount = item.amount ?? null;
|
||||||
profile.amountSpecial = item.amountSpecial ?? null;
|
profile.amountSpecial = item.amountSpecial ?? null;
|
||||||
|
|
@ -6876,7 +6885,7 @@ export class CommandController extends Controller {
|
||||||
where: {
|
where: {
|
||||||
id: item.bodyPosition.posmasterId,
|
id: item.bodyPosition.posmasterId,
|
||||||
},
|
},
|
||||||
relations: { orgRevision: true }
|
relations: { orgRevision: true, orgRoot: true, orgChild1: true, orgChild2: true, orgChild3: true, orgChild4: true }
|
||||||
});
|
});
|
||||||
|
|
||||||
// เช็คว่า posMaster ที่หามาอยู่ในโครงสร้างปัจจุบันหรือไม่
|
// เช็คว่า posMaster ที่หามาอยู่ในโครงสร้างปัจจุบันหรือไม่
|
||||||
|
|
@ -6893,9 +6902,8 @@ export class CommandController extends Controller {
|
||||||
orgRevisionIsDraft: false
|
orgRevisionIsDraft: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
relations: { orgRevision: true }
|
relations: { orgRevision: true, orgRoot: true, orgChild1: true, orgChild2: true, orgChild3: true, orgChild4: true }
|
||||||
});
|
}); }
|
||||||
}
|
|
||||||
|
|
||||||
if (posMaster == null)
|
if (posMaster == null)
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||||
|
|
@ -6983,6 +6991,7 @@ export class CommandController extends Controller {
|
||||||
id: item.bodyPosition.positionId,
|
id: item.bodyPosition.positionId,
|
||||||
posMasterId: posMaster.id,
|
posMasterId: posMaster.id,
|
||||||
},
|
},
|
||||||
|
relations: ["posExecutive"],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6993,6 +7002,12 @@ export class CommandController extends Controller {
|
||||||
profile.posLevelId = positionNew.posLevelId;
|
profile.posLevelId = positionNew.posLevelId;
|
||||||
profile.posTypeId = positionNew.posTypeId;
|
profile.posTypeId = positionNew.posTypeId;
|
||||||
profile.position = positionNew.positionName;
|
profile.position = positionNew.positionName;
|
||||||
|
profile.positionField = positionNew.positionField ?? null;
|
||||||
|
profile.posExecutive = positionNew.posExecutive?.posExecutiveName ?? null;
|
||||||
|
profile.positionArea = positionNew.positionArea ?? null;
|
||||||
|
profile.positionExecutiveField = positionNew.positionExecutiveField ?? null;
|
||||||
|
profile.posMasterNo = getPosMasterNo(posMaster);
|
||||||
|
profile.org = getOrgFullName(posMaster);
|
||||||
// profile.dateStart = new Date();
|
// profile.dateStart = new Date();
|
||||||
await this.profileRepository.save(profile, { data: req });
|
await this.profileRepository.save(profile, { data: req });
|
||||||
setLogDataDiff(req, { before, after: profile });
|
setLogDataDiff(req, { before, after: profile });
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ import { AuthRole } from "../entities/AuthRole";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
import { resolveNodeLevel, setLogDataDiff } from "../interfaces/utils";
|
import { resolveNodeLevel, setLogDataDiff } from "../interfaces/utils";
|
||||||
|
import { getPosMasterNo, getOrgFullName } from "../utils/org-formatting";
|
||||||
import { PosMasterAssign } from "../entities/PosMasterAssign";
|
import { PosMasterAssign } from "../entities/PosMasterAssign";
|
||||||
import { Assign } from "../entities/Assign";
|
import { Assign } from "../entities/Assign";
|
||||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
|
@ -3793,7 +3794,7 @@ export class PositionController extends Controller {
|
||||||
await new permission().PermissionUpdate(request, "SYS_ORG");
|
await new permission().PermissionUpdate(request, "SYS_ORG");
|
||||||
const dataMaster = await this.posMasterRepository.findOne({
|
const dataMaster = await this.posMasterRepository.findOne({
|
||||||
where: { id: requestBody.posMaster },
|
where: { id: requestBody.posMaster },
|
||||||
relations: ["positions"],
|
relations: ["positions", "orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"],
|
||||||
});
|
});
|
||||||
if (!dataMaster) {
|
if (!dataMaster) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||||
|
|
@ -3825,6 +3826,7 @@ export class PositionController extends Controller {
|
||||||
if (_profile) {
|
if (_profile) {
|
||||||
let _position = await this.positionRepository.findOne({
|
let _position = await this.positionRepository.findOne({
|
||||||
where: { id: requestBody.position, posMasterId: requestBody.posMaster },
|
where: { id: requestBody.position, posMasterId: requestBody.posMaster },
|
||||||
|
relations: ["posExecutive"],
|
||||||
});
|
});
|
||||||
if (_position) {
|
if (_position) {
|
||||||
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
|
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
|
||||||
|
|
@ -3832,6 +3834,12 @@ export class PositionController extends Controller {
|
||||||
_profile.position = _position.positionName;
|
_profile.position = _position.positionName;
|
||||||
_profile.posTypeId = _position.posTypeId;
|
_profile.posTypeId = _position.posTypeId;
|
||||||
_profile.posLevelId = _position.posLevelId;
|
_profile.posLevelId = _position.posLevelId;
|
||||||
|
_profile.positionField = _position.positionField ?? undefined;
|
||||||
|
_profile.posExecutive = _position.posExecutive?.posExecutiveName ?? undefined;
|
||||||
|
_profile.positionArea = _position.positionArea ?? undefined;
|
||||||
|
_profile.positionExecutiveField = _position.positionExecutiveField ?? undefined;
|
||||||
|
_profile.posMasterNo = getPosMasterNo(dataMaster);
|
||||||
|
_profile.org = getOrgFullName(dataMaster);
|
||||||
await this.profileRepository.save(_profile);
|
await this.profileRepository.save(_profile);
|
||||||
setLogDataDiff(request, { before, after: _profile });
|
setLogDataDiff(request, { before, after: _profile });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,54 @@ export class Profile extends EntityBase {
|
||||||
})
|
})
|
||||||
posTypeId: string | null;
|
posTypeId: string | null;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "สายงาน",
|
||||||
|
length: 45,
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
positionField: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "ตำแหน่งทางการบริหาร",
|
||||||
|
length: 255,
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
posExecutive?: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "ด้าน/สาขา",
|
||||||
|
length: 255,
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
positionArea?: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "ด้านทางการบริหาร",
|
||||||
|
length: 255,
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
positionExecutiveField?: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "เลขที่ตำแหน่ง",
|
||||||
|
length: 255,
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
posMasterNo?: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "สังกัด",
|
||||||
|
type: "text",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
org?: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
length: 255,
|
length: 255,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class AddPositionFieldsToProfile1776308026834 implements MigrationInterface {
|
||||||
|
name = 'AddPositionFieldsToProfile1776308026834'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`positionField\` varchar(45) NULL COMMENT 'สายงาน'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`posExecutive\` varchar(255) NULL COMMENT 'ตำแหน่งทางการบริหาร'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`positionArea\` varchar(255) NULL COMMENT 'ด้าน/สาขา'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`positionExecutiveField\` varchar(255) NULL COMMENT 'ด้านทางการบริหาร'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`posMasterNo\` varchar(255) NULL COMMENT 'เลขที่ตำแหน่ง'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`org\` text NULL COMMENT 'สังกัด'`);
|
||||||
|
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`positionField\` varchar(45) NULL COMMENT 'สายงาน'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`posExecutive\` varchar(255) NULL COMMENT 'ตำแหน่งทางการบริหาร'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`positionArea\` varchar(255) NULL COMMENT 'ด้าน/สาขา'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`positionExecutiveField\` varchar(255) NULL COMMENT 'ด้านทางการบริหาร'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`posMasterNo\` varchar(255) NULL COMMENT 'เลขที่ตำแหน่ง'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`org\` text NULL COMMENT 'สังกัด'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`org\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`posMasterNo\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`positionExecutiveField\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`positionArea\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`posExecutive\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`positionField\``);
|
||||||
|
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`org\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`posMasterNo\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`positionExecutiveField\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`positionArea\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`posExecutive\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`positionField\``);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ import { AppDataSource } from "../database/data-source";
|
||||||
import { Command } from "../entities/Command";
|
import { Command } from "../entities/Command";
|
||||||
import { chunkArray, commandTypePath } from "../interfaces/utils";
|
import { chunkArray, commandTypePath } from "../interfaces/utils";
|
||||||
import CallAPI from "../interfaces/call-api";
|
import CallAPI from "../interfaces/call-api";
|
||||||
|
import { getPosMasterNo, getOrgFullName } from "../utils/org-formatting";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { PosMaster } from "../entities/PosMaster";
|
import { PosMaster } from "../entities/PosMaster";
|
||||||
|
|
@ -668,6 +669,12 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
profile.posLevelId = position?.posLevelId ?? _null;
|
profile.posLevelId = position?.posLevelId ?? _null;
|
||||||
profile.posTypeId = position?.posTypeId ?? _null;
|
profile.posTypeId = position?.posTypeId ?? _null;
|
||||||
profile.position = position?.positionName ?? _null;
|
profile.position = position?.positionName ?? _null;
|
||||||
|
profile.positionField = position?.positionField ?? _null;
|
||||||
|
profile.posExecutive = position?.posExecutive?.posExecutiveName ?? _null;
|
||||||
|
profile.positionArea = position?.positionArea ?? _null;
|
||||||
|
profile.positionExecutiveField = position?.positionExecutiveField ?? _null;
|
||||||
|
profile.posMasterNo = getPosMasterNo(item) ?? _null;
|
||||||
|
profile.org = getOrgFullName(item) ?? _null;
|
||||||
await repoProfile.save(profile);
|
await repoProfile.save(profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,3 +68,42 @@ export function filterPosMasters(
|
||||||
): PosMaster[] {
|
): PosMaster[] {
|
||||||
return posMasters.filter((x) => x[childLevelIdKey] == null && x.isDirector === true);
|
return posMasters.filter((x) => x[childLevelIdKey] == null && x.isDirector === true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* สร้าง orgShortName จาก posMaster (ต้อง load org relations มาก่อน)
|
||||||
|
*/
|
||||||
|
export function getOrgShortName(posMaster: PosMaster): string {
|
||||||
|
if (posMaster.orgChild1Id === null) {
|
||||||
|
return posMaster.orgRoot?.orgRootShortName ?? "";
|
||||||
|
} else if (posMaster.orgChild2Id === null) {
|
||||||
|
return posMaster.orgChild1?.orgChild1ShortName ?? "";
|
||||||
|
} else if (posMaster.orgChild3Id === null) {
|
||||||
|
return posMaster.orgChild2?.orgChild2ShortName ?? "";
|
||||||
|
} else if (posMaster.orgChild4Id === null) {
|
||||||
|
return posMaster.orgChild3?.orgChild3ShortName ?? "";
|
||||||
|
} else {
|
||||||
|
return posMaster.orgChild4?.orgChild4ShortName ?? "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* สร้างชื่อสังกัดเต็ม จาก posMaster (join ด้วย \n)
|
||||||
|
*/
|
||||||
|
export function getOrgFullName(posMaster: PosMaster): string {
|
||||||
|
const parts = [
|
||||||
|
posMaster.orgChild4?.orgChild4Name,
|
||||||
|
posMaster.orgChild3?.orgChild3Name,
|
||||||
|
posMaster.orgChild2?.orgChild2Name,
|
||||||
|
posMaster.orgChild1?.orgChild1Name,
|
||||||
|
posMaster.orgRoot?.orgRootName,
|
||||||
|
];
|
||||||
|
return parts.filter((part) => part !== undefined && part !== null).join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* สร้างเลขที่ตำแหน่ง เช่น "กทม. 1234"
|
||||||
|
*/
|
||||||
|
export function getPosMasterNo(posMaster: PosMaster): string {
|
||||||
|
const orgShortName = getOrgShortName(posMaster);
|
||||||
|
return `${orgShortName} ${posMaster.posMasterNo}`;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue