ค้นหาทะเบียน
This commit is contained in:
parent
e368c4cae8
commit
6e8b8d58b9
5 changed files with 1412 additions and 32 deletions
1279
src/controllers/MainController.ts
Normal file
1279
src/controllers/MainController.ts
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -25,7 +25,7 @@ import { OrgRevision } from "../entities/OrgRevision";
|
|||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
import { PosType } from "../entities/PosType";
|
||||
import { calculateRetireDate } from "../interfaces/utils";
|
||||
import { calculateRetireDate, calculateRetireYear } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
||||
@Route("api/v1/org/profile")
|
||||
|
|
@ -259,39 +259,91 @@ export class ProfileController extends Controller {
|
|||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query() searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position",
|
||||
@Query() searchKeyword: string = "",
|
||||
@Query() posType?: string,
|
||||
@Query() posLevel?: string,
|
||||
@Query() yearLeave?: number,
|
||||
@Query() isProbation?: boolean,
|
||||
@Query() isRetire?: boolean,
|
||||
) {
|
||||
if (searchField === "fullName") {
|
||||
const [record, total] = await this.profileRepo
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.posType", "posType")
|
||||
.leftJoinAndSelect("profile.gender", "gender")
|
||||
.leftJoinAndSelect("profile.relationship", "relationship")
|
||||
.leftJoinAndSelect("profile.bloodGroup", "bloodGroup")
|
||||
.where("CONCAT(profile.firstName, ' ', profile.lastName) LIKE :fullName", {
|
||||
fullName: `%${searchKeyword}%`,
|
||||
})
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
return new HttpSuccess({ data: record, total });
|
||||
let queryLike =
|
||||
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
|
||||
if (searchField == "citizenId") {
|
||||
queryLike = "profile.citizenId LIKE :keyword";
|
||||
} else if (searchField == "position") {
|
||||
queryLike = "profile.position LIKE :keyword";
|
||||
}
|
||||
const [record, total] = await this.profileRepo
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.posType", "posType")
|
||||
.leftJoinAndSelect("profile.gender", "gender")
|
||||
.leftJoinAndSelect("profile.relationship", "relationship")
|
||||
.leftJoinAndSelect("profile.bloodGroup", "bloodGroup")
|
||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
||||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||
.select([
|
||||
"profile.id",
|
||||
"profile.prefix",
|
||||
"profile.firstName",
|
||||
"profile.lastName",
|
||||
"profile.citizenId",
|
||||
"profile.birthDate",
|
||||
"profile.isProbation",
|
||||
"profile.dateRetire",
|
||||
"profile.position",
|
||||
"posType.posTypeName",
|
||||
"posLevel.posLevelName",
|
||||
"current_holders.posMasterNo",
|
||||
// "orgRoot?.orgRootShortName",
|
||||
// "orgChild1?.orgRootShortName",
|
||||
// "orgChild2?.orgRootShortName",
|
||||
// "orgChild3?.orgRootShortName",
|
||||
// "orgChild4?.orgRootShortName",
|
||||
])
|
||||
.andWhere(
|
||||
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
|
||||
? queryLike
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${searchKeyword}%`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
posType != undefined && posType != null && posType != ""
|
||||
? "posType.posTypeName LIKE :keyword1"
|
||||
: "1=1",
|
||||
{
|
||||
keyword1: `${posType}`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
posLevel != undefined && posLevel != null && posLevel != ""
|
||||
? "posLevel.posLevelName LIKE :keyword2"
|
||||
: "1=1",
|
||||
{
|
||||
keyword2: `${posLevel}`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
isProbation != undefined && isProbation != null
|
||||
? `profile.isProbation = ${isProbation}`
|
||||
: "1=1",
|
||||
)
|
||||
.andWhere(
|
||||
isRetire != undefined && isRetire != null
|
||||
? isRetire == true
|
||||
? `profile.dateRetire IS null`
|
||||
: `profile.dateRetire IS NOT NULL`
|
||||
: "1=1",
|
||||
)
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const [record, total] = await this.profileRepo.findAndCount({
|
||||
relations: {
|
||||
posLevel: true,
|
||||
posType: true,
|
||||
gender: true,
|
||||
relationship: true,
|
||||
bloodGroup: true,
|
||||
},
|
||||
where:
|
||||
searchField && searchKeyword ? [{ [searchField]: Like(`%${searchKeyword}%`) }] : undefined,
|
||||
order: { createdAt: "ASC" },
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
});
|
||||
return new HttpSuccess({ data: record, total });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import { Gender } from "./Gender";
|
|||
import { Relationship } from "./Relationship";
|
||||
import { BloodGroup } from "./BloodGroup";
|
||||
import { Religion } from "./Religion";
|
||||
import { calculateRetireYear } from "../interfaces/utils";
|
||||
|
||||
@Entity("profile")
|
||||
export class Profile extends EntityBase {
|
||||
|
|
@ -126,6 +127,12 @@ export class Profile extends EntityBase {
|
|||
})
|
||||
isProbation: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "เกษียณ",
|
||||
default: false,
|
||||
})
|
||||
isLeave: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "datetime",
|
||||
|
|
@ -263,6 +270,10 @@ export class Profile extends EntityBase {
|
|||
@ManyToOne(() => PosType, (posType) => posType.profiles)
|
||||
@JoinColumn({ name: "posTypeId" })
|
||||
posType: PosType;
|
||||
|
||||
// calculateRetireYear(): number {
|
||||
// return calculateRetireYear(this.birthDate);
|
||||
// }
|
||||
}
|
||||
|
||||
@Entity("profileHistory")
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ export function calculateRetireDate(birthDate: Date) {
|
|||
if (dd >= 2) flag = false;
|
||||
break;
|
||||
case 11:
|
||||
break;
|
||||
case 12:
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -41,3 +41,25 @@ export function calculateRetireDate(birthDate: Date) {
|
|||
|
||||
return new Date(`${yy + 61}-09-30T00:00:00.000+07:00`);
|
||||
}
|
||||
|
||||
export function calculateRetireYear(birthDate: Date) {
|
||||
let dd = birthDate.getDate();
|
||||
let mm = birthDate.getMonth();
|
||||
let yy = birthDate.getFullYear();
|
||||
|
||||
let flag = true;
|
||||
|
||||
switch (mm) {
|
||||
case 10:
|
||||
if (dd >= 2) flag = false;
|
||||
break;
|
||||
case 11:
|
||||
break;
|
||||
case 12:
|
||||
break;
|
||||
}
|
||||
|
||||
if (flag) return yy + 60;
|
||||
|
||||
return yy + 61;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTableProfileAddIsLeave1711357767283 implements MigrationInterface {
|
||||
name = 'UpdateTableProfileAddIsLeave1711357767283'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`isLeave\` tinyint NOT NULL COMMENT 'เกษียณ' DEFAULT 0`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`isLeave\` tinyint NOT NULL COMMENT 'เกษียณ' DEFAULT 0`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`isLeave\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`isLeave\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue