โครงการเพิ่มค้นหาหน่วยงาน

This commit is contained in:
Kittapath 2024-04-17 22:34:21 +07:00
parent 281a8515ba
commit ddc0e85e3e
5 changed files with 297 additions and 103 deletions

View file

@ -110,6 +110,29 @@ export class DevelopmentController extends Controller {
); );
} }
const development = Object.assign(new Development(), requestBody); const development = Object.assign(new Development(), requestBody);
await new CallAPI()
.PostData(request, "org/find/all", {
node: requestBody.node,
nodeId: requestBody.nodeId,
})
.then((x) => {
development.root = x.root;
development.rootId = x.rootId;
development.rootShortName = x.rootShortName;
development.child1 = x.child1;
development.child1Id = x.child1Id;
development.child1ShortName = x.child1ShortName;
development.child2 = x.child2;
development.child2Id = x.child2Id;
development.child2ShortName = x.child2ShortName;
development.child3 = x.child3;
development.child3Id = x.child3Id;
development.child3ShortName = x.child3ShortName;
development.child4 = x.child4;
development.child4Id = x.child4Id;
development.child4ShortName = x.child4ShortName;
})
.catch((x) => {});
development.createdUserId = request.user.sub; development.createdUserId = request.user.sub;
development.createdFullName = request.user.name; development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub; development.lastUpdateUserId = request.user.sub;
@ -155,6 +178,29 @@ export class DevelopmentController extends Controller {
); );
} }
Object.assign(development, requestBody); Object.assign(development, requestBody);
await new CallAPI()
.PostData(request, "org/find/all", {
node: requestBody.node,
nodeId: requestBody.nodeId,
})
.then((x) => {
development.root = x.root;
development.rootId = x.rootId;
development.rootShortName = x.rootShortName;
development.child1 = x.child1;
development.child1Id = x.child1Id;
development.child1ShortName = x.child1ShortName;
development.child2 = x.child2;
development.child2Id = x.child2Id;
development.child2ShortName = x.child2ShortName;
development.child3 = x.child3;
development.child3Id = x.child3Id;
development.child3ShortName = x.child3ShortName;
development.child4 = x.child4;
development.child4Id = x.child4Id;
development.child4ShortName = x.child4ShortName;
})
.catch((x) => {});
development.lastUpdateUserId = request.user.sub; development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name; development.lastUpdateFullName = request.user.name;
await this.developmentRepository.save(development); await this.developmentRepository.save(development);
@ -1122,7 +1168,8 @@ export class DevelopmentController extends Controller {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("year") year: number, @Query("year") year: number,
@Query("status") status: string, @Query("status") status: string,
@Query("root") root?: string | null, @Query("nodeId") nodeId?: string | null,
@Query("node") node?: number | null,
@Query("keyword") keyword?: string, @Query("keyword") keyword?: string,
) { ) {
const [development, total] = await AppDataSource.getRepository(Development) const [development, total] = await AppDataSource.getRepository(Development)
@ -1130,16 +1177,38 @@ export class DevelopmentController extends Controller {
.andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", {
year: `${year.toString()}`, year: `${year.toString()}`,
}) })
.andWhere(root != undefined && root != null ? "development.root LIKE :root" : "1=1", { .andWhere(
root: `${root}`, node != undefined && node != null
}) ? node == 4
? "development.child4Id LIKE :nodeId"
: node == 3
? "development.child3Id LIKE :nodeId"
: node == 2
? "development.child2Id LIKE :nodeId"
: node == 1
? "development.child1Id LIKE :nodeId"
: "development.rootId LIKE :nodeId"
: "1=1",
{
nodeId: `${nodeId}`,
},
)
.andWhere(status != undefined ? "development.status LIKE :status" : "1=1", { .andWhere(status != undefined ? "development.status LIKE :status" : "1=1", {
status: `%${status}%`, status: `%${status}%`,
}) })
.andWhere(keyword != undefined ? "development.projectName LIKE :keyword" : "1=1", { .andWhere(keyword != undefined ? "development.projectName LIKE :keyword" : "1=1", {
keyword: `%${keyword}%`, keyword: `%${keyword}%`,
}) })
.select(["development.id", "development.projectName", "development.year", "development.root"]) .select([
"development.id",
"development.projectName",
"development.year",
"development.root",
"development.child1",
"development.child2",
"development.child3",
"development.child4",
])
.orderBy("development.year", "DESC") .orderBy("development.year", "DESC")
.orderBy("development.createdAt", "DESC") .orderBy("development.createdAt", "DESC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
@ -1201,22 +1270,39 @@ export class DevelopmentController extends Controller {
async GetDevelopemtTab1ById(@Path() id: string) { async GetDevelopemtTab1ById(@Path() id: string) {
const getDevelopment = await this.developmentRepository.findOne({ const getDevelopment = await this.developmentRepository.findOne({
where: { id: id }, where: { id: id },
select: [
"id",
"year",
"projectName",
"reason",
"objective",
"root",
"rootId",
"orgRootShortName",
"orgRevisionId",
],
}); });
if (!getDevelopment) { if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
} }
return new HttpSuccess(getDevelopment); let node = null;
let nodeId = null;
if (getDevelopment.child4Id != null) {
node = 4;
nodeId = getDevelopment.child4Id;
} else if (getDevelopment.child3Id != null) {
node = 3;
nodeId = getDevelopment.child3Id;
} else if (getDevelopment.child2Id != null) {
node = 2;
nodeId = getDevelopment.child2Id;
} else if (getDevelopment.child1Id != null) {
node = 1;
nodeId = getDevelopment.child1Id;
} else if (getDevelopment.rootId != null) {
node = 0;
nodeId = getDevelopment.rootId;
}
const formattedData = {
id: getDevelopment.id,
year: getDevelopment.year,
projectName: getDevelopment.projectName,
reason: getDevelopment.reason,
objective: getDevelopment.objective,
node: node,
nodeId: nodeId,
};
return new HttpSuccess(formattedData);
} }
/** /**

View file

@ -345,45 +345,40 @@ export class DevelopmentEmployeeHistoryController extends Controller {
} }
const formattedData = { const formattedData = {
rank: getDevelopment.rank ? getDevelopment.rank : null, rank: getDevelopment.rank,
prefix: getDevelopment.prefix ? getDevelopment.prefix : null, org: getDevelopment.org,
firstName: getDevelopment.firstName ? getDevelopment.firstName : null, prefix: getDevelopment.prefix,
lastName: getDevelopment.lastName ? getDevelopment.lastName : null, firstName: getDevelopment.firstName,
citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, lastName: getDevelopment.lastName,
position: getDevelopment.position ? getDevelopment.position : null, citizenId: getDevelopment.citizenId,
posLevelId: getDevelopment.employeePosLevelId ? getDevelopment.employeePosLevelId : null, position: getDevelopment.position,
posLevelName: getDevelopment.employeePosLevel.posLevelName posLevelId: getDevelopment.employeePosLevelId,
? getDevelopment.employeePosLevel.posLevelName posLevelName:
: null, getDevelopment.employeePosLevel != null
posTypeId: getDevelopment.employeePosTypeId ? getDevelopment.employeePosTypeId : null, ? getDevelopment.employeePosLevel.posLevelName
posTypeName: getDevelopment.employeePosType.posTypeName : null,
? getDevelopment.employeePosType.posTypeName posTypeId: getDevelopment.employeePosTypeId,
: null, posTypeName:
developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, getDevelopment.employeePosType != null ? getDevelopment.employeePosType.posTypeName : null,
order: getDevelopment.order ? getDevelopment.order : null, developmentId: getDevelopment.developmentId,
dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, order: getDevelopment.order,
dateHisStart: getDevelopment.dateStart ? getDevelopment.dateStart : null, dateOrder: getDevelopment.dateOrder,
dateHisEnd: getDevelopment.dateEnd ? getDevelopment.dateEnd : null, dateHisStart: getDevelopment.dateStart,
year: getDevelopment.development.year ? getDevelopment.development.year : null, dateHisEnd: getDevelopment.dateEnd,
projectName: getDevelopment.development.projectName year: getDevelopment.development != null ? getDevelopment.development.year : null,
? getDevelopment.development.projectName projectName:
: null, getDevelopment.development != null ? getDevelopment.development.projectName : null,
dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null, dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null,
dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null, dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null,
totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null,
addressAcademic: getDevelopment.development.addressAcademic addressAcademic:
? getDevelopment.development.addressAcademic getDevelopment.development != null ? getDevelopment.development.addressAcademic : null,
: null, topicAcademic:
topicAcademic: getDevelopment.development.topicAcademic getDevelopment.development != null ? getDevelopment.development.topicAcademic : null,
? getDevelopment.development.topicAcademic dateStudyStart:
: null, getDevelopment.development != null ? getDevelopment.development.dateStudyStart : null,
dateStudyStart: getDevelopment.development.dateStudyStart dateStudyEnd:
? getDevelopment.development.dateStudyStart getDevelopment.development != null ? getDevelopment.development.dateStudyEnd : null,
: null,
dateStudyEnd: getDevelopment.development.dateStudyEnd
? getDevelopment.development.dateStudyEnd
: null,
org: null,
}; };
return new HttpSuccess(formattedData); return new HttpSuccess(formattedData);

View file

@ -340,44 +340,37 @@ export class DevelopmentOfficerHistoryController extends Controller {
} }
const formattedData = { const formattedData = {
rank: getDevelopment.rank ? getDevelopment.rank : null, rank: getDevelopment.rank,
prefix: getDevelopment.prefix ? getDevelopment.prefix : null, org: getDevelopment.org,
firstName: getDevelopment.firstName ? getDevelopment.firstName : null, prefix: getDevelopment.prefix,
lastName: getDevelopment.lastName ? getDevelopment.lastName : null, firstName: getDevelopment.firstName,
citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, lastName: getDevelopment.lastName,
position: getDevelopment.position ? getDevelopment.position : null, citizenId: getDevelopment.citizenId,
posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, position: getDevelopment.position,
posLevelName: getDevelopment.posLevel.posLevelName posLevelId: getDevelopment.posLevelId,
? getDevelopment.posLevel.posLevelName posLevelName: getDevelopment.posLevel != null ? getDevelopment.posLevel.posLevelName : null,
: null, posTypeId: getDevelopment.posTypeId,
posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, posTypeName: getDevelopment.posType != null ? getDevelopment.posType.posTypeName : null,
posTypeName: getDevelopment.posType.posTypeName ? getDevelopment.posType.posTypeName : null, posExecutive: getDevelopment.posExecutive,
posExecutive: getDevelopment.posExecutive ? getDevelopment.posExecutive : null, developmentId: getDevelopment.developmentId,
developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, order: getDevelopment.order,
order: getDevelopment.order ? getDevelopment.order : null, dateOrder: getDevelopment.dateOrder,
dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, dateHisStart: getDevelopment.dateStart,
dateHisStart: getDevelopment.dateStart ? getDevelopment.dateStart : null, dateHisEnd: getDevelopment.dateEnd,
dateHisEnd: getDevelopment.dateEnd ? getDevelopment.dateEnd : null, year: getDevelopment.development != null ? getDevelopment.development.year : null,
year: getDevelopment.development.year ? getDevelopment.development.year : null, projectName:
projectName: getDevelopment.development.projectName getDevelopment.development != null ? getDevelopment.development.projectName : null,
? getDevelopment.development.projectName dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null,
: null, dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null,
dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null, totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null,
dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null, addressAcademic:
totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, getDevelopment.development != null ? getDevelopment.development.addressAcademic : null,
addressAcademic: getDevelopment.development.addressAcademic topicAcademic:
? getDevelopment.development.addressAcademic getDevelopment.development != null ? getDevelopment.development.topicAcademic : null,
: null, dateStudyStart:
topicAcademic: getDevelopment.development.topicAcademic getDevelopment.development != null ? getDevelopment.development.dateStudyStart : null,
? getDevelopment.development.topicAcademic dateStudyEnd:
: null, getDevelopment.development != null ? getDevelopment.development.dateStudyEnd : null,
dateStudyStart: getDevelopment.development.dateStudyStart
? getDevelopment.development.dateStudyStart
: null,
dateStudyEnd: getDevelopment.development.dateStudyEnd
? getDevelopment.development.dateStudyEnd
: null,
org: null,
}; };
return new HttpSuccess(formattedData); return new HttpSuccess(formattedData);

View file

@ -38,7 +38,91 @@ export class Development extends EntityBase {
comment: "ชื่อย่อหน่วยงาน", comment: "ชื่อย่อหน่วยงาน",
default: null, default: null,
}) })
orgRootShortName: string; rootShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child1",
default: null,
})
child1Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child1",
default: null,
})
child1: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child1",
default: null,
})
child1ShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child2",
default: null,
})
child2Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child2",
default: null,
})
child2: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child2",
default: null,
})
child2ShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child3",
default: null,
})
child3Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child3",
default: null,
})
child3: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child3",
default: null,
})
child3ShortName: string;
@Column({
nullable: true,
comment: "id หน่วยงาน child4",
default: null,
})
child4Id: string;
@Column({
nullable: true,
comment: "ชื่อหน่วยงาน child4",
default: null,
})
child4: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน child4",
default: null,
})
child4ShortName: string;
@Column({ @Column({
nullable: true, nullable: true,
@ -531,11 +615,9 @@ export class CreateDevelopment {
@Column() @Column()
projectName: string; projectName: string;
@Column() @Column()
root: string; node: number;
@Column() @Column()
rootId: string; nodeId: string;
@Column()
orgRootShortName: string;
@Column() @Column()
orgRevisionId: string; orgRevisionId: string;
} }
@ -550,11 +632,9 @@ export class UpdateDevelopment1 {
@Column() @Column()
objective: string | null; objective: string | null;
@Column() @Column()
root: string; node: number;
@Column() @Column()
rootId: string; nodeId: string;
@Column()
orgRootShortName: string;
@Column() @Column()
orgRevisionId: string; orgRevisionId: string;
@Column() @Column()

View file

@ -0,0 +1,40 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableDevAddChild11713366798329 implements MigrationInterface {
name = 'UpdateTableDevAddChild11713366798329'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`orgRootShortName\``);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`rootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child1Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child1'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child1\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child1'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child1ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child1'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child2Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child2'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child2\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child2'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child2ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child2'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child3Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child3'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child3\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child3'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child3ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child3'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child4Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child4'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child4\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child4'`);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`child4ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child4'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child4ShortName\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child4\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child4Id\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child3ShortName\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child3\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child3Id\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child2ShortName\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child2\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child2Id\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child1ShortName\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child1\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child1Id\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`rootShortName\``);
await queryRunner.query(`ALTER TABLE \`development\` ADD \`orgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน'`);
}
}