Merge branch 'develop' into dev

* develop:
  update org
  fix ผู้เกษียณ ในแบบร่าง ของระบบโครงสร้างไม่ถูกปลด #1912
  migration
  migration
  update Retire Clear Org
  #1767 (#205)
  test commit
This commit is contained in:
Warunee Tamkoo 2025-11-04 09:01:34 +07:00
commit 4af26d19e6
10 changed files with 182 additions and 46 deletions

View file

@ -67,8 +67,8 @@ async function main() {
});
// const cronTime_Oct = "0 0 1 10 *";
// Test #1892
const cronTime_Oct = "0 0 31 10 *";
// Test #1912
const cronTime_Oct = "0 0 4 11 *";
cron.schedule(cronTime_Oct, async () => {
try {
const commandController = new CommandController();

View file

@ -1477,24 +1477,6 @@ export class CommandController extends Controller {
}
// @Get("XXX")
async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) {
// let body = {
// client_id: "gettoken",
// client_secret: process.env.AUTH_ACCOUNT_SECRET,
// grant_type: "client_credentials",
// };
// const postData = querystring.stringify(body);
// const response = await axios.post(
// `${process.env.KC_URL}/realms/${process.env.KC_REALMS}/protocol/openid-connect/token`,
// postData,
// {
// headers: {
// "Content-Type": "application/x-www-form-urlencoded",
// api_key: process.env.API_KEY,
// },
// },
// );
// const adminToken = response.data.access_token;
// const adminToken = request.headers["authorization"]?.replace("Bearer ", "");
const adminToken = await getToken() ?? "";
const today = new Date();
today.setUTCHours(0, 0, 0, 0);
@ -1668,32 +1650,30 @@ export class CommandController extends Controller {
}
async posMasterRetire(profileId: string, type: string, _Date: Date) {
const orgRevision = await this.orgRevisionRepo.findOne({
const revisionIsCurrent = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (orgRevision) {
if (revisionIsCurrent) {
let _posMaster: any = null;
let _position: any = null;
if (type == "OFFICER") {
_posMaster = await this.posMasterRepository.findOne({
where: {
orgRevisionId: orgRevision.id,
orgRevisionId: revisionIsCurrent.id,
current_holderId: profileId,
},
});
if (_posMaster) {
_position = await this.positionRepository.findOne({
where: {
await this.positionRepository.update(
{
posMasterId: _posMaster.id,
positionIsSelected: true,
},
});
if (_position) {
_position.positionIsSelected = false;
_position.lastUpdateFullName = "System Administrator";
_position.lastUpdatedAt = _Date;
await this.positionRepository.save(_position);
}
{
positionIsSelected: false,
lastUpdateFullName: "System Administrator",
lastUpdatedAt: _Date,
}
);
_posMaster.isSit = false;
_posMaster.current_holderId = null;
_posMaster.lastUpdateFullName = "System Administrator";
@ -1701,26 +1681,57 @@ export class CommandController extends Controller {
await this.posMasterRepository.save(_posMaster);
await CreatePosMasterHistoryOfficer(_posMaster.id, null);
}
const revisionIsDraft = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true },
});
if (revisionIsDraft) {
_posMaster = null;
_posMaster = await this.posMasterRepository.findOne({
where: {
orgRevisionId: revisionIsDraft.id,
next_holderId: profileId,
},
});
if (_posMaster) {
await this.positionRepository.update(
{
posMasterId: _posMaster.id,
positionIsSelected: true,
},
{
positionIsSelected: false,
lastUpdateFullName: "System Administrator",
lastUpdatedAt: _Date,
}
);
_posMaster.isSit = false;
_posMaster.next_holderId = null;
_posMaster.lastUpdateFullName = "System Administrator";
_posMaster.lastUpdatedAt = _Date;
await this.posMasterRepository.save(_posMaster);
await CreatePosMasterHistoryOfficer(_posMaster.id, null);
}
// console.log("clear posMaster & position 'Draf' success")
}
} else if (type == "EMPLOYEE") {
_posMaster = await this.employeePosMasterRepository.findOne({
where: {
orgRevisionId: orgRevision.id,
orgRevisionId: revisionIsCurrent.id,
current_holderId: profileId,
},
});
if (_posMaster) {
_position = await this.employeePositionRepository.findOne({
where: {
await this.employeePositionRepository.update(
{
posMasterId: _posMaster.id,
positionIsSelected: true,
},
});
if (_position) {
_position.positionIsSelected = false;
_position.lastUpdateFullName = "System Administrator";
_position.lastUpdatedAt = _Date;
await this.employeePositionRepository.save(_position);
}
{
positionIsSelected: false,
lastUpdateFullName: "System Administrator",
lastUpdatedAt: _Date,
}
);
_posMaster.isSit = false;
_posMaster.current_holderId = null;
_posMaster.lastUpdateFullName = "System Administrator";
@ -1729,6 +1740,7 @@ export class CommandController extends Controller {
await CreatePosMasterHistoryEmployee(_posMaster.id, null);
}
}
// console.log("clear posMaster & position 'Current' success")
}
}

View file

@ -6312,4 +6312,54 @@ export class ImportDataController extends Controller {
}
return new HttpSuccess();
}
@Post("updateRetireClearOrg")
async updateRetireClearOrg(@Request() request: { user: Record<string, any> }) {
const profiles = await this.profileRepo.find({
where: { isLeave: true },
select: ["id"],
});
const profileIds = profiles.map((p) => p.id);
if (profileIds.length > 0) {
const posmasters = await this.posMasterRepo.find({
where: {
orgRevision: {
orgRevisionIsCurrent: false,
orgRevisionIsDraft: true,
},
next_holderId: In(profileIds),
},
});
for (const posmaster of posmasters) {
posmaster.next_holderId = null;
}
if (posmasters.length > 0) {
await this.posMasterRepo.save(posmasters);
}
}
const profileEmps = await this.profileEmpRepo.find({
where: { isLeave: true },
select: ["id"],
});
const profileEmpIds = profileEmps.map((p) => p.id);
if (profileEmpIds.length > 0) {
const posmasterEmps = await this.posMasterEmpRepo.find({
where: {
orgRevision: {
orgRevisionIsCurrent: false,
orgRevisionIsDraft: true,
},
next_holderId: In(profileEmpIds),
},
});
for (const posmasterEmp of posmasterEmps) {
posmasterEmp.next_holderId = null;
}
if (posmasterEmps.length > 0) {
await this.posMasterEmpRepo.save(posmasterEmps);
}
}
return new HttpSuccess();
}
}

View file

@ -1218,6 +1218,7 @@ export class OrganizationController extends Controller {
"orgRoot.SECTION_CODE",
"orgRoot.JOB_CODE",
"orgRoot.responsibility",
"orgRoot.ancestorDNA",
])
.orderBy("orgRoot.orgRootOrder", "ASC")
.getMany();
@ -1246,6 +1247,7 @@ export class OrganizationController extends Controller {
"orgChild1.SECTION_CODE",
"orgChild1.JOB_CODE",
"orgChild1.responsibility",
"orgChild1.ancestorDNA",
])
.orderBy("orgChild1.orgChild1Order", "ASC")
.getMany()
@ -1275,6 +1277,7 @@ export class OrganizationController extends Controller {
"orgChild2.JOB_CODE",
"orgChild2.orgChild1Id",
"orgChild2.responsibility",
"orgChild2.ancestorDNA",
])
.orderBy("orgChild2.orgChild2Order", "ASC")
.getMany()
@ -1304,6 +1307,7 @@ export class OrganizationController extends Controller {
"orgChild3.JOB_CODE",
"orgChild3.orgChild2Id",
"orgChild3.responsibility",
"orgChild3.ancestorDNA",
])
.orderBy("orgChild3.orgChild3Order", "ASC")
.getMany()
@ -1333,6 +1337,7 @@ export class OrganizationController extends Controller {
"orgChild4.JOB_CODE",
"orgChild4.orgChild3Id",
"orgChild4.responsibility",
"orgChild4.ancestorDNA",
])
.orderBy("orgChild4.orgChild4Order", "ASC")
.getMany()
@ -1351,6 +1356,7 @@ export class OrganizationController extends Controller {
orgCode: orgRoot.orgRootCode + "00",
orgTreeRank: orgRoot.orgRootRank,
orgTreeRankSub: orgRoot.orgRootRankSub,
orgRootDnaId: orgRoot.ancestorDNA,
DEPARTMENT_CODE: orgRoot.DEPARTMENT_CODE,
DIVISION_CODE: orgRoot.DIVISION_CODE,
SECTION_CODE: orgRoot.SECTION_CODE,
@ -1466,6 +1472,8 @@ export class OrganizationController extends Controller {
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
orgTreeRank: orgChild1.orgChild1Rank,
orgTreeRankSub: orgChild1.orgChild1RankSub,
orgRootDnaId: orgRoot.ancestorDNA,
orgChild1DnaId: orgChild1.ancestorDNA,
DEPARTMENT_CODE: orgChild1.DEPARTMENT_CODE,
DIVISION_CODE: orgChild1.DIVISION_CODE,
SECTION_CODE: orgChild1.SECTION_CODE,
@ -1587,6 +1595,9 @@ export class OrganizationController extends Controller {
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
orgTreeRank: orgChild2.orgChild2Rank,
orgTreeRankSub: orgChild2.orgChild2RankSub,
orgRootDnaId: orgRoot.ancestorDNA,
orgChild1DnaId: orgChild1.ancestorDNA,
orgChild2DnaId: orgChild2.ancestorDNA,
DEPARTMENT_CODE: orgChild2.DEPARTMENT_CODE,
DIVISION_CODE: orgChild2.DIVISION_CODE,
SECTION_CODE: orgChild2.SECTION_CODE,
@ -1709,6 +1720,10 @@ export class OrganizationController extends Controller {
orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code,
orgTreeRank: orgChild3.orgChild3Rank,
orgTreeRankSub: orgChild3.orgChild3RankSub,
orgRootDnaId: orgRoot.ancestorDNA,
orgChild1DnaId: orgChild1.ancestorDNA,
orgChild2DnaId: orgChild2.ancestorDNA,
orgChild3DnaId: orgChild3.ancestorDNA,
DEPARTMENT_CODE: orgChild3.DEPARTMENT_CODE,
DIVISION_CODE: orgChild3.DIVISION_CODE,
SECTION_CODE: orgChild3.SECTION_CODE,
@ -1831,6 +1846,11 @@ export class OrganizationController extends Controller {
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code,
orgTreeRank: orgChild4.orgChild4Rank,
orgTreeRankSub: orgChild4.orgChild4RankSub,
orgRootDnaId: orgRoot.ancestorDNA,
orgChild1DnaId: orgChild1.ancestorDNA,
orgChild2DnaId: orgChild2.ancestorDNA,
orgChild3DnaId: orgChild3.ancestorDNA,
orgChild4DnaId: orgChild4.ancestorDNA,
DEPARTMENT_CODE: orgChild4.DEPARTMENT_CODE,
DIVISION_CODE: orgChild4.DIVISION_CODE,
SECTION_CODE: orgChild4.SECTION_CODE,

View file

@ -14,9 +14,9 @@ export class ApiKey extends EntityBase {
name: string;
@Column({
type: 'longtext',
nullable: true,
comment: "keyApi",
length: 255,
default: null,
})
keyApi: string;

View file

@ -23,6 +23,13 @@ export class AuthRole extends EntityBase {
})
roleDescription: string;
@Column({
nullable: true,
comment: "ข้อมูลที่ role admin สามารถเห็นได้",
default: null,
})
isAdminVisibled: boolean;
@OneToMany(() => AuthRoleAttr, (authRoleAttr) => authRoleAttr.authRoleAttrForRole)
authRoles: AuthRoleAttr[];

View file

@ -55,9 +55,9 @@ export class ProfileTraining extends EntityBase {
topic: string;
@Column({
type: 'longtext',
nullable: true,
length: 200,
comment: "สถานที่ฝึกอบรม/ดูงาน ",
comment: "สถานที่ฝึกอบรม/ดูงาน",
default: null,
})
place: string;

View file

@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateSizeKeyapiField1762159481993 implements MigrationInterface {
name = 'UpdateSizeKeyapiField1762159481993'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`keyApi\``);
await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`keyApi\` longtext NULL COMMENT 'keyApi'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`apiKey\` DROP COLUMN \`keyApi\``);
await queryRunner.query(`ALTER TABLE \`apiKey\` ADD \`keyApi\` varchar(255) NULL COMMENT 'keyApi'`);
}
}

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateSizePlaceField1762159824907 implements MigrationInterface {
name = 'UpdateSizePlaceField1762159824907'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileTraining\` DROP COLUMN \`place\``);
await queryRunner.query(`ALTER TABLE \`profileTraining\` ADD \`place\` longtext NULL COMMENT 'สถานที่ฝึกอบรม/ดูงาน'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileTraining\` DROP COLUMN \`place\``);
await queryRunner.query(`ALTER TABLE \`profileTraining\` ADD \`place\` varchar(200) NULL COMMENT 'สถานที่ฝึกอบรม/ดูงาน '`);
}
}

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddFieldIsAdminVisibledTableAuthRole1762165716863 implements MigrationInterface {
name = 'AddFieldIsAdminVisibledTableAuthRole1762165716863'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`authRole\` ADD \`isAdminVisibled\` tinyint NULL COMMENT 'ข้อมูลที่ role admin สามารถเห็นได้'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`authRole\` DROP COLUMN \`isAdminVisibled\``);
}
}