report02
This commit is contained in:
parent
0598f8fd34
commit
efe434e6ac
1 changed files with 272 additions and 95 deletions
|
|
@ -1,100 +1,277 @@
|
||||||
import {
|
import {
|
||||||
Controller,
|
Controller,
|
||||||
Get,
|
Get,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Delete,
|
Delete,
|
||||||
Patch,
|
Patch,
|
||||||
Route,
|
Route,
|
||||||
Security,
|
Security,
|
||||||
Tags,
|
Tags,
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
Example,
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
Query,
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { In, IsNull, Not } from "typeorm";
|
import { In, IsNull, Not } from "typeorm";
|
||||||
import { Salarys } from "../entities/Salarys";
|
import { Salarys } from "../entities/Salarys";
|
||||||
import { SalaryRanks } from "../entities/SalaryRanks";
|
import { SalaryRanks } from "../entities/SalaryRanks";
|
||||||
import { PosType } from "../entities/PosType";
|
import { PosType } from "../entities/PosType";
|
||||||
import { PosLevel } from "../entities/PosLevel";
|
import { PosLevel } from "../entities/PosLevel";
|
||||||
import Extension from "../interfaces/extension";
|
import Extension from "../interfaces/extension";
|
||||||
import { SalaryPeriod } from "../entities/SalaryPeriod";
|
import { SalaryPeriod } from "../entities/SalaryPeriod";
|
||||||
import { SalaryProfile } from "../entities/SalaryProfile";
|
import { SalaryProfile } from "../entities/SalaryProfile";
|
||||||
@Route("api/v1/salary/report")
|
@Route("api/v1/salary/report")
|
||||||
@Tags("Report")
|
@Tags("Report")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
@Response(
|
@Response(
|
||||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
)
|
)
|
||||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
export class Report2Controller extends Controller {
|
export class Report2Controller extends Controller {
|
||||||
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
|
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
|
||||||
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
|
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
|
||||||
private salaryRepository = AppDataSource.getRepository(Salarys);
|
private salaryRepository = AppDataSource.getRepository(Salarys);
|
||||||
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
|
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
|
||||||
private poTypeRepository = AppDataSource.getRepository(PosType);
|
private poTypeRepository = AppDataSource.getRepository(PosType);
|
||||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||||
|
|
||||||
/**
|
|
||||||
* API รายชื่อข้าราชการผู้ที่ครองตำแหน่ง
|
|
||||||
*
|
|
||||||
* @summary รายชื่อข้าราชการผู้ที่ครองตำแหน่ง
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Post("report1")
|
|
||||||
async report1(@Body() body: { rootId: string; salaryPeriodId: string;}) {
|
|
||||||
const salaryPeriodAPR = await this.salaryProfileRepository.find({
|
|
||||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
|
||||||
where: {
|
|
||||||
salaryOrg:{
|
|
||||||
snapshot:"SNAP1",
|
|
||||||
rootId:body.rootId,
|
|
||||||
salaryPeriodId: body.salaryPeriodId,
|
|
||||||
salaryPeriod:{
|
|
||||||
period:"APR"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!salaryPeriodAPR) {
|
/**
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
* API รายชื่อข้าราชการผู้ที่ครองตำแหน่ง
|
||||||
}
|
*
|
||||||
|
* @summary รายชื่อข้าราชการผู้ที่ครองตำแหน่ง
|
||||||
const agency = salaryPeriodAPR[0]?.root;
|
*
|
||||||
|
*/
|
||||||
|
@Get("report1/{rootId}/{salaryPeriodId}")
|
||||||
|
async SalaryReport1(@Path() rootId: string, @Path() salaryPeriodId: string) {
|
||||||
|
const salaryPeriodAPR = await this.salaryProfileRepository.find({
|
||||||
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
where: {
|
||||||
|
salaryOrg: {
|
||||||
|
snapshot: "SNAP1",
|
||||||
|
rootId: rootId,
|
||||||
|
salaryPeriodId: salaryPeriodId,
|
||||||
|
salaryPeriod: {
|
||||||
|
period: "APR",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
orgShortName: "ASC",
|
||||||
|
posMasterNo: "ASC",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const formattedData = salaryPeriodAPR.map((profile, index) => {
|
if (!salaryPeriodAPR) {
|
||||||
const fullNameParts = [
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
profile?.child4,
|
|
||||||
profile?.child3,
|
|
||||||
profile?.child2,
|
|
||||||
profile?.child1,
|
|
||||||
profile?.root,
|
|
||||||
`${profile?.prefix}${profile?.firstName} ${profile?.lastName}`
|
|
||||||
];
|
|
||||||
|
|
||||||
const fullName = fullNameParts.filter(part => part !== undefined && part !== null).join('/');
|
|
||||||
|
|
||||||
return {
|
|
||||||
no: index + 1,
|
|
||||||
fullName: fullName?fullName:"",
|
|
||||||
posLevel: profile?.posLevel?profile?.posLevel:"",
|
|
||||||
posNumber: profile?.posMasterNo?profile?.posMasterNo:"",
|
|
||||||
amount: profile?.amount?profile?.amount:"",
|
|
||||||
reason: null,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return new HttpSuccess({ agency: agency, data: formattedData });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const agency = salaryPeriodAPR[0]?.root;
|
||||||
|
|
||||||
|
const formattedData = salaryPeriodAPR.map((profile, index) => {
|
||||||
|
const fullNameParts = [
|
||||||
|
profile?.child4,
|
||||||
|
profile?.child3,
|
||||||
|
profile?.child2,
|
||||||
|
profile?.child1,
|
||||||
|
profile?.root,
|
||||||
|
`${profile?.prefix}${profile?.firstName} ${profile?.lastName}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
const fullName = fullNameParts
|
||||||
|
.filter((part) => part !== undefined && part !== null)
|
||||||
|
.join("/");
|
||||||
|
|
||||||
|
return {
|
||||||
|
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
|
||||||
|
fullName: fullName ? fullName : null,
|
||||||
|
posLevel: profile?.posLevel ? profile?.posLevel : null,
|
||||||
|
posNumber:
|
||||||
|
profile?.orgShortName + profile?.posMasterNo
|
||||||
|
? profile?.orgShortName + Extension.ToThaiNumber(profile?.posMasterNo.toLocaleString())
|
||||||
|
: null,
|
||||||
|
amount: profile?.amount ? Extension.ToThaiNumber(profile?.amount.toLocaleString()) : null,
|
||||||
|
reason: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return { agency: agency, data: formattedData };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API การคำนวณโควตาการเลื่อนเงินเดือนข้าราชการ กรุงเทพมหานครสามัญ
|
||||||
|
*
|
||||||
|
* @summary การคำนวณโควตาการเลื่อนเงินเดือนข้าราชการ กรุงเทพมหานครสามัญ
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("report2/{rootId}/{salaryPeriodId}/{salaryOrgId}")
|
||||||
|
async SalaryReport2(@Path() rootId: string, @Path() salaryPeriodId: string, @Path() salaryOrgId: string) {
|
||||||
|
// const counts = await AppDataSource.getRepository(SalaryProfile)
|
||||||
|
// .createQueryBuilder("salaryProfile")
|
||||||
|
// .leftJoin("salaryProfile.salaryOrg", "salaryOrg")
|
||||||
|
// .leftJoin("salaryOrg.salaryPeriod", "salaryPeriod")
|
||||||
|
// .where({
|
||||||
|
// salaryOrg: {
|
||||||
|
// rootId: rootId,
|
||||||
|
// salaryPeriodId: salaryPeriodId,
|
||||||
|
// group: "GROUP2",
|
||||||
|
// snapshot: "SNAP1",
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .select([
|
||||||
|
// "COUNT(CASE WHEN salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ทักษะพิเศษ' THEN 1 END) AS count1",
|
||||||
|
// "COUNT(CASE WHEN salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'เชี่ยวชาญ' THEN 1 END) AS count2",
|
||||||
|
// "COUNT(CASE WHEN salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ทรงคุณวุฒิ' THEN 1 END) AS count3",
|
||||||
|
// "COUNT(CASE WHEN salaryProfile.posType = 'อำนวยการ' AND salaryProfile.posLevel = 'สูง' THEN 1 END) AS count4",
|
||||||
|
// "COUNT(CASE WHEN salaryProfile.posType = 'บริหาร' AND salaryProfile.posLevel = 'ต้น' THEN 1 END) AS count5",
|
||||||
|
// "COUNT(CASE WHEN salaryProfile.posType = 'บริหาร' AND salaryProfile.posLevel = 'สูง' THEN 1 END) AS count6",
|
||||||
|
// ])
|
||||||
|
// .getRawOne();
|
||||||
|
|
||||||
|
// const [data1,count1] = await this.salaryProfileRepository.findAndCount({
|
||||||
|
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
// where: {
|
||||||
|
// salaryOrg: {
|
||||||
|
// snapshot: "SNAP1",
|
||||||
|
// group: "GROUP2",
|
||||||
|
// rootId: rootId,
|
||||||
|
// salaryPeriodId: salaryPeriodId,
|
||||||
|
// salaryPeriod: {
|
||||||
|
// period: "APR",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// posType: "ทั่วไป",
|
||||||
|
// posLevel: "ทักษะพิเศษ",
|
||||||
|
// },
|
||||||
|
// select: ["posType", "posLevel"],
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const [data2,count2] = await this.salaryProfileRepository.findAndCount({
|
||||||
|
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
// where: {
|
||||||
|
// salaryOrg: {
|
||||||
|
// snapshot: "SNAP1",
|
||||||
|
// group: "GROUP2",
|
||||||
|
// rootId: rootId,
|
||||||
|
// salaryPeriodId: salaryPeriodId,
|
||||||
|
// salaryPeriod: {
|
||||||
|
// period: "APR",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// posType: "วิชาการ",
|
||||||
|
// posLevel: "เชี่ยวชาญ",
|
||||||
|
// },
|
||||||
|
// select: ["posType", "posLevel"],
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const [data3,count3] = await this.salaryProfileRepository.findAndCount({
|
||||||
|
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
// where: {
|
||||||
|
// salaryOrg: {
|
||||||
|
// snapshot: "SNAP1",
|
||||||
|
// group: "GROUP2",
|
||||||
|
// rootId: rootId,
|
||||||
|
// salaryPeriodId: salaryPeriodId,
|
||||||
|
// salaryPeriod: {
|
||||||
|
// period: "APR",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// posType: "วิชาการ",
|
||||||
|
// posLevel: "ทรงคุณวุฒิ",
|
||||||
|
// },
|
||||||
|
// select: ["posType", "posLevel"],
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const [data4,count4] = await this.salaryProfileRepository.findAndCount({
|
||||||
|
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
// where: {
|
||||||
|
// salaryOrg: {
|
||||||
|
// snapshot: "SNAP1",
|
||||||
|
// group: "GROUP2",
|
||||||
|
// rootId: rootId,
|
||||||
|
// salaryPeriodId: salaryPeriodId,
|
||||||
|
// salaryPeriod: {
|
||||||
|
// period: "APR",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// posType: "อำนวยการ",
|
||||||
|
// posLevel: "สูง",
|
||||||
|
// },
|
||||||
|
// select: ["posType", "posLevel"],
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const [data5,count5] = await this.salaryProfileRepository.findAndCount({
|
||||||
|
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
// where: {
|
||||||
|
// salaryOrg: {
|
||||||
|
// snapshot: "SNAP1",
|
||||||
|
// group: "GROUP2",
|
||||||
|
// rootId: rootId,
|
||||||
|
// salaryPeriodId: salaryPeriodId,
|
||||||
|
// salaryPeriod: {
|
||||||
|
// period: "APR",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// posType: "บริหาร",
|
||||||
|
// posLevel: "ต้น",
|
||||||
|
// },
|
||||||
|
// select: ["posType", "posLevel"],
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const [data6,count6] = await this.salaryProfileRepository.findAndCount({
|
||||||
|
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
// where: {
|
||||||
|
// salaryOrg: {
|
||||||
|
// snapshot: "SNAP1",
|
||||||
|
// group: "GROUP2",
|
||||||
|
// rootId: rootId,
|
||||||
|
// salaryPeriodId: salaryPeriodId,
|
||||||
|
// salaryPeriod: {
|
||||||
|
// period: "APR",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// posType: "บริหาร",
|
||||||
|
// posLevel: "สูง",
|
||||||
|
// },
|
||||||
|
// select: ["posType", "posLevel"],
|
||||||
|
// });
|
||||||
|
|
||||||
|
const statistics = await this.salaryProfileRepository.find({
|
||||||
|
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||||
|
where: {
|
||||||
|
salaryOrg: {
|
||||||
|
id:salaryOrgId,
|
||||||
|
snapshot: "SNAP1",
|
||||||
|
group: "GROUP2",
|
||||||
|
rootId: rootId,
|
||||||
|
salaryPeriod: {
|
||||||
|
id: salaryPeriodId,
|
||||||
|
period: "APR",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const notPromoSum = (statistics[0]?.salaryOrg?.total ?? 0) - (statistics[0]?.salaryOrg?.fifteenPercent ?? 0);
|
||||||
|
const haftCount = statistics?.filter(item => item.type === "HAFT").length ?? 0;
|
||||||
|
const data = {
|
||||||
|
group: statistics[0]?.salaryOrg.total?"กลุ่ม 2":"",
|
||||||
|
total: statistics[0]?.salaryOrg.total?statistics[0]?.salaryOrg.total:"",
|
||||||
|
fifteenPercent: statistics[0]?.salaryOrg.fifteenPercent?statistics[0]?.salaryOrg.fifteenPercent:"",
|
||||||
|
full: statistics[0]?.salaryOrg.quantityUsed?statistics[0]?.salaryOrg.quantityUsed:"",
|
||||||
|
remaining: statistics[0]?.salaryOrg.remainQuota?statistics[0]?.salaryOrg.remainQuota:"",
|
||||||
|
haft: haftCount,
|
||||||
|
notPromoted: notPromoSum,
|
||||||
|
reason: null,
|
||||||
|
};
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue