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

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);
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.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
@ -155,6 +178,29 @@ export class DevelopmentController extends Controller {
);
}
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.lastUpdateFullName = request.user.name;
await this.developmentRepository.save(development);
@ -1122,7 +1168,8 @@ export class DevelopmentController extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query("year") year: number,
@Query("status") status: string,
@Query("root") root?: string | null,
@Query("nodeId") nodeId?: string | null,
@Query("node") node?: number | null,
@Query("keyword") keyword?: string,
) {
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", {
year: `${year.toString()}`,
})
.andWhere(root != undefined && root != null ? "development.root LIKE :root" : "1=1", {
root: `${root}`,
})
.andWhere(
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", {
status: `%${status}%`,
})
.andWhere(keyword != undefined ? "development.projectName LIKE :keyword" : "1=1", {
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.createdAt", "DESC")
.skip((page - 1) * pageSize)
@ -1201,22 +1270,39 @@ export class DevelopmentController extends Controller {
async GetDevelopemtTab1ById(@Path() id: string) {
const getDevelopment = await this.developmentRepository.findOne({
where: { id: id },
select: [
"id",
"year",
"projectName",
"reason",
"objective",
"root",
"rootId",
"orgRootShortName",
"orgRevisionId",
],
});
if (!getDevelopment) {
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 = {
rank: getDevelopment.rank ? getDevelopment.rank : null,
prefix: getDevelopment.prefix ? getDevelopment.prefix : null,
firstName: getDevelopment.firstName ? getDevelopment.firstName : null,
lastName: getDevelopment.lastName ? getDevelopment.lastName : null,
citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null,
position: getDevelopment.position ? getDevelopment.position : null,
posLevelId: getDevelopment.employeePosLevelId ? getDevelopment.employeePosLevelId : null,
posLevelName: getDevelopment.employeePosLevel.posLevelName
? getDevelopment.employeePosLevel.posLevelName
: null,
posTypeId: getDevelopment.employeePosTypeId ? getDevelopment.employeePosTypeId : null,
posTypeName: getDevelopment.employeePosType.posTypeName
? getDevelopment.employeePosType.posTypeName
: null,
developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null,
order: getDevelopment.order ? getDevelopment.order : null,
dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null,
dateHisStart: getDevelopment.dateStart ? getDevelopment.dateStart : null,
dateHisEnd: getDevelopment.dateEnd ? getDevelopment.dateEnd : null,
year: getDevelopment.development.year ? getDevelopment.development.year : null,
projectName: getDevelopment.development.projectName
? getDevelopment.development.projectName
: null,
dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null,
dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null,
totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null,
addressAcademic: getDevelopment.development.addressAcademic
? getDevelopment.development.addressAcademic
: null,
topicAcademic: getDevelopment.development.topicAcademic
? getDevelopment.development.topicAcademic
: null,
dateStudyStart: getDevelopment.development.dateStudyStart
? getDevelopment.development.dateStudyStart
: null,
dateStudyEnd: getDevelopment.development.dateStudyEnd
? getDevelopment.development.dateStudyEnd
: null,
org: null,
rank: getDevelopment.rank,
org: getDevelopment.org,
prefix: getDevelopment.prefix,
firstName: getDevelopment.firstName,
lastName: getDevelopment.lastName,
citizenId: getDevelopment.citizenId,
position: getDevelopment.position,
posLevelId: getDevelopment.employeePosLevelId,
posLevelName:
getDevelopment.employeePosLevel != null
? getDevelopment.employeePosLevel.posLevelName
: null,
posTypeId: getDevelopment.employeePosTypeId,
posTypeName:
getDevelopment.employeePosType != null ? getDevelopment.employeePosType.posTypeName : null,
developmentId: getDevelopment.developmentId,
order: getDevelopment.order,
dateOrder: getDevelopment.dateOrder,
dateHisStart: getDevelopment.dateStart,
dateHisEnd: getDevelopment.dateEnd,
year: getDevelopment.development != null ? getDevelopment.development.year : null,
projectName:
getDevelopment.development != null ? getDevelopment.development.projectName : null,
dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null,
dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null,
totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null,
addressAcademic:
getDevelopment.development != null ? getDevelopment.development.addressAcademic : null,
topicAcademic:
getDevelopment.development != null ? getDevelopment.development.topicAcademic : null,
dateStudyStart:
getDevelopment.development != null ? getDevelopment.development.dateStudyStart : null,
dateStudyEnd:
getDevelopment.development != null ? getDevelopment.development.dateStudyEnd : null,
};
return new HttpSuccess(formattedData);

View file

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

View file

@ -38,7 +38,91 @@ export class Development extends EntityBase {
comment: "ชื่อย่อหน่วยงาน",
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({
nullable: true,
@ -531,11 +615,9 @@ export class CreateDevelopment {
@Column()
projectName: string;
@Column()
root: string;
node: number;
@Column()
rootId: string;
@Column()
orgRootShortName: string;
nodeId: string;
@Column()
orgRevisionId: string;
}
@ -550,11 +632,9 @@ export class UpdateDevelopment1 {
@Column()
objective: string | null;
@Column()
root: string;
node: number;
@Column()
rootId: string;
@Column()
orgRootShortName: string;
nodeId: string;
@Column()
orgRevisionId: string;
@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 'ชื่อย่อหน่วยงาน'`);
}
}