update report4

This commit is contained in:
Bright 2024-11-19 11:45:10 +07:00
parent 8f0624d27b
commit ab07e0485f

View file

@ -10,6 +10,8 @@ import { OrgChild1 } from "../entities/OrgChild1";
import { OrgChild2 } from "../entities/OrgChild2"; import { OrgChild2 } from "../entities/OrgChild2";
import { OrgChild3 } from "../entities/OrgChild3"; import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4"; import { OrgChild4 } from "../entities/OrgChild4";
import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
@Route("api/v1/org/report") @Route("api/v1/org/report")
@Tags("Report") @Tags("Report")
@ -25,6 +27,8 @@ export class ReportController extends Controller {
private child2Repository = AppDataSource.getRepository(OrgChild2); private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3); private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4); private child4Repository = AppDataSource.getRepository(OrgChild4);
private posTypepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
/** /**
* API Report1 * API Report1
@ -4087,8 +4091,7 @@ export class ReportController extends Controller {
} }
@Get("report4/{rootId}") @Get("report4/{rootId}")
async findReport4(@Path() rootId: string) { async findReport4(@Path() rootId: string ="71bf0e3d-ba38-4b6c-b87e-c27c8d42edce") {
const orgRootData = await this.orgRootRepository.find({ const orgRootData = await this.orgRootRepository.find({
where: { where: {
id: rootId, id: rootId,
@ -4102,87 +4105,77 @@ export class ReportController extends Controller {
"posMasters.positions.posExecutive", "posMasters.positions.posExecutive",
], ],
}); });
let data: any = []; if(!rootId) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
var _data = [{ const posType = await this.posTypepository.find({
type: "ทั่วไป", order: {
level: "ปฎิบัติงาน", posTypeRank: "ASC",
total: "0", posLevels: { "posLevelRank": "ASC" }
remark: "-" },
}, relations: ["posLevels"]
{ });
type: "",
level: "ชำนาญงาน", const posLevel = await this.posLevelRepository.find({
total: "0", order: {"posLevelRank": "ASC"}
remark: "-" });
},
{ const mapData = posType.map((type) => ({
type: "", id: type.id,
level: "อาวุโส", typeName: type.posTypeName,
total: "0", levels: posLevel
remark: "-" .filter((level) => level.posTypeId === type.id)
}, .map((level) => ({ levelName: level.posLevelName, id: level.id })),
{ }));
type: "",
level: "รวม", let _data: any = [];
total: "0", mapData.forEach((type, idx) => {
type.levels.forEach((level, idy) => {
_data.push({
typeName: idy == 0 ? type.typeName : "",
levelName: level.levelName,
total: orgRootData.length > 0
? orgRootData[0].posMasters
.flatMap((x) => x.positions
.filter((y) => y.posLevelId === level.id && y.posTypeId === type.id )
.map((z) => ({
position: z.positionName || ""
})
)).length
: 0,
remark: ""
});
});
_data.push({
typeName: "",
levelName: "รวม",
total: orgRootData.length > 0
? orgRootData[0].posMasters
.flatMap((x) => x.positions
.filter((y) => y.posTypeId === type.id )
.map((z) => ({
position: z.positionName || ""
})
)).length
: 0,
remark: ""
});
});
_data.push({
typeName: "",
levelName: "รวมทั้งสิ้น",
total: orgRootData.length > 0
? orgRootData[0].posMasters.flatMap((x) => x.positions).length
: 0,
remark: "" remark: ""
}, });
{
type: "วิชาการ", return new HttpSuccess({
level: "ปฎิบัติการ", template: "report4",
total: "0", reportName: "report4",
remark: "-" data: {
}, dateCurrent: Extension.ToThaiShortDate(new Date()),
{ rootName: orgRootData.length > 0 ? orgRootData[0].orgRootName : "-",
type: "", data: _data
level: "ชำนาญการ", }
total: "0", });
remark: "-"
},
{
type: "",
level: "รวม",
total: "0",
remark: ""
},
{
type: "อำนวยการ",
level: "ต้น",
total: "0",
remark: "-"
},
{
type: "",
level: "สูง",
total: "0",
remark: "-"
},
{
type: "",
level: "รวม",
total: "0",
remark: ""
},
{
type: "บริหาร",
level: "ต้น",
total: "0",
remark: "-"
},
{
type: "",
level: "สูง",
total: "0",
remark: "-"
},
{
type: "",
level: "รวม",
total: "0",
remark: ""
}
]
data.push(_data);
return new HttpSuccess({ template: "report4", reportName: "report4", data: { dateCurrent: Extension.ToThaiShortDate(new Date()) , data: _data } });
} }
} }