Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-04-17 10:21:32 +07:00
commit bee26f07a9
26 changed files with 2236 additions and 281 deletions

File diff suppressed because it is too large Load diff

View file

@ -185,6 +185,7 @@ export class DevelopmentOfficerHistoryController extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
@Query("year") year?: number,
@Query("root") root?: number,
) {
const type = "OFFICER";
const [development, total] = await AppDataSource.getRepository(DevelopmentHistory)
@ -192,14 +193,18 @@ export class DevelopmentOfficerHistoryController extends Controller {
.leftJoinAndSelect("developmentHistory.development", "development")
.leftJoinAndSelect("developmentHistory.posLevel", "posLevel")
.leftJoinAndSelect("developmentHistory.posType", "posType")
.andWhere(year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", { year: year })
.andWhere(
year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1",
{ year: year },
)
.andWhere(root != null && root != undefined ? "development.root = :root" : "1=1", {
root: root,
})
.andWhere("developmentHistory.type = :type", { type: type })
.andWhere(
new Brackets((qb) => {
qb.where(
keyword != null && keyword != ""
? "developmentHistory.prefix LIKE :keyword"
: "1=1",
keyword != null && keyword != "" ? "developmentHistory.prefix LIKE :keyword" : "1=1",
{
keyword: `%${keyword}%`,
},
@ -237,25 +242,19 @@ export class DevelopmentOfficerHistoryController extends Controller {
},
)
.orWhere(
keyword != null && keyword != ""
? "development.projectName LIKE :keyword"
: "1=1",
keyword != null && keyword != "" ? "development.projectName LIKE :keyword" : "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "posType.posTypeName LIKE :keyword"
: "1=1",
keyword != null && keyword != "" ? "posType.posTypeName LIKE :keyword" : "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "posLevel.posLevelName LIKE :keyword"
: "1=1",
keyword != null && keyword != "" ? "posLevel.posLevelName LIKE :keyword" : "1=1",
{
keyword: `%${keyword}%`,
},
@ -266,10 +265,10 @@ export class DevelopmentOfficerHistoryController extends Controller {
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const formattedData = development.map(item => ({
const formattedData = development.map((item) => ({
id: item.id,
citizenId: item.citizenId,
fullName: item.prefix+item.firstName+" "+item.lastName,
fullName: item.prefix + item.firstName + " " + item.lastName,
position: item.position,
posType: item.posType ? item.posType.posTypeName : null,
posLevel: item.posLevel ? item.posLevel.posLevelName : null,
@ -287,11 +286,11 @@ export class DevelopmentOfficerHistoryController extends Controller {
*
* @param {string} id Id
*/
@Get("{id}")
@Get("{id}")
async GetDevelopemtHistoryById(@Path() id: string) {
const type = "OFFICER";
const getDevelopment = await this.developmentHistoryRepository.findOne({
relations: ["development","posLevel","posType"],
relations: ["development", "posLevel", "posType"],
where: { id: id, type: type },
});
if (!getDevelopment) {
@ -306,7 +305,9 @@ export class DevelopmentOfficerHistoryController extends Controller {
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,
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,
@ -314,17 +315,27 @@ export class DevelopmentOfficerHistoryController extends Controller {
order: getDevelopment.order ? getDevelopment.order : null,
dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null,
year: getDevelopment.development.year ? getDevelopment.development.year : null,
projectName: getDevelopment.development.projectName ? getDevelopment.development.projectName : 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,
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,
};
return new HttpSuccess(formattedData);
}
}

View file

@ -21,6 +21,7 @@ import {
CreateDevelopmentScholarship,
DevelopmentScholarship,
UpdateDevelopmentScholarship,
UpdateDevelopmentScholarshipUser,
} from "../entities/DevelopmentScholarship";
import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
@ -237,6 +238,7 @@ export class DevelopmentScholarshipController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
}
const formattedData = {
root: getDevelopment.root ? getDevelopment.root : null,
rank: getDevelopment.rank ? getDevelopment.rank : null,
prefix: getDevelopment.prefix ? getDevelopment.prefix : null,
firstName: getDevelopment.firstName ? getDevelopment.firstName : null,
@ -314,10 +316,92 @@ export class DevelopmentScholarshipController extends Controller {
totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null,
status: getDevelopment.status ? getDevelopment.status : null,
profileId: getDevelopment.profileId ? getDevelopment.profileId : null,
planType: getDevelopment.planType ? getDevelopment.planType : null,
isNoUseBudget: getDevelopment.isNoUseBudget ? getDevelopment.isNoUseBudget : null,
};
return new HttpSuccess(formattedData);
}
/**
* API user
*
* @summary DEV_0 - user #
*
* @param {string} profileId profileId
*/
@Get("user/{profileId}")
async GetDevelopemtScholarshipUserById(@Path() profileId: string) {
const getDevelopment = await this.developmentScholarshipRepository.find({
where: { profileId: profileId },
});
const formattedData = getDevelopment.map((item) => ({
id: item.id,
scholarshipYear: item.scholarshipYear,
scholarshipType: item.scholarshipType,
fundType: item.fundType,
}));
return new HttpSuccess(formattedData);
}
/**
* API user
*
* @summary DEV_0 - user #
*
* @param {string} id id
*/
@Get("user/detail/{id}")
async GetDevelopemtScholarshipUserDetailById(@Path() id: string) {
const getDevelopment = await this.developmentScholarshipRepository.findOne({
where: { id: id },
select: [
"id",
"scholarshipYear",
"scholarshipType",
"fundType",
"governmentDate",
"isGraduated",
"graduatedDate",
"isNoGraduated",
"graduatedReason",
"root",
],
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
}
return new HttpSuccess(getDevelopment);
}
/**
* API user
*
* @summary DEV_015 - user #15
*
* @param {string} id
*/
@Put("user/detail/{id}")
async UpdateDevelopemtScholarshipUserById(
@Path() id: string,
@Body() requestBody: UpdateDevelopmentScholarshipUser,
@Request() request: { user: Record<string, any> },
) {
const getDevelopment = await this.developmentScholarshipRepository.findOne({
where: { id: id },
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
}
Object.assign(getDevelopment, requestBody);
getDevelopment.lastUpdateUserId = request.user.sub;
getDevelopment.lastUpdateFullName = request.user.name;
await this.developmentScholarshipRepository.save(getDevelopment);
return new HttpSuccess(getDevelopment.id);
}
/**
* API
*
@ -340,6 +424,8 @@ export class DevelopmentScholarshipController extends Controller {
}
const _status = status.trim().toUpperCase();
getDevelopment.status = _status;
getDevelopment.lastUpdateUserId = request.user.sub;
getDevelopment.lastUpdateFullName = request.user.name;
if (_status == "GRADUATE") {
if (getDevelopment.scholarshipType != null) {
switch (getDevelopment.scholarshipType.trim().toUpperCase()) {

View file

@ -25,7 +25,8 @@ import {
} from "../entities/DevelopmentHistory";
import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
import Extension from "../interfaces/extension";
import { DevelopmentScholarship } from "../entities/DevelopmentScholarship";
@Route("api/v1/development/report")
@Tags("Report")
@Security("bearerAuth")
@ -34,6 +35,7 @@ export class ReportController extends Controller {
private developmentRepository = AppDataSource.getRepository(Development);
private posTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship);
/**
* API Report /
@ -63,18 +65,58 @@ export class ReportController extends Controller {
*
* @summary DEV_0xx - Report / #xx
*
* @param {string} type type report
*/
@Get("history-officer/{type}")
async GetReportDevelopemtHistoryOfficer(@Path() type: string) {
const _type = type.trim().toUpperCase();
const formattedData = {
org: _type,
};
@Post("history-officer")
async PostReportDevelopemtHistoryOfficer(
@Body()
body: {
year: number;
root: string;
},
) {
const development = await AppDataSource.getRepository(DevelopmentHistory)
.createQueryBuilder("developmentHistory")
.leftJoinAndSelect("developmentHistory.posLevel", "posLevel")
.leftJoinAndSelect("developmentHistory.posType", "posType")
.leftJoinAndSelect("developmentHistory.development", "development")
.andWhere(body.year != 0 && body.year != null ? "development.year = :year" : "1=1", {
year: body.year,
})
.andWhere(body.root != null ? "development.root = :root" : "1=1", {
root: body.root,
})
.andWhere("developmentHistory.type = :type", { type: "OFFICER" })
.select([
"developmentHistory.citizenId",
"developmentHistory.rank",
"developmentHistory.position",
"developmentHistory.posExecutive",
"developmentHistory.developmentId",
"developmentHistory.prefix",
"developmentHistory.firstName",
"developmentHistory.lastName",
"posLevel.posLevelName",
"posType.posTypeName",
"development.projectName",
"development.root",
])
.getMany();
const formattedData = development.map((item) => ({
id: item.id,
citizenId: Extension.ToThaiNumber(item.citizenId.toString()),
fullName: item.prefix + item.firstName + " " + item.lastName,
position: item.position,
posType: item.posType ? item.posType.posTypeName : null,
posLevel: item.posLevel ? item.posLevel.posLevelName : null,
posExecutive: item.posExecutive,
projectName: item.development ? item.development.projectName : null,
root: item.root,
}));
return new HttpSuccess({
template: "development",
reportName: "development",
template: "developmentHistoryOfficer",
reportName: "developmentHistoryOfficer",
data: {
data: formattedData,
},
@ -86,18 +128,60 @@ export class ReportController extends Controller {
*
* @summary DEV_0xx - Report / #xx
*
* @param {string} type type report
* @param {number} year year report
*/
@Get("history-employee/{type}")
async GetReportDevelopemtHistoryEmployee(@Path() type: string) {
const _type = type.trim().toUpperCase();
const formattedData = {
org: _type,
};
@Post("history-employee")
async PostReportDevelopemtHistoryEmployee(
@Body()
body: {
year: number;
root: string;
},
) {
const development = await AppDataSource.getRepository(DevelopmentHistory)
.createQueryBuilder("developmentHistory")
.leftJoinAndSelect("developmentHistory.employeePosLevel", "employeePosLevel")
.leftJoinAndSelect("developmentHistory.employeePosType", "employeePosType")
.leftJoinAndSelect("developmentHistory.development", "development")
.andWhere(body.year != 0 && body.year != null ? "development.year = :year" : "1=1", {
year: body.year,
})
.andWhere(body.root != null ? "development.root = :root" : "1=1", {
root: body.root,
})
.andWhere("developmentHistory.type = :type", { type: "EMPLOYEE" })
.select([
"developmentHistory.citizenId",
"developmentHistory.position",
"developmentHistory.developmentId",
"developmentHistory.prefix",
"developmentHistory.firstName",
"developmentHistory.lastName",
"employeePosLevel.posLevelName",
"employeePosType.posTypeName",
"employeePosType.posTypeShortName",
"development.projectName",
"development.root",
])
.getMany();
const formattedData = development.map((item) => ({
id: item.id,
citizenId: Extension.ToThaiNumber(item.citizenId.toString()),
fullName: item.prefix + item.firstName + " " + item.lastName,
position: item.position,
employeePosType: item.employeePosType ? item.employeePosType.posTypeName : null,
employeePosLevel:
item.employeePosType.posTypeShortName +
" " +
Extension.ToThaiNumber(item.employeePosLevel.posLevelName.toString()),
projectName: item.development ? item.development.projectName : null,
root: item.root,
}));
return new HttpSuccess({
template: "development",
reportName: "development",
template: "developmentHistoryEmployee",
reportName: "developmentHistoryEmployee",
data: {
data: formattedData,
},
@ -124,4 +208,86 @@ export class ReportController extends Controller {
},
});
}
/**
* API Report / detail
*
* @summary DEV_0xx - Report / detail #xx
*
* @param {string} id Id scholarship
*/
@Get("scholarship/{id}")
async GetReportDevelopemtScholarshipDetail(@Path() id: string) {
const getDevelopment = await this.developmentScholarshipRepository.findOne({
where: { id: id },
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
}
if (getDevelopment.scholarshipType != null) {
switch (getDevelopment.scholarshipType.trim().toUpperCase()) {
case "DOMESTICE":
getDevelopment.scholarshipType = "การศึกษาในประเทศ";
break;
case "NOABROAD":
getDevelopment.scholarshipType =
"ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)";
break;
case "ABROAD":
getDevelopment.scholarshipType =
"ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)";
break;
case "EXECUTIVE":
getDevelopment.scholarshipType =
"ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)";
break;
default:
break;
}
}
const formattedData = {
id: getDevelopment.id,
firstName: getDevelopment.firstName,
lastName: getDevelopment.lastName,
position: getDevelopment.position,
root: getDevelopment.root,
degreeLevel: getDevelopment.degreeLevel,
course: getDevelopment.course,
field: getDevelopment.field,
studyPlace: getDevelopment.studyPlace,
scholarshipType: getDevelopment.scholarshipType,
startDate:
getDevelopment.startDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.startDate)),
endDate:
getDevelopment.endDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.endDate)),
reportBackNo:
getDevelopment.reportBackNo == null
? ""
: Extension.ToThaiNumber(getDevelopment.reportBackNo),
reportBackNoDate:
getDevelopment.reportBackNoDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.reportBackNoDate)),
governmentDate:
getDevelopment.governmentDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.governmentDate)),
graduatedDate:
getDevelopment.graduatedDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.graduatedDate)),
graduatedReason: getDevelopment.graduatedReason,
};
return new HttpSuccess({
template: "repatriation",
reportName: "repatriation",
data: formattedData,
});
}
}