This commit is contained in:
AdisakKanthawilang 2024-02-28 13:38:08 +07:00
parent 1c9a4d47cc
commit c1599e9d41

View file

@ -24,6 +24,7 @@ import { OrgRevision } from "../entities/OrgRevision";
import { PosMaster } from "../entities/PosMaster";
import { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType";
import { request } from "http";
@Route("api/v1/org/profile")
@Tags("Profile")
@ -946,15 +947,22 @@ export class ProfileController extends Controller {
* @summary ORG_072 - #76
*
*/
@Get("salary/gen")
async salaryGen() {
@Post("salary/gen")
async salaryGen(
@Body()
body: {
page: number;
pageSize: number;
keyword?: string;
},
) {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const findPosMaster = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
@ -966,15 +974,95 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("posMaster.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.leftJoinAndSelect("current_holder.profileSalary", "profileSalary")
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
.leftJoinAndSelect("current_holder.posType", "posType")
.where({
orgRevisionId: findRevision?.id,
current_holderId: Not(IsNull()),
})
.andWhere(
new Brackets((qb) => {
qb.where(
body.keyword != null && body.keyword != ""
? "current_holder.prefix LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.firstName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.lastName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.position LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "orgRoot.orgRootName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "orgChild1.orgChild1Name LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "orgChild2.orgChild2Name LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "orgChild3.orgChild3Name LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "orgChild4.orgChild4Name LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
}),
)
.take(body.pageSize)
.getMany();
if (!findPosMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster");
}
const total = findPosMaster?findPosMaster.length:0;
const formattedData = findPosMaster.map((item) => {
let orgShortName = "";
@ -1015,21 +1103,21 @@ export class ProfileController extends Controller {
posMasterNoSuffix: item.posMasterNoSuffix,
orgShortName: orgShortName,
position: item.current_holder.position,
posTypeId: item.current_holder.posTypeId,
posLevelId: item.current_holder.posLevelId,
posType: item.current_holder.posType.posTypeName,
posLevel: item.current_holder.posLevel.posLevelName,
posExecutive: posExecutive,
amount: amount,
revisionId: item.orgRevisionId,
amount: amount?amount:0,
// revisionId: item.orgRevisionId,
rootId: item.orgRootId,
root: item.orgRoot?.orgRootName,
root: item.orgRoot?.orgRootName?item.orgRoot.orgRootName:null,
child1Id: item.orgChild1Id,
child1: item.orgChild1?.orgChild1Name,
child1: item.orgChild1?.orgChild1Name?item.orgChild1.orgChild1Name:null,
child2Id: item.orgChild2Id,
child2: item.orgChild2?.orgChild2Name,
child2: item.orgChild2?.orgChild2Name?item.orgChild2.orgChild2Name:null,
child3Id: item.orgChild3Id,
child3: item.orgChild3?.orgChild3Name,
child3: item.orgChild3?.orgChild3Name?item.orgChild3.orgChild3Name:null,
child4Id: item.orgChild4Id,
child4: item.orgChild4?.orgChild4Name,
child4: item.orgChild4?.orgChild4Name?item.orgChild4.orgChild4Name:null,
isResult: true,
isDuration: false,
isPunish: true,
@ -1038,7 +1126,7 @@ export class ProfileController extends Controller {
};
});
return new HttpSuccess(formattedData);
return new HttpSuccess({data:formattedData,total:total});
}
/**