add permission profile

This commit is contained in:
mamoss 2025-03-24 21:57:50 +07:00
parent dc9ac66896
commit af3e0abd2a
5 changed files with 725 additions and 38 deletions

View file

@ -340,24 +340,24 @@ export class ImportDataController extends Controller {
.select(["profile.citizenId", "profile.id"])
.orderBy("profile.citizenId", "ASC")
// .where("profile.citizenId = '3101702379675'")
.where({
citizenId: In([
// "1100600109451",
// "1209900075508",
// "1739900231556",
// "1809900305214",
// "1920600228762",
// "3101600963742",
// "3102401171243",
// "3120100454406",
// "3180100306172",
// "3700100094722",
// "3809900116957",
"3940900213929",
]),
})
// .skip(10000)
// .take(20000)
// .where({
// citizenId: In([
// // "1100600109451",
// // "1209900075508",
// // "1739900231556",
// // "1809900305214",
// // "1920600228762",
// // "3101600963742",
// // "3102401171243",
// // "3120100454406",
// // "3180100306172",
// // "3700100094722",
// // "3809900116957",
// "3940900213929",
// ]),
// })
.skip(0)
.take(10000)
.getManyAndCount();
var _profiles: ProfileSalary[] = [];
const filePath = path.join(__dirname, "salaryProfile1.csv");
@ -1956,7 +1956,8 @@ export class ImportDataController extends Controller {
@Post("ImportOrg")
async ImportOrg(@Request() request: { user: Record<string, any> }) {
const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
// where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
where: { id: "30e594c9-a65b-485e-a4c5-71aa497e6b8a" },
});
if (orgRevision == null) return new HttpSuccess();
//create root
@ -2005,7 +2006,7 @@ export class ImportDataController extends Controller {
for (const item of IMPORT_CHILD1) {
const orgChild1 = new OrgChild1();
let orgRoot = await this.orgRootRepo.findOne({
where: { orgRootName: item.orgRoot },
where: { orgRootName: item.orgRoot, orgRevisionId: orgRevision.id },
relations: ["orgChild1s"],
});
if (orgRoot == null) {
@ -2067,7 +2068,7 @@ export class ImportDataController extends Controller {
for (const item of IMPORT_CHILD2) {
const orgChild2 = new OrgChild2();
let orgRoot = await this.orgRootRepo.findOne({
where: { orgRootName: item.orgRoot },
where: { orgRootName: item.orgRoot, orgRevisionId: orgRevision.id },
relations: ["orgChild1s"],
});
if (orgRoot == null) {
@ -2093,7 +2094,11 @@ export class ImportDataController extends Controller {
await this.orgRootRepo.save(orgRoot);
}
let orgChild1 = await this.orgChild1Repo.findOne({
where: { orgChild1Name: item.orgChild1 },
where: {
orgChild1Name: item.orgChild1,
orgRootId: orgRoot.id,
orgRevisionId: orgRevision.id,
},
relations: ["orgChild2s"],
});
if (orgChild1 == null) {
@ -2159,7 +2164,7 @@ export class ImportDataController extends Controller {
for (const item of IMPORT_CHILD3) {
const orgChild3 = new OrgChild3();
let orgRoot = await this.orgRootRepo.findOne({
where: { orgRootName: item.orgRoot },
where: { orgRootName: item.orgRoot, orgRevisionId: orgRevision.id },
relations: ["orgChild1s"],
});
if (orgRoot == null) {
@ -2185,7 +2190,11 @@ export class ImportDataController extends Controller {
await this.orgRootRepo.save(orgRoot);
}
let orgChild1 = await this.orgChild1Repo.findOne({
where: { orgChild1Name: item.orgChild1 },
where: {
orgChild1Name: item.orgChild1,
orgRootId: orgRoot.id,
orgRevisionId: orgRevision.id,
},
relations: ["orgChild2s"],
});
if (orgChild1 == null) {
@ -2214,7 +2223,12 @@ export class ImportDataController extends Controller {
await this.orgChild1Repo.save(orgChild1);
}
let orgChild2 = await this.orgChild2Repo.findOne({
where: { orgChild2Name: item.orgChild2 },
where: {
orgChild2Name: item.orgChild2,
orgChild1Id: orgChild1.id,
orgRootId: orgRoot.id,
orgRevisionId: orgRevision.id,
},
relations: ["orgChild3s"],
});
if (orgChild2 == null) {
@ -2277,7 +2291,7 @@ export class ImportDataController extends Controller {
async MapPositionOfficer(@Request() request: { user: Record<string, any> }) {
const officer = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "posMaster")
.leftJoinAndSelect("profile.next_holders", "posMaster")
// .where({citizenId: "1720700018869"})
.where("posMaster.id IS NULL")
.getMany();
@ -2286,7 +2300,8 @@ export class ImportDataController extends Controller {
let type_: any = null;
let level_: any = null;
const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
// where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
where: { id: "30e594c9-a65b-485e-a4c5-71aa497e6b8a" },
});
if (orgRevision == null) return new HttpSuccess();
for await (const _item of officer) {
@ -2380,8 +2395,9 @@ export class ImportDataController extends Controller {
posMaster.isStaff = false;
posMaster.isDirector = false;
posMaster.isSit = false;
posMaster.current_holderId = _item.id;
posMaster.posMasterNo = item.POS_NUM_CODE == "" || item.POS_NUM_CODE == null ? _null : Number(item.POS_NUM_CODE);
posMaster.next_holderId = _item.id;
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;
@ -2590,10 +2606,13 @@ export class ImportDataController extends Controller {
@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) }});
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 } });
const OFFICER = await this.OFFICERRepo.findOne({
select: ["CIT", "SALARY"],
where: { CIT: _item.citizenId },
});
if (OFFICER) {
rowCount++;
_item.amount = Number(OFFICER.SALARY);
@ -2603,4 +2622,28 @@ export class ImportDataController extends Controller {
}
return new HttpSuccess();
}
/**
* @summary
*/
@Post("update-profileSalary")
async UpdateProfileSalary(@Request() request: { user: Record<string, any> }) {
let rowCount = 0;
const profileSalarys: any = await this.salaryRepo.find();
for await (const _item of profileSalarys) {
const OFFICER = await this.OFFICERRepo.findOne({
select: ["ID", "POS_NUM_CODE_SIT", "POS_NUM_CODE_SIT_ABB"],
where: { ID: _item.refId },
});
if (OFFICER) {
rowCount++;
_item.posNumCodeSit = OFFICER.POS_NUM_CODE_SIT;
_item.posNumCodeSitAbb = OFFICER.POS_NUM_CODE_SIT_ABB;
await this.profileRepo.save(_item);
console.log(rowCount);
}
}
return new HttpSuccess();
}
}