struct-chart
This commit is contained in:
parent
e85691019f
commit
022770c2c9
1 changed files with 184 additions and 0 deletions
|
|
@ -1663,4 +1663,188 @@ export class OrganizationController extends Controller {
|
|||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API Organizational StructChart
|
||||
*
|
||||
* @summary Organizational StructChart
|
||||
*
|
||||
*/
|
||||
@Get("struct-chart/{idNode}/{type}")//bright
|
||||
async structchart(@Path() idNode: string, type: number) {
|
||||
try {
|
||||
|
||||
let revision: any;
|
||||
let root: any;
|
||||
let child1: any;
|
||||
let child2: any;
|
||||
let child3: any;
|
||||
let child4: any;
|
||||
let totalPositionCount_1: any;
|
||||
let totalPositionVacant_1: any;
|
||||
let totalPositionCount_2: any;
|
||||
let totalPositionVacant_2: any;
|
||||
let totalPositionCount_3: any;
|
||||
let totalPositionVacant_3: any;
|
||||
let totalPositionCount_4: any;
|
||||
let totalPositionVacant_4: any;
|
||||
let totalPositionCount_5: any;
|
||||
let totalPositionVacant_5: any;
|
||||
|
||||
switch (type) {
|
||||
case 0: {
|
||||
|
||||
revision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!revision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found revision");
|
||||
}
|
||||
totalPositionCount_1 = await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: idNode
|
||||
}
|
||||
});
|
||||
totalPositionVacant_1 = await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: idNode,
|
||||
current_holderId: IsNull() && "",
|
||||
}
|
||||
});
|
||||
root = await this.orgRootRepository.find({
|
||||
where: {
|
||||
orgRevisionId: idNode
|
||||
},
|
||||
});
|
||||
|
||||
if(root.length > 0){
|
||||
child1 = await this.child1Repository.find({
|
||||
where: {
|
||||
// orgRevisionId: idNode,
|
||||
orgRootId: root.id,
|
||||
},
|
||||
});
|
||||
if(child1.length > 0){
|
||||
child2 = await this.child2Repository.find({
|
||||
where: {
|
||||
// orgRevisionId: idNode,
|
||||
// orgRootId: root.id,
|
||||
orgChild1Id: child1.id
|
||||
},
|
||||
});
|
||||
if(child2.length > 0){
|
||||
child3 = await this.child3Repository.find({
|
||||
where: {
|
||||
// orgRevisionId: idNode,
|
||||
// orgRootId: root.id,
|
||||
// orgChild1Id: child1.id,
|
||||
orgChild2Id: child2.id
|
||||
},
|
||||
});
|
||||
if(child3.length > 0){
|
||||
child4 = await this.child4Repository.find({
|
||||
where: {
|
||||
// orgRevisionId: idNode,
|
||||
// orgRootId: root.id,
|
||||
// orgChild1Id: child1.id,
|
||||
// orgChild2Id: child2.id,
|
||||
orgChild3Id: child3.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Tree
|
||||
const treeObject = {
|
||||
deptID: revision.id,
|
||||
departmentName: revision.orgRevisionName,
|
||||
totalPositionCount: totalPositionCount_1 == 0 || null ? 0 : totalPositionCount_1,
|
||||
totalPositionVacant: totalPositionVacant_1 == 0 || null ? 0 : totalPositionVacant_1,
|
||||
children: root.map((roots:any) => ({
|
||||
deptID: roots.id,
|
||||
departmentName: roots.orgRootName,
|
||||
|
||||
|
||||
})),
|
||||
heads: [
|
||||
{
|
||||
positionID: null,
|
||||
positionName: null,
|
||||
positionNum: null,
|
||||
totalPositionCount: 0,
|
||||
totalPositionVacant: 0
|
||||
}
|
||||
],
|
||||
officer: [
|
||||
{
|
||||
positionID: null,
|
||||
positionName: null,
|
||||
positionNum: null,
|
||||
totalPositionCount: 0,
|
||||
totalPositionVacant: 0
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return new HttpSuccess(treeObject)
|
||||
|
||||
}
|
||||
case 1: {
|
||||
root = await this.orgRootRepository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!root) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
child1 = await this.child1Repository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!child1) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
child2 = await this.child2Repository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!child2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
child3 = await this.child3Repository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
child4 = await this.child4Repository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!child4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4Id");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: ");
|
||||
}
|
||||
|
||||
// return new HttpSuccess();
|
||||
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue