Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-06-12 14:55:58 +07:00
commit ea2566395e
13 changed files with 341 additions and 55 deletions

View file

@ -27,11 +27,25 @@ export class AuthSysController extends Controller {
@Get("list")
public async listAuthSys() {
const getList = await this.authSysRepo.find();
// if (!getList || getList.length === 0) {
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// }
return new HttpSuccess(getList);
const getList = await this.authSysRepo.find({
select: ["id", "parentId", "sysName", "sysDescription", "order"],
});
if (!getList || getList.length === 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const lists = getList
.filter((x) => x.parentId == null)
.map((item) => {
return {
...item,
children: getList.filter((x) => x.parentId == item.id).sort((a, b) => a.order - b.order),
};
})
.sort((a, b) => a.order - b.order);
return new HttpSuccess(lists);
}
@Get("{systemId}")

View file

@ -23,6 +23,7 @@ import HttpError from "../interfaces/http-error";
import { Equal, ILike, In, IsNull, Like, Not, Brackets, MoreThan } from "typeorm";
import { RequestWithUser } from "../middlewares/user";
import { ChangePosition, CreateChangePosition, UpdateChangePosition } from "../entities/ChangePosition";
import { ProfileChangePosition, CreateProfileChangePosition } from "../entities/ProfileChangePosition";
@Route("api/v1/org/placement/change-position")
@Tags("Placement")
@ -33,7 +34,8 @@ import { ChangePosition, CreateChangePosition, UpdateChangePosition } from "../e
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class ChangePositionController extends Controller {
private ChangePositionRepository = AppDataSource.getRepository(ChangePosition);
private ChangePositionRepository = AppDataSource.getRepository(ChangePosition);
private ProfileChangePositionRepository = AppDataSource.getRepository(ProfileChangePosition);
/**
* API
@ -68,6 +70,41 @@ export class ChangePositionController extends Controller {
return new HttpSuccess();
}
/**
* API
*
* @summary (ADMIN)
*
* @param {string} id Id
*/
@Post("profile/{id}")
async CreateProfileChangePosition(
@Path() id: string,
@Body() body: CreateProfileChangePosition,
@Request() request: RequestWithUser,
) {
const changePosition = await this.ChangePositionRepository.findOneBy({ id });
if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง");
const profileChangePositions: ProfileChangePosition[] = [];
const profiles = new ProfileChangePosition();
for (const data of body.profiles) {
Object.assign(profiles, data);
let positionOld = data.positionOld ? `${data.positionOld}` : "";
let rootOld = data.rootOld ? data.positionOld ? `/${data.rootOld}` : `${data.rootOld}` : "";
profiles.changePositionId = id;
profiles.organizationPositionOld = `${positionOld}${rootOld}`,
profiles.status = "WAITTING",
profiles.createdUserId = request.user.sub;
profiles.createdFullName = request.user.name;
profiles.lastUpdateUserId = request.user.sub;
profiles.lastUpdateFullName = request.user.name;
profileChangePositions.push(profiles);
}
await this.ProfileChangePositionRepository.save(profileChangePositions);
return new HttpSuccess();
}
/**
* API
*
@ -107,7 +144,7 @@ export class ChangePositionController extends Controller {
) {
const changePosition = await this.ChangePositionRepository.findOneBy({ id });
if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง");
const checkDuplicate = await this.ChangePositionRepository.find({
where: {
@ -134,7 +171,7 @@ export class ChangePositionController extends Controller {
* @summary API (ADMIN)
*
*/
@Get("")
@Get()
async GetChangePositionLists() {
const data = await this.ChangePositionRepository.find();
return new HttpSuccess(data);

View file

@ -255,6 +255,8 @@ export class EmployeePositionController extends Controller {
? null
: `${position.posType.posTypeShortName} ${position.posLevel.posLevelName}`,
positionIsSelected: position.positionIsSelected,
isOfficer: posMaster.isOfficer,
isDirecter: posMaster.isDirector,
})),
};
return new HttpSuccess(formattedData);
@ -611,6 +613,8 @@ export class EmployeePositionController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง");
}
posMaster.posMasterNo = requestBody.posMasterNo;
posMaster.isDirector = requestBody.isDirector;
posMaster.isOfficer = requestBody.isOfficer;
posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix;
posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix;
posMaster.reason = requestBody.reason == null ? "" : requestBody.reason;

View file

@ -28,6 +28,8 @@ import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
import { ProfileFamilyMother } from "../entities/ProfileFamilyMother";
import { ProfileFamilyFather } from "../entities/ProfileFamilyFather";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType";
@Route("api/v1/org/upload")
@Tags("UPLOAD")
@ -40,6 +42,8 @@ export class ImportDataController extends Controller {
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
private profileRepo = AppDataSource.getRepository(Profile);
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
private posLevelRepo = AppDataSource.getRepository(PosLevel);
private posTypeRepo = AppDataSource.getRepository(PosType);
/**
* API upload EDU
*
@ -594,4 +598,58 @@ export class ImportDataController extends Controller {
await this.salaryRepository.save(profiles);
return new HttpSuccess(allData);
}
@Post("uploadposSQL")
@UseInterceptors(FileInterceptor("file"))
async UploadPOSFileSQL(@UploadedFile() file: Express.Multer.File) {
const workbook = xlsx.read(file.buffer, { type: "buffer" });
const sheetName = workbook.SheetNames[0];
const sheet = workbook.Sheets[sheetName];
const getProFile = xlsx.utils.sheet_to_json(sheet);
let profiles: any = [];
await Promise.all(
getProFile.map(async (item: any) => {
// Find profile by ID
let profile = await this.profileRepo.findOne({
where: { citizenId: item["ID"] },
});
if (!profile) {
return; // Skip processing this item
}
if (item["MP_CEE_TYPE"] === "NULL") {
profile.posTypeId = null;
} else {
// Find posType by posTypeName
const posType = await this.posTypeRepo.findOne({
where: { posTypeName: item["MP_CEE_TYPE"] },
});
if (!posType) {
return; // Skip processing this item
}
profile.posTypeId = posType.id;
}
// Check if posLevelName is "NULL"
if (item["MP_CEE_POSITION"] === "NULL") {
profile.posLevelId = null;
} else {
// Find posLevel by posLevelName
const posLevel = await this.posLevelRepo.findOne({
where: { posLevelName: item["MP_CEE_POSITION"] },
});
if (!posLevel) {
console.error(
`posLevel with name ${item["MP_CEE_POSITION"]} not found for profile ID ${profile.id}`,
);
return; // Skip processing this item
}
profile.posLevelId = posLevel.id;
}
profiles.push(profile);
}),
);
await this.profileRepo.save(profiles);
return new HttpSuccess(getProFile);
}
}

View file

@ -797,6 +797,8 @@ export class PositionController extends Controller {
if (!posMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง");
}
posMaster.isDirector = requestBody.isDirector;
posMaster.isOfficer = requestBody.isOfficer;
posMaster.posMasterNo = requestBody.posMasterNo;
posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix;
posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix;
@ -949,6 +951,8 @@ export class PositionController extends Controller {
position.positionExecutiveField = x.posDictExecutiveField;
position.positionArea = x.posDictArea;
position.isSpecial = x.isSpecial;
position.isOfficer = x.isOfficer;
position.isDirector = x.isDirector;
position.positionIsSelected = x.positionIsSelected;
position.posMasterId = posMaster.id;
position.createdUserId = request.user.sub;
@ -1001,6 +1005,8 @@ export class PositionController extends Controller {
positionArea: position.positionArea,
positionIsSelected: position.positionIsSelected,
isSpecial: position.isSpecial,
isOfficer: posMaster.isOfficer,
isDirecter: posMaster.isDirector,
})),
};
return new HttpSuccess(formattedData);

View file

@ -563,17 +563,27 @@ export class ProfileController extends Controller {
where: { keycloak: request.user.sub },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const _caregiver = await this.profileRepo.find({
relations: { posLevel: true, posType: true },
});
const _commander = await this.profileRepo.find({
relations: { posLevel: true, posType: true },
});
const _chairman = await this.profileRepo.find({
relations: { posLevel: true, posType: true },
});
const _caregiver = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.skip((1 - 1) * 20)
.take(20)
.getMany();
const _commander = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.skip((1 - 1) * 20)
.take(20)
.getMany();
const _chairman = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.skip((1 - 1) * 20)
.take(20)
.getMany();
const caregiver = _caregiver.map((_data) => ({
id: _data.id,
@ -2097,6 +2107,7 @@ export class ProfileController extends Controller {
child3ShortName: child3Holder?.orgChild3ShortName ?? null,
child4: child4Holder?.orgChild4Name ?? null,
child4Id: child4Holder?.id ?? null,
child4ShortName: child4Holder?.orgChild4ShortName ?? null,
posMasterNo: posMasterNo ?? null,
posTypeId: item.posTypeId,
posTypeName: item.posType?.posTypeName,

View file

@ -18,7 +18,7 @@ import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { Brackets, IsNull, Like, Not } from "typeorm";
import { Brackets, In, IsNull, Like, Not } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { calculateRetireDate, calculateRetireLaw } from "../interfaces/utils";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
@ -557,10 +557,10 @@ export class ProfileEmployeeController extends Controller {
const exists =
!!body.citizenId &&
(await this.profileRepo.findOne({
where: {
id: Not(id),
citizenId: body.citizenId,
employeeClass: String(body.employeeClass)
where: {
id: Not(id),
citizenId: body.citizenId,
employeeClass: String(body.employeeClass),
},
}));
@ -690,12 +690,12 @@ export class ProfileEmployeeController extends Controller {
: _data.current_holders[0].orgRoot != null
? `${_data.current_holders[0].orgRoot.orgRootShortName}${_data.current_holders[0].posMasterNo}`
: null;
const dateEmployment =
const dateEmployment =
_data.profileEmployeeEmployment.length == 0
? null
: _data.profileEmployeeEmployment.reduce((latest, current) => {
return (latest.date > current.date) ? latest : current;
}).date;
return latest.date > current.date ? latest : current;
}).date;
return {
id: _data.id,
prefix: _data.prefix,
@ -933,12 +933,12 @@ export class ProfileEmployeeController extends Controller {
: _data.current_holders[0].orgRoot != null
? `${_data.current_holders[0].orgRoot.orgRootShortName}${_data.current_holders[0].posMasterNo}`
: null;
const dateEmployment =
const dateEmployment =
_data.profileEmployeeEmployment.length == 0
? null
: _data.profileEmployeeEmployment.reduce((latest, current) => {
return (latest.date > current.date) ? latest : current;
}).date;
return latest.date > current.date ? latest : current;
}).date;
return {
id: _data.id,
prefix: _data.prefix,
@ -2569,33 +2569,33 @@ export class ProfileEmployeeController extends Controller {
/**
* API
*
* @summary (ADMIN)
* @summary (ADMIN)
*
* @param {string} profileEmployeeId profileEmployeeId
*/
@Get("information/{profileEmployeeId}")
async getInformationById(@Path() profileEmployeeId: string) {
const profileInformation = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
where: { id: profileEmployeeId },
});
if (!profileInformation) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const mapData = {
id: profileInformation.id,
positionEmployeeGroupId: profileInformation.positionEmployeeGroupId,
positionEmployeeLineId: profileInformation.positionEmployeeLineId,
positionEmployeePositionId: profileInformation.positionEmployeePositionId,
employeeOc: profileInformation.employeeOc,
employeeTypeIndividual: profileInformation.employeeTypeIndividual,
employeeWage: profileInformation.employeeWage,
employeeMoneyIncrease: profileInformation.employeeMoneyIncrease,
employeeMoneyAllowance: profileInformation.employeeMoneyAllowance,
employeeMoneyEmployee: profileInformation.employeeMoneyEmployee,
employeeMoneyEmployer: profileInformation.employeeMoneyEmployer,
id: profileInformation.id,
positionEmployeeGroupId: profileInformation.positionEmployeeGroupId,
positionEmployeeLineId: profileInformation.positionEmployeeLineId,
positionEmployeePositionId: profileInformation.positionEmployeePositionId,
employeeOc: profileInformation.employeeOc,
employeeTypeIndividual: profileInformation.employeeTypeIndividual,
employeeWage: profileInformation.employeeWage,
employeeMoneyIncrease: profileInformation.employeeMoneyIncrease,
employeeMoneyAllowance: profileInformation.employeeMoneyAllowance,
employeeMoneyEmployee: profileInformation.employeeMoneyEmployee,
employeeMoneyEmployer: profileInformation.employeeMoneyEmployer,
};
return new HttpSuccess(mapData);
}
/**
* API
*
@ -2781,4 +2781,42 @@ export class ProfileEmployeeController extends Controller {
return new HttpSuccess();
}
/**
* API
*
* @summary ORG_038 - (ADMIN) #
*
*/
@Post("report")
async sendReport(@Request() request: RequestWithUser, @Body() requestBody: { id: string[] }) {
const profiles = await this.profileRepo.find({ where: { id: In(requestBody.id) } });
const _profiles = await Promise.all(
profiles.map(async (item: any) => {
return {
...item,
statusTemp: "REPORT",
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
};
}),
);
await this.profileRepo.save(_profiles);
return new HttpSuccess();
}
/**
* API
*
* @summary ORG_038 - (ADMIN) #
*
*/
@Get("report")
async getReport(@Request() request: RequestWithUser) {
const profiles = await this.profileRepo.find({
where: { statusTemp: "REPORT", employeeClass: "TEMP" },
});
return new HttpSuccess(profiles);
}
}

View file

@ -1,12 +1,4 @@
import {
Entity,
Column,
OneToMany,
CreateDateColumn,
UpdateDateColumn,
PrimaryColumn,
} from "typeorm";
import { AuthRoleAttr } from "./AuthRoleAttr";
import { Entity, Column, CreateDateColumn, UpdateDateColumn, PrimaryColumn } from "typeorm";
@Entity("authSys")
export class AuthSys {
@ -16,6 +8,36 @@ export class AuthSys {
})
id: string;
@Column({
comment: "Id ของเมนูหลักถ้าเป็นเมนูหลักจะเป็นค่า null",
nullable: true,
default: null,
length: 255,
})
parentId!: string;
@Column({
comment: "ชื่อ icon",
nullable: true,
default: null,
length: 100,
})
icon!: string;
@Column({
comment: "path url ของระบบ",
nullable: true,
default: null,
length: 255,
})
path!: string;
@Column({
comment: "ลำดับการแสดงผล",
default: 0,
})
order: number;
@CreateDateColumn({ comment: "สร้างข้อมูลเมื่อ" })
createdAt!: Date;
@ -66,6 +88,9 @@ export class CreateAuthSys {
@PrimaryColumn()
id: string;
@Column()
parentId: string;
@Column()
sysName: string;

View file

@ -237,6 +237,12 @@ export class CreateEmployeePosMaster {
@Column()
reason: string | null;
@Column()
isDirector: boolean;
@Column()
isOfficer: boolean;
}
export type UpdateEmployeePosMaster = Partial<EmployeePosMaster>;

View file

@ -236,6 +236,12 @@ export class CreatePosMaster {
@Column()
reason: string | null;
@Column()
isDirector: boolean;
@Column()
isOfficer: boolean;
}
export type UpdatePosMaster = Partial<PosMaster>;

View file

@ -10,7 +10,7 @@ export class ProfileChangePosition extends EntityBase {
@Column({ nullable: true, comment: "วุฒิ/สาขาเดิม", default: null })
educationOld: string;
@Column({ nullable: true, comment: "สังกัดเดิม", default: null })
@Column({ nullable: true, comment: "สังกัดเดิม ตำแหน่ง", default: null })
organizationPositionOld: string;
@Column({ nullable: true, comment: "สังกัดเดิม", default: null })
@ -32,7 +32,6 @@ export class ProfileChangePosition extends EntityBase {
amountOld: number;
@Column({ nullable: true, comment: "profile Id", default: null })
profileId: string;
@ -191,6 +190,9 @@ export class ProfileChangePosition extends EntityBase {
@Column({ nullable: true, comment: "ชื่อระดับตำแหน่ง old", default: null })
posLevelNameOld: string;
@Column({ nullable: true, comment: "สถานะ", type: "text", default: null })
status: string;
@Column({nullable: true, length: 40, comment: "คีย์นอก(FK)ของตาราง ChangePosition", default: null })
changePositionId: string;
@ -198,3 +200,44 @@ export class ProfileChangePosition extends EntityBase {
@JoinColumn({ name: "changePositionId" })
profile: ChangePosition;
}
export class CreateProfileChangePosition {
changePositionId: string;
profiles: ProfileItem[]
}
export class ProfileItem {
profileId: string;
prefix: string;
firstName: string;
lastName: string;
citizenId: string;
positionOld: string | null;
positionTypeOld: string | null;
positionLevelOld: string | null;
positionNumberOld: string | null;
organizationOld: string | null;
organizationPositionOld: string | null;
amountOld: number | null;
educationOld: string | null;
rootOld: string | null;
rootOldId: string | null;
rootShortNameOld: string | null;
child1Old: string | null;
child1OldId: string | null;
child1ShortNameOld: string | null;
child2Old: string | null;
child2OldId: string | null;
child2ShortNameOld: string | null;
child3Old: string | null;
child3OldId: string | null;
child3ShortNameOld: string | null;
child4Old: string | null;
child4OldId: string | null;
child4ShortNameOld: string | null;
posMasterNoOld: number | null;
posTypeOldId: string | null;
posTypeNameOld: string | null;
posLevelOldId: string | null;
posLevelNameOld: string | null;
}

View file

@ -0,0 +1,22 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableRoleAddSys1718173589821 implements MigrationInterface {
name = 'UpdateTableRoleAddSys1718173589821'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX \`FK_b5b59c60792d518f4f025379dba\` ON \`authRoleAttr\``);
await queryRunner.query(`ALTER TABLE \`authSys\` ADD \`parentId\` varchar(255) NULL COMMENT 'Id ของเมนูหลักถ้าเป็นเมนูหลักจะเป็นค่า null'`);
await queryRunner.query(`ALTER TABLE \`authSys\` ADD \`icon\` varchar(100) NULL COMMENT 'ชื่อ icon'`);
await queryRunner.query(`ALTER TABLE \`authSys\` ADD \`path\` varchar(255) NULL COMMENT 'path url ของระบบ'`);
await queryRunner.query(`ALTER TABLE \`authSys\` ADD \`order\` int NOT NULL COMMENT 'ลำดับการแสดงผล' DEFAULT '0'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`authSys\` DROP COLUMN \`order\``);
await queryRunner.query(`ALTER TABLE \`authSys\` DROP COLUMN \`path\``);
await queryRunner.query(`ALTER TABLE \`authSys\` DROP COLUMN \`icon\``);
await queryRunner.query(`ALTER TABLE \`authSys\` DROP COLUMN \`parentId\``);
await queryRunner.query(`CREATE INDEX \`FK_b5b59c60792d518f4f025379dba\` ON \`authRoleAttr\` (\`authSysId\`)`);
}
}

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableRoleAddSys11718176873613 implements MigrationInterface {
name = 'UpdateTableRoleAddSys11718176873613'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileChangePosition\` ADD \`status\` text NULL COMMENT 'สถานะ'`);
await queryRunner.query(`ALTER TABLE \`profileChangePosition\` CHANGE \`organizationPositionOld\` \`organizationPositionOld\` varchar(255) NULL COMMENT 'สังกัดเดิม ตำแหน่ง'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileChangePosition\` CHANGE \`organizationPositionOld\` \`organizationPositionOld\` varchar(255) NULL COMMENT 'สังกัดเดิม'`);
await queryRunner.query(`ALTER TABLE \`profileChangePosition\` DROP COLUMN \`status\``);
}
}