no message
This commit is contained in:
parent
2d2f35847a
commit
5e7fa0eddf
2 changed files with 110 additions and 72 deletions
|
|
@ -30,6 +30,10 @@ import permission from "../interfaces/permission";
|
|||
import { PermissionOrg } from "../entities/PermissionOrg";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { sendToQueueOrg } from "../services/rabbitmq";
|
||||
import { PosMasterAssign } from "../entities/PosMasterAssign";
|
||||
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||
import { EmployeePosition } from "../entities/EmployeePosition";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
|
||||
@Route("api/v1/org")
|
||||
@Tags("Organization")
|
||||
|
|
@ -47,8 +51,12 @@ export class OrganizationController extends Controller {
|
|||
private child3Repository = AppDataSource.getRepository(OrgChild3);
|
||||
private child4Repository = AppDataSource.getRepository(OrgChild4);
|
||||
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||
private posMasterActRepository = AppDataSource.getRepository(PosMasterAct);
|
||||
private posMasterAssignRepository = AppDataSource.getRepository(PosMasterAssign);
|
||||
private positionRepository = AppDataSource.getRepository(Position);
|
||||
private profileRepo = AppDataSource.getRepository(Profile);
|
||||
private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
|
||||
private employeePositionRepository = AppDataSource.getRepository(EmployeePosition);
|
||||
|
||||
/**
|
||||
* API รายการประวัติโครงสร้าง
|
||||
|
|
@ -653,20 +661,32 @@ export class OrganizationController extends Controller {
|
|||
const _orgRevisions = await this.orgRevisionRepository.find({
|
||||
where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }],
|
||||
});
|
||||
const _roots = await this.orgRootRepository.find({
|
||||
where: [{ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }],
|
||||
});
|
||||
const _posMasters = await this.posMasterRepository.find({
|
||||
where: [{ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }],
|
||||
});
|
||||
const _positions = await this.positionRepository.find({
|
||||
where: [{ posMasterId: In(_posMasters.map((x) => x.id)) }],
|
||||
const _employeePosMasters = await this.employeePosMasterRepository.find({
|
||||
where: [{ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }],
|
||||
});
|
||||
await this.positionRepository.delete({ posMasterId: In(_posMasters.map((x) => x.id)) });
|
||||
await this.employeePositionRepository.delete({
|
||||
posMasterId: In(_employeePosMasters.map((x) => x.id)),
|
||||
});
|
||||
await this.posMasterAssignRepository.delete({ posMasterId: In(_posMasters.map((x) => x.id)) });
|
||||
await this.posMasterActRepository.delete({ posMasterId: In(_posMasters.map((x) => x.id)) });
|
||||
await this.posMasterActRepository.delete({
|
||||
posMasterChildId: In(_posMasters.map((x) => x.id)),
|
||||
});
|
||||
await this.positionRepository.remove(_positions);
|
||||
await this.posMasterRepository.remove(_posMasters);
|
||||
await this.employeePosMasterRepository.remove(_employeePosMasters);
|
||||
await this.child4Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
||||
await this.child3Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
||||
await this.child2Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
||||
await this.child1Repository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
||||
await this.permissionOrgRepository.delete({
|
||||
orgRootId: In(_posMasters.map((x) => x.orgRootId)),
|
||||
orgRootId: In(_roots.map((x) => x.id)),
|
||||
});
|
||||
await this.orgRootRepository.delete({ orgRevisionId: In(_orgRevisions.map((x) => x.id)) });
|
||||
await this.orgRevisionRepository.remove(_orgRevisions);
|
||||
|
|
|
|||
|
|
@ -1293,9 +1293,9 @@ export class PositionController extends Controller {
|
|||
@Request() request: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
id: string;
|
||||
id: string | null;
|
||||
revisionId: string;
|
||||
type: number;
|
||||
type: number | null;
|
||||
isAll: boolean;
|
||||
isBlank: boolean;
|
||||
page: number;
|
||||
|
|
@ -1307,75 +1307,76 @@ export class PositionController extends Controller {
|
|||
let checkChildConditions: any = {};
|
||||
let keywordAsInt: any;
|
||||
let searchShortName = "";
|
||||
let labelName = "";
|
||||
let searchShortName0 = `CONCAT(orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
if (body.type === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild1Id: IsNull(),
|
||||
if (body.type != null && body.id != null) {
|
||||
if (body.type === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.id,
|
||||
};
|
||||
searchShortName = `CONCAT(orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
|
||||
} else {
|
||||
}
|
||||
if (body.isBlank == true) {
|
||||
typeCondition.current_holderId = IsNull();
|
||||
}
|
||||
} else if (body.type === 1) {
|
||||
typeCondition = {
|
||||
orgChild1Id: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild2Id: IsNull(),
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild1Id: IsNull(),
|
||||
};
|
||||
searchShortName = `CONCAT(orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
|
||||
} else {
|
||||
}
|
||||
if (body.isBlank == true) {
|
||||
typeCondition.current_holderId = IsNull();
|
||||
}
|
||||
} else if (body.type === 1) {
|
||||
typeCondition = {
|
||||
orgChild1Id: body.id,
|
||||
};
|
||||
searchShortName = `CONCAT(orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
|
||||
} else {
|
||||
}
|
||||
if (body.isBlank == true) {
|
||||
typeCondition.current_holderId = IsNull();
|
||||
}
|
||||
} else if (body.type === 2) {
|
||||
typeCondition = {
|
||||
orgChild2Id: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild3Id: IsNull(),
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild2Id: IsNull(),
|
||||
};
|
||||
searchShortName = `CONCAT(orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
|
||||
} else {
|
||||
}
|
||||
if (body.isBlank == true) {
|
||||
typeCondition.current_holderId = IsNull();
|
||||
}
|
||||
} else if (body.type === 2) {
|
||||
typeCondition = {
|
||||
orgChild2Id: body.id,
|
||||
};
|
||||
searchShortName = `CONCAT(orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
|
||||
} else {
|
||||
}
|
||||
if (body.isBlank == true) {
|
||||
typeCondition.current_holderId = IsNull();
|
||||
}
|
||||
} else if (body.type === 3) {
|
||||
typeCondition = {
|
||||
orgChild3Id: body.id,
|
||||
};
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild4Id: IsNull(),
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild3Id: IsNull(),
|
||||
};
|
||||
searchShortName = `CONCAT(orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
|
||||
} else {
|
||||
}
|
||||
if (body.isBlank == true) {
|
||||
typeCondition.current_holderId = IsNull();
|
||||
}
|
||||
} else if (body.type === 3) {
|
||||
typeCondition = {
|
||||
orgChild3Id: body.id,
|
||||
};
|
||||
searchShortName = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
|
||||
} else {
|
||||
}
|
||||
if (body.isBlank == true) {
|
||||
typeCondition.current_holderId = IsNull();
|
||||
}
|
||||
} else if (body.type === 4) {
|
||||
typeCondition = {
|
||||
orgChild4Id: body.id,
|
||||
};
|
||||
searchShortName = `CONCAT(orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
|
||||
if (body.isBlank == true) {
|
||||
typeCondition.current_holderId = IsNull();
|
||||
if (!body.isAll) {
|
||||
checkChildConditions = {
|
||||
orgChild4Id: IsNull(),
|
||||
};
|
||||
searchShortName = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
|
||||
} else {
|
||||
}
|
||||
if (body.isBlank == true) {
|
||||
typeCondition.current_holderId = IsNull();
|
||||
}
|
||||
} else if (body.type === 4) {
|
||||
typeCondition = {
|
||||
orgChild4Id: body.id,
|
||||
};
|
||||
searchShortName = `CONCAT(orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;
|
||||
if (body.isBlank == true) {
|
||||
typeCondition.current_holderId = IsNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
let findPosition: any;
|
||||
|
|
@ -1464,11 +1465,26 @@ export class PositionController extends Controller {
|
|||
.andWhere(revisionCondition);
|
||||
}),
|
||||
)
|
||||
// .orWhere(
|
||||
// new Brackets((qb) => {
|
||||
// qb.andWhere(
|
||||
// body.keyword != null && body.keyword != ""
|
||||
// ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'`
|
||||
// : "1=1",
|
||||
// {
|
||||
// keyword: `%${body.keyword}%`,
|
||||
// },
|
||||
// )
|
||||
// .andWhere(checkChildConditions)
|
||||
// .andWhere(typeCondition)
|
||||
// .andWhere(revisionCondition);
|
||||
// }),
|
||||
// )
|
||||
.orWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.andWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'`
|
||||
? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'`
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
|
|
@ -1483,7 +1499,7 @@ export class PositionController extends Controller {
|
|||
new Brackets((qb) => {
|
||||
qb.andWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'`
|
||||
? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN next_holder.citizenId ELSE current_holder.citizenId END LIKE '%${body.keyword}%'`
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
|
|
@ -1581,8 +1597,8 @@ export class PositionController extends Controller {
|
|||
},
|
||||
relations: ["posLevel", "posType", "posExecutive"],
|
||||
order: {
|
||||
posType:{posTypeRank: "ASC"},
|
||||
posLevel:{posLevelRank: "ASC"}
|
||||
posType: { posTypeRank: "ASC" },
|
||||
posLevel: { posLevelRank: "ASC" },
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -1679,6 +1695,8 @@ export class PositionController extends Controller {
|
|||
profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName,
|
||||
profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName,
|
||||
authRoleId: posMaster.authRoleId,
|
||||
profileIdNextHolder: posMaster.next_holderId,
|
||||
profileIdCurrentHolder: posMaster.current_holderId,
|
||||
authRoleName:
|
||||
authRoleName == null || authRoleName.roleName == null ? null : authRoleName.roleName,
|
||||
isPosMasterAssign: posMaster.posMasterAssigns.length > 0 ? true : false,
|
||||
|
|
@ -2008,8 +2026,8 @@ export class PositionController extends Controller {
|
|||
},
|
||||
relations: ["posLevel", "posType", "posExecutive"],
|
||||
order: {
|
||||
posType:{posTypeRank: "ASC"},
|
||||
posLevel:{posLevelRank: "ASC"}
|
||||
posType: { posTypeRank: "ASC" },
|
||||
posLevel: { posLevelRank: "ASC" },
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue