update salary

This commit is contained in:
mamoss 2025-03-17 15:42:48 +07:00
parent a03ce9d55a
commit 23b6452d56

View file

@ -1,6 +1,6 @@
import { Controller, Post, Route, Security, Tags, Request, UploadedFile } from "tsoa";
import { AppDataSource } from "../database/data-source";
import { In, IsNull, Not } from "typeorm";
import { In, IsNull, LessThanOrEqual, Not } from "typeorm";
import HttpSuccess from "../interfaces/http-success";
import { UseInterceptors } from "@nestjs/common";
import { Profile } from "../entities/Profile";
@ -2276,11 +2276,11 @@ export class ImportDataController extends Controller {
@Post("mapposition-Officer")
async MapPositionOfficer(@Request() request: { user: Record<string, any> }) {
const officer = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "posMaster")
// .where({citizenId: "1720700018869"})
.where("posMaster.id IS NULL")
.getMany();
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "posMaster")
// .where({citizenId: "1720700018869"})
.where("posMaster.id IS NULL")
.getMany();
let rowCount = 0;
let _null: any = null;
let type_: any = null;
@ -2294,22 +2294,22 @@ export class ImportDataController extends Controller {
console.log(rowCount);
const item = await AppDataSource.getRepository(OFFICER)
.createQueryBuilder("OFFICER")
.where({ CIT: _item.citizenId })
.where({ CIT: _item.citizenId })
.getOne();
if (item == null) {
continue;
}
let posMaster = new PosMaster();
let orgRoot = (await this.orgRootRepo.findOne({
where: {
DEPARTMENT_CODE: item.DEPARTMENT_CODE,
DIVISION_CODE: item.DIVISION_CODE,
SECTION_CODE: item.SECTION_CODE,
JOB_CODE: item.JOB_CODE,
orgRevisionId: orgRevision.id,
},
})) as OrgRoot;
let orgRoot = (await this.orgRootRepo.findOne({
where: {
DEPARTMENT_CODE: item.DEPARTMENT_CODE,
DIVISION_CODE: item.DIVISION_CODE,
SECTION_CODE: item.SECTION_CODE,
JOB_CODE: item.JOB_CODE,
orgRevisionId: orgRevision.id,
},
})) as OrgRoot;
if (orgRoot != null) {
posMaster.orgRootId = orgRoot.id ?? _null;
} else {
@ -2325,7 +2325,7 @@ export class ImportDataController extends Controller {
if (orgChild1 != null) {
posMaster.orgRootId = orgChild1.orgRootId ?? _null;
posMaster.orgChild1Id = orgChild1.id ?? _null;
} else {
} else {
let orgChild2 = await this.orgChild2Repo.findOne({
where: {
DEPARTMENT_CODE: item.DEPARTMENT_CODE,
@ -2381,7 +2381,7 @@ export class ImportDataController extends Controller {
posMaster.isDirector = false;
posMaster.isSit = false;
posMaster.current_holderId = _item.id;
posMaster.posMasterNo = item.SALARY == "" ? _null : Number(item.POS_NUM_CODE);
posMaster.posMasterNo = item.POS_NUM_CODE == "" || item.POS_NUM_CODE == null ? _null : Number(item.POS_NUM_CODE);
posMaster.orgRevisionId = orgRevision.id;
posMaster.posMasterCreatedAt = new Date();
posMaster.createdUserId = request.user.sub;
@ -2583,4 +2583,24 @@ export class ImportDataController extends Controller {
}
return new HttpSuccess();
}
/**
* @summary
*/
@Post("update-amount")
async UpdateAmount(@Request() request: { user: Record<string, any> }) {
let rowCount = 0;
const profile:any = await this.profileRepo.find({where: { amount: LessThanOrEqual(0) }});
for await (const _item of profile) {
const OFFICER = await this.OFFICERRepo.findOne({ select: ["CIT", "SALARY"], where: { CIT: _item.citizenId } });
if (OFFICER) {
rowCount++;
_item.amount = Number(OFFICER.SALARY);
await this.profileRepo.save(_item);
console.log(rowCount);
}
}
return new HttpSuccess();
}
}