no message
This commit is contained in:
parent
d897c8c041
commit
fa52b33786
4 changed files with 1007 additions and 13 deletions
|
|
@ -588,15 +588,22 @@ export class OrganizationController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Get("{id}")
|
||||
async detail(@Path() id: string) {
|
||||
async detail(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
|
||||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
|
||||
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
||||
.createQueryBuilder("orgRoot")
|
||||
.where("orgRoot.orgRevisionId = :id", { id })
|
||||
.andWhere(
|
||||
_data.root != undefined && _data.root != null ? `orgRoot.id IN (:...node)` : "1=1",
|
||||
{
|
||||
node: _data.root,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
"orgRoot.id",
|
||||
"orgRoot.orgRootName",
|
||||
|
|
@ -613,13 +620,20 @@ export class OrganizationController extends Controller {
|
|||
])
|
||||
.orderBy("orgRoot.orgRootOrder", "ASC")
|
||||
.getMany();
|
||||
|
||||
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null;
|
||||
const orgChild1Data =
|
||||
orgRootIds && orgRootIds.length > 0
|
||||
? await AppDataSource.getRepository(OrgChild1)
|
||||
.createQueryBuilder("orgChild1")
|
||||
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
|
||||
.andWhere(
|
||||
_data.child1 != undefined && _data.child1 != null
|
||||
? `orgChild1.id IN (:...node)`
|
||||
: "1=1",
|
||||
{
|
||||
node: _data.child1,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
"orgChild1.id",
|
||||
"orgChild1.orgChild1Name",
|
||||
|
|
@ -644,6 +658,14 @@ export class OrganizationController extends Controller {
|
|||
? await AppDataSource.getRepository(OrgChild2)
|
||||
.createQueryBuilder("orgChild2")
|
||||
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
|
||||
.andWhere(
|
||||
_data.child2 != undefined && _data.child2 != null
|
||||
? `orgChild2.id IN (:...node)`
|
||||
: "1=1",
|
||||
{
|
||||
node: _data.child2,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
"orgChild2.id",
|
||||
"orgChild2.orgChild2Name",
|
||||
|
|
@ -669,6 +691,14 @@ export class OrganizationController extends Controller {
|
|||
? await AppDataSource.getRepository(OrgChild3)
|
||||
.createQueryBuilder("orgChild3")
|
||||
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
|
||||
.andWhere(
|
||||
_data.child3 != undefined && _data.child3 != null
|
||||
? `orgChild3.id IN (:...node)`
|
||||
: "1=1",
|
||||
{
|
||||
node: _data.child3,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
"orgChild3.id",
|
||||
"orgChild3.orgChild3Name",
|
||||
|
|
@ -694,6 +724,14 @@ export class OrganizationController extends Controller {
|
|||
? await AppDataSource.getRepository(OrgChild4)
|
||||
.createQueryBuilder("orgChild4")
|
||||
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
|
||||
.andWhere(
|
||||
_data.child4 != undefined && _data.child4 != null
|
||||
? `orgChild4.id IN (:...node)`
|
||||
: "1=1",
|
||||
{
|
||||
node: _data.child4,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
"orgChild4.id",
|
||||
"orgChild4.orgChild4Name",
|
||||
|
|
@ -1486,7 +1524,10 @@ export class OrganizationController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Post("sort")
|
||||
async Sort(@Body() requestBody: { id: string; type: number; sortId: string[] }, @Request() request: RequestWithUser) {
|
||||
async Sort(
|
||||
@Body() requestBody: { id: string; type: number; sortId: string[] },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_ORG");
|
||||
switch (requestBody.type) {
|
||||
case 0: {
|
||||
|
|
@ -3728,4 +3769,774 @@ export class OrganizationController extends Controller {
|
|||
|
||||
return new HttpSuccess(maps);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดโครงสร้าง
|
||||
*
|
||||
* @summary ORG_023 - รายละเอียดโครงสร้าง (ADMIN) #25
|
||||
*
|
||||
*/
|
||||
@Get("{id}/{system}")
|
||||
async detailBySystem(
|
||||
@Path() id: string,
|
||||
@Path() system: string,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
|
||||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
let _data = await new permission().PermissionOrgList(request, system.trim().toUpperCase());
|
||||
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
||||
.createQueryBuilder("orgRoot")
|
||||
.where("orgRoot.orgRevisionId = :id", { id })
|
||||
.andWhere(
|
||||
_data.root != undefined && _data.root != null ? `orgRoot.id IN (:...node)` : "1=1",
|
||||
{
|
||||
node: _data.root,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
"orgRoot.id",
|
||||
"orgRoot.orgRootName",
|
||||
"orgRoot.orgRootShortName",
|
||||
"orgRoot.orgRootCode",
|
||||
"orgRoot.orgRootOrder",
|
||||
"orgRoot.orgRootPhoneEx",
|
||||
"orgRoot.orgRootPhoneIn",
|
||||
"orgRoot.orgRootFax",
|
||||
"orgRoot.orgRevisionId",
|
||||
"orgRoot.orgRootRank",
|
||||
"orgRoot.orgRootRankSub",
|
||||
"orgRoot.responsibility",
|
||||
])
|
||||
.orderBy("orgRoot.orgRootOrder", "ASC")
|
||||
.getMany();
|
||||
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null;
|
||||
const orgChild1Data =
|
||||
orgRootIds && orgRootIds.length > 0
|
||||
? await AppDataSource.getRepository(OrgChild1)
|
||||
.createQueryBuilder("orgChild1")
|
||||
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
|
||||
.andWhere(
|
||||
_data.child1 != undefined && _data.child1 != null
|
||||
? `orgChild1.id IN (:...node)`
|
||||
: "1=1",
|
||||
{
|
||||
node: _data.child1,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
"orgChild1.id",
|
||||
"orgChild1.orgChild1Name",
|
||||
"orgChild1.orgChild1ShortName",
|
||||
"orgChild1.orgChild1Code",
|
||||
"orgChild1.orgChild1Order",
|
||||
"orgChild1.orgChild1PhoneEx",
|
||||
"orgChild1.orgChild1PhoneIn",
|
||||
"orgChild1.orgChild1Fax",
|
||||
"orgChild1.orgRootId",
|
||||
"orgChild1.orgChild1Rank",
|
||||
"orgChild1.orgChild1RankSub",
|
||||
"orgChild1.responsibility",
|
||||
])
|
||||
.orderBy("orgChild1.orgChild1Order", "ASC")
|
||||
.getMany()
|
||||
: [];
|
||||
|
||||
const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null;
|
||||
const orgChild2Data =
|
||||
orgChild1Ids && orgChild1Ids.length > 0
|
||||
? await AppDataSource.getRepository(OrgChild2)
|
||||
.createQueryBuilder("orgChild2")
|
||||
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
|
||||
.andWhere(
|
||||
_data.child2 != undefined && _data.child2 != null
|
||||
? `orgChild2.id IN (:...node)`
|
||||
: "1=1",
|
||||
{
|
||||
node: _data.child2,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
"orgChild2.id",
|
||||
"orgChild2.orgChild2Name",
|
||||
"orgChild2.orgChild2ShortName",
|
||||
"orgChild2.orgChild2Code",
|
||||
"orgChild2.orgChild2Order",
|
||||
"orgChild2.orgChild2PhoneEx",
|
||||
"orgChild2.orgChild2PhoneIn",
|
||||
"orgChild2.orgChild2Fax",
|
||||
"orgChild2.orgRootId",
|
||||
"orgChild2.orgChild2Rank",
|
||||
"orgChild2.orgChild2RankSub",
|
||||
"orgChild2.orgChild1Id",
|
||||
"orgChild2.responsibility",
|
||||
])
|
||||
.orderBy("orgChild2.orgChild2Order", "ASC")
|
||||
.getMany()
|
||||
: [];
|
||||
|
||||
const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null;
|
||||
const orgChild3Data =
|
||||
orgChild2Ids && orgChild2Ids.length > 0
|
||||
? await AppDataSource.getRepository(OrgChild3)
|
||||
.createQueryBuilder("orgChild3")
|
||||
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
|
||||
.andWhere(
|
||||
_data.child3 != undefined && _data.child3 != null
|
||||
? `orgChild3.id IN (:...node)`
|
||||
: "1=1",
|
||||
{
|
||||
node: _data.child3,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
"orgChild3.id",
|
||||
"orgChild3.orgChild3Name",
|
||||
"orgChild3.orgChild3ShortName",
|
||||
"orgChild3.orgChild3Code",
|
||||
"orgChild3.orgChild3Order",
|
||||
"orgChild3.orgChild3PhoneEx",
|
||||
"orgChild3.orgChild3PhoneIn",
|
||||
"orgChild3.orgChild3Fax",
|
||||
"orgChild3.orgRootId",
|
||||
"orgChild3.orgChild3Rank",
|
||||
"orgChild3.orgChild3RankSub",
|
||||
"orgChild3.orgChild2Id",
|
||||
"orgChild3.responsibility",
|
||||
])
|
||||
.orderBy("orgChild3.orgChild3Order", "ASC")
|
||||
.getMany()
|
||||
: [];
|
||||
|
||||
const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null;
|
||||
const orgChild4Data =
|
||||
orgChild3Ids && orgChild3Ids.length > 0
|
||||
? await AppDataSource.getRepository(OrgChild4)
|
||||
.createQueryBuilder("orgChild4")
|
||||
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
|
||||
.andWhere(
|
||||
_data.child4 != undefined && _data.child4 != null
|
||||
? `orgChild4.id IN (:...node)`
|
||||
: "1=1",
|
||||
{
|
||||
node: _data.child4,
|
||||
},
|
||||
)
|
||||
.select([
|
||||
"orgChild4.id",
|
||||
"orgChild4.orgChild4Name",
|
||||
"orgChild4.orgChild4ShortName",
|
||||
"orgChild4.orgChild4Code",
|
||||
"orgChild4.orgChild4Order",
|
||||
"orgChild4.orgChild4PhoneEx",
|
||||
"orgChild4.orgChild4PhoneIn",
|
||||
"orgChild4.orgChild4Fax",
|
||||
"orgChild4.orgRootId",
|
||||
"orgChild4.orgChild4Rank",
|
||||
"orgChild4.orgChild4RankSub",
|
||||
"orgChild4.orgChild3Id",
|
||||
"orgChild4.responsibility",
|
||||
])
|
||||
.orderBy("orgChild4.orgChild4Order", "ASC")
|
||||
.getMany()
|
||||
: [];
|
||||
|
||||
// const formattedData = orgRootData.map((orgRoot) => {
|
||||
const formattedData = await Promise.all(
|
||||
orgRootData.map(async (orgRoot) => {
|
||||
return {
|
||||
orgTreeId: orgRoot.id,
|
||||
orgLevel: 0,
|
||||
orgName: orgRoot.orgRootName,
|
||||
orgTreeName: orgRoot.orgRootName,
|
||||
orgTreeShortName: orgRoot.orgRootShortName,
|
||||
orgTreeCode: orgRoot.orgRootCode,
|
||||
orgCode: orgRoot.orgRootCode + "00",
|
||||
orgTreeRank: orgRoot.orgRootRank,
|
||||
orgTreeRankSub: orgRoot.orgRootRankSub,
|
||||
orgTreeOrder: orgRoot.orgRootOrder,
|
||||
orgTreePhoneEx: orgRoot.orgRootPhoneEx,
|
||||
orgTreePhoneIn: orgRoot.orgRootPhoneIn,
|
||||
orgTreeFax: orgRoot.orgRootFax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgRoot.responsibility,
|
||||
labelName:
|
||||
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
where: { orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id },
|
||||
}),
|
||||
totalPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild1Data
|
||||
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
|
||||
.map(async (orgChild1) => ({
|
||||
orgTreeId: orgChild1.id,
|
||||
orgRootId: orgRoot.id,
|
||||
orgLevel: 1,
|
||||
orgName: `${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
||||
orgTreeName: orgChild1.orgChild1Name,
|
||||
orgTreeShortName: orgChild1.orgChild1ShortName,
|
||||
orgTreeCode: orgChild1.orgChild1Code,
|
||||
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
|
||||
orgTreeRank: orgChild1.orgChild1Rank,
|
||||
orgTreeRankSub: orgChild1.orgChild1RankSub,
|
||||
orgTreeOrder: orgChild1.orgChild1Order,
|
||||
orgRootCode: orgRoot.orgRootCode,
|
||||
orgTreePhoneEx: orgChild1.orgChild1PhoneEx,
|
||||
orgTreePhoneIn: orgChild1.orgChild1PhoneIn,
|
||||
orgTreeFax: orgChild1.orgChild1Fax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgChild1.responsibility,
|
||||
labelName:
|
||||
orgChild1.orgChild1Name +
|
||||
" " +
|
||||
orgRoot.orgRootCode +
|
||||
orgChild1.orgChild1Code +
|
||||
" " +
|
||||
orgChild1.orgChild1ShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
|
||||
}),
|
||||
totalPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild1Id: orgChild1.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild1Id: orgChild1.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild1Id: orgChild1.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild1Id: orgChild1.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild2Data
|
||||
.filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id)
|
||||
.map(async (orgChild2) => ({
|
||||
orgTreeId: orgChild2.id,
|
||||
orgRootId: orgChild1.id,
|
||||
orgLevel: 2,
|
||||
orgName: `${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
||||
orgTreeName: orgChild2.orgChild2Name,
|
||||
orgTreeShortName: orgChild2.orgChild2ShortName,
|
||||
orgTreeCode: orgChild2.orgChild2Code,
|
||||
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
|
||||
orgTreeRank: orgChild2.orgChild2Rank,
|
||||
orgTreeRankSub: orgChild2.orgChild2RankSub,
|
||||
orgTreeOrder: orgChild2.orgChild2Order,
|
||||
orgRootCode: orgRoot.orgRootCode,
|
||||
orgTreePhoneEx: orgChild2.orgChild2PhoneEx,
|
||||
orgTreePhoneIn: orgChild2.orgChild2PhoneIn,
|
||||
orgTreeFax: orgChild2.orgChild2Fax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgChild2.responsibility,
|
||||
labelName:
|
||||
orgChild2.orgChild2Name +
|
||||
" " +
|
||||
orgRoot.orgRootCode +
|
||||
orgChild2.orgChild2Code +
|
||||
" " +
|
||||
orgChild2.orgChild2ShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild2Id: orgChild2.id,
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild2Id: orgChild2.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild2Id: orgChild2.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild2Id: orgChild2.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild2Id: orgChild2.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild3Data
|
||||
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id)
|
||||
.map(async (orgChild3) => ({
|
||||
orgTreeId: orgChild3.id,
|
||||
orgRootId: orgChild2.id,
|
||||
orgLevel: 3,
|
||||
orgName: `${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
||||
orgTreeName: orgChild3.orgChild3Name,
|
||||
orgTreeShortName: orgChild3.orgChild3ShortName,
|
||||
orgTreeCode: orgChild3.orgChild3Code,
|
||||
orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code,
|
||||
orgTreeRank: orgChild3.orgChild3Rank,
|
||||
orgTreeRankSub: orgChild3.orgChild3RankSub,
|
||||
orgTreeOrder: orgChild3.orgChild3Order,
|
||||
orgRootCode: orgRoot.orgRootCode,
|
||||
orgTreePhoneEx: orgChild3.orgChild3PhoneEx,
|
||||
orgTreePhoneIn: orgChild3.orgChild3PhoneIn,
|
||||
orgTreeFax: orgChild3.orgChild3Fax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgChild3.responsibility,
|
||||
labelName:
|
||||
orgChild3.orgChild3Name +
|
||||
" " +
|
||||
orgRoot.orgRootCode +
|
||||
orgChild3.orgChild3Code +
|
||||
" " +
|
||||
orgChild3.orgChild3ShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild3Id: orgChild3.id,
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild3Id: orgChild3.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild3Id: orgChild3.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild3Id: orgChild3.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild3Id: orgChild3.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild4Data
|
||||
.filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id)
|
||||
.map(async (orgChild4) => ({
|
||||
orgTreeId: orgChild4.id,
|
||||
orgRootId: orgChild3.id,
|
||||
orgLevel: 4,
|
||||
orgName: `${orgChild4.orgChild4Name}/${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
||||
orgTreeName: orgChild4.orgChild4Name,
|
||||
orgTreeShortName: orgChild4.orgChild4ShortName,
|
||||
orgTreeCode: orgChild4.orgChild4Code,
|
||||
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code,
|
||||
orgTreeRank: orgChild4.orgChild4Rank,
|
||||
orgTreeRankSub: orgChild4.orgChild4RankSub,
|
||||
orgTreeOrder: orgChild4.orgChild4Order,
|
||||
orgRootCode: orgRoot.orgRootCode,
|
||||
orgTreePhoneEx: orgChild4.orgChild4PhoneEx,
|
||||
orgTreePhoneIn: orgChild4.orgChild4PhoneIn,
|
||||
orgTreeFax: orgChild4.orgChild4Fax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgChild4.responsibility,
|
||||
labelName:
|
||||
orgChild4.orgChild4Name +
|
||||
" " +
|
||||
orgRoot.orgRootCode +
|
||||
orgChild4.orgChild4Code +
|
||||
" " +
|
||||
orgChild4.orgChild4ShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild4Id: orgChild4.id,
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild4Id: orgChild4.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild4Id: orgChild4.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild4Id: orgChild4.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild4Id: orgChild4.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: orgChild4.id,
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentUse: await this.posMasterRepository.count(
|
||||
{
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: orgChild4.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
},
|
||||
),
|
||||
totalRootPositionCurrentVacant:
|
||||
await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: orgChild4.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: orgChild4.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextVacant: await this.posMasterRepository.count(
|
||||
{
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: orgChild4.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
},
|
||||
),
|
||||
})),
|
||||
),
|
||||
})),
|
||||
),
|
||||
})),
|
||||
),
|
||||
})),
|
||||
),
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess(formattedData);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue