บรรจุ
This commit is contained in:
parent
31b8116a6f
commit
d999c8050c
3 changed files with 379 additions and 34 deletions
|
|
@ -79,6 +79,12 @@ import { ProfileAssistance } from "../entities/ProfileAssistance";
|
|||
import { ProfileAssistanceHistory } from "../entities/ProfileAssistanceHistory";
|
||||
import { ProfileActposition } from "../entities/ProfileActposition";
|
||||
import { ProfileActpositionHistory } from "../entities/ProfileActpositionHistory";
|
||||
import { ProfileFamilyFather } from "../entities/ProfileFamilyFather";
|
||||
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
|
||||
import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
|
||||
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
|
||||
import { ProfileFamilyMother } from "../entities/ProfileFamilyMother";
|
||||
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
|
||||
|
||||
@Route("api/v1/org/command")
|
||||
@Tags("Command")
|
||||
|
|
@ -122,6 +128,12 @@ export class CommandController extends Controller {
|
|||
private assistanceHistoryRepository = AppDataSource.getRepository(ProfileAssistanceHistory);
|
||||
private actpositionRepository = AppDataSource.getRepository(ProfileActposition);
|
||||
private actpositionHistoryRepository = AppDataSource.getRepository(ProfileActpositionHistory);
|
||||
private profileFamilyCoupleRepo = AppDataSource.getRepository(ProfileFamilyCouple);
|
||||
private profileFamilyCoupleHistoryRepo = AppDataSource.getRepository(ProfileFamilyCoupleHistory);
|
||||
private profileFamilyMotherRepo = AppDataSource.getRepository(ProfileFamilyMother);
|
||||
private profileFamilyMotherHistoryRepo = AppDataSource.getRepository(ProfileFamilyMotherHistory);
|
||||
private profileFamilyFatherRepo = AppDataSource.getRepository(ProfileFamilyFather);
|
||||
private profileFamilyFatherHistoryRepo = AppDataSource.getRepository(ProfileFamilyFatherHistory);
|
||||
|
||||
/**
|
||||
* API list รายการคำสั่ง
|
||||
|
|
@ -2121,7 +2133,7 @@ export class CommandController extends Controller {
|
|||
})
|
||||
.then(async (res) => {})
|
||||
.catch(() => {});
|
||||
let order =
|
||||
let order =
|
||||
command.commandRecives == null || command.commandRecives.length <= 0
|
||||
? 0
|
||||
: command.commandRecives[0].order;
|
||||
|
|
@ -2160,8 +2172,7 @@ export class CommandController extends Controller {
|
|||
commandRecive.amountSpecial =
|
||||
item.amountSpecial ?? (salaryData ? salaryData.amountSpecial : _setZero);
|
||||
commandRecive.positionSalaryAmount =
|
||||
item.positionSalaryAmount ??
|
||||
(salaryData ? salaryData.positionSalaryAmount : _setZero);
|
||||
item.positionSalaryAmount ?? (salaryData ? salaryData.positionSalaryAmount : _setZero);
|
||||
commandRecive.mouthSalaryAmount =
|
||||
item.mouthSalaryAmount ?? (salaryData ? salaryData.mouthSalaryAmount : _setZero);
|
||||
} else {
|
||||
|
|
@ -2171,8 +2182,7 @@ export class CommandController extends Controller {
|
|||
commandRecive.mouthSalaryAmount = _null;
|
||||
}
|
||||
|
||||
commandRecive.remarkVertical =
|
||||
item.remarkVertical == null ? _null : item.remarkVertical;
|
||||
commandRecive.remarkVertical = item.remarkVertical == null ? _null : item.remarkVertical;
|
||||
commandRecive.remarkHorizontal =
|
||||
item.remarkHorizontal == null ? _null : item.remarkHorizontal;
|
||||
commandRecive.order = order;
|
||||
|
|
@ -3288,7 +3298,17 @@ export class CommandController extends Controller {
|
|||
const checkUser = await getUserByUsername(profile.citizenId);
|
||||
//ถ้ายังไม่มี user keycloak ให้สร้างใหม่
|
||||
if (checkUser.length == 0) {
|
||||
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
|
||||
let password = profile.citizenId;
|
||||
if (profile.birthDate != null) {
|
||||
const gregorianYear = profile.birthDate.getFullYear() + 543;
|
||||
|
||||
const formattedDate =
|
||||
profile.birthDate.toISOString().slice(8, 10) +
|
||||
profile.birthDate.toISOString().slice(5, 7) +
|
||||
gregorianYear;
|
||||
password = formattedDate;
|
||||
}
|
||||
userKeycloakId = await createUser(profile.citizenId, password, {
|
||||
firstName: profile.firstName,
|
||||
lastName: profile.lastName,
|
||||
});
|
||||
|
|
@ -4746,6 +4766,28 @@ export class CommandController extends Controller {
|
|||
posmasterId: string;
|
||||
positionId: string;
|
||||
} | null;
|
||||
bodyMarry?: {
|
||||
marry?: boolean | null;
|
||||
marryPrefix?: string | null;
|
||||
marryFirstName?: string | null;
|
||||
marryLastName?: string | null;
|
||||
marryOccupation?: string | null;
|
||||
marryNationality?: string | null;
|
||||
} | null;
|
||||
bodyFather?: {
|
||||
fatherPrefix?: string | null;
|
||||
fatherFirstName?: string | null;
|
||||
fatherLastName?: string | null;
|
||||
fatherOccupation?: string | null;
|
||||
fatherNationality?: string | null;
|
||||
} | null;
|
||||
bodyMother?: {
|
||||
motherPrefix?: string | null;
|
||||
motherFirstName?: string | null;
|
||||
motherLastName?: string | null;
|
||||
motherOccupation?: string | null;
|
||||
motherNationality?: string | null;
|
||||
} | null;
|
||||
}[];
|
||||
},
|
||||
) {
|
||||
|
|
@ -4814,14 +4856,20 @@ export class CommandController extends Controller {
|
|||
let result: any;
|
||||
const checkUser = await getUserByUsername(item.bodyProfile.citizenId);
|
||||
if (checkUser.length == 0) {
|
||||
userKeycloakId = await createUser(
|
||||
item.bodyProfile.citizenId,
|
||||
item.bodyProfile.citizenId,
|
||||
{
|
||||
firstName: item.bodyProfile.firstName,
|
||||
lastName: item.bodyProfile.lastName,
|
||||
},
|
||||
);
|
||||
let password = item.bodyProfile.citizenId;
|
||||
if (item.bodyProfile.birthDate != null) {
|
||||
const gregorianYear = item.bodyProfile.birthDate.getFullYear() + 543;
|
||||
|
||||
const formattedDate =
|
||||
item.bodyProfile.birthDate.toISOString().slice(8, 10) +
|
||||
item.bodyProfile.birthDate.toISOString().slice(5, 7) +
|
||||
gregorianYear;
|
||||
password = formattedDate;
|
||||
}
|
||||
userKeycloakId = await createUser(item.bodyProfile.citizenId, password, {
|
||||
firstName: item.bodyProfile.firstName,
|
||||
lastName: item.bodyProfile.lastName,
|
||||
});
|
||||
result = await addUserRoles(
|
||||
userKeycloakId,
|
||||
list
|
||||
|
|
@ -4967,6 +5015,71 @@ export class CommandController extends Controller {
|
|||
}),
|
||||
);
|
||||
}
|
||||
|
||||
//FamilyCouple
|
||||
if (item.bodyMarry != null) {
|
||||
const profileCouple = new ProfileFamilyCouple();
|
||||
const data = {
|
||||
profileId: profile.id,
|
||||
couple: item.bodyMarry.marry,
|
||||
couplePrefix: item.bodyMarry.marryPrefix,
|
||||
coupleFirstName: item.bodyMarry.marryFirstName,
|
||||
coupleLastName: item.bodyMarry.marryLastName,
|
||||
coupleCareer: item.bodyMarry.marryOccupation,
|
||||
coupleLive: true,
|
||||
};
|
||||
Object.assign(profileCouple, { ...data, ...meta });
|
||||
const coupleHistory = new ProfileFamilyCoupleHistory();
|
||||
Object.assign(coupleHistory, { ...profileCouple, id: undefined });
|
||||
profileCouple.profileId = profile.id;
|
||||
await this.profileFamilyCoupleRepo.save(profileCouple, { data: req });
|
||||
setLogDataDiff(req, { before, after: profileCouple });
|
||||
coupleHistory.profileFamilyCoupleId = profileCouple.id;
|
||||
await this.profileFamilyCoupleHistoryRepo.save(coupleHistory, { data: req });
|
||||
}
|
||||
|
||||
//FamilyFather
|
||||
if (item.bodyFather != null) {
|
||||
const profileFather = new ProfileFamilyFather();
|
||||
const data = {
|
||||
profileId: profile.id,
|
||||
fatherPrefix: item.bodyFather.fatherPrefix,
|
||||
fatherFirstName: item.bodyFather.fatherFirstName,
|
||||
fatherLastName: item.bodyFather.fatherLastName,
|
||||
fatherCareer: item.bodyFather.fatherOccupation,
|
||||
fatherLive: true,
|
||||
};
|
||||
Object.assign(profileFather, { ...data, ...meta });
|
||||
const fatherHistory = new ProfileFamilyFatherHistory();
|
||||
Object.assign(fatherHistory, { ...profileFather, id: undefined });
|
||||
profileFather.profileId = profile.id;
|
||||
await this.profileFamilyFatherRepo.save(profileFather, { data: req });
|
||||
setLogDataDiff(req, { before, after: profileFather });
|
||||
fatherHistory.profileFamilyFatherId = profileFather.id;
|
||||
await this.profileFamilyFatherHistoryRepo.save(fatherHistory, { data: req });
|
||||
}
|
||||
|
||||
//FamilyMother
|
||||
if (item.bodyMother != null) {
|
||||
const profileMother = new ProfileFamilyMother();
|
||||
const data = {
|
||||
profileId: profile.id,
|
||||
motherPrefix: item.bodyMother.motherPrefix,
|
||||
motherFirstName: item.bodyMother.motherFirstName,
|
||||
motherLastName: item.bodyMother.motherLastName,
|
||||
motherCareer: item.bodyMother.motherOccupation,
|
||||
motherLive: true,
|
||||
};
|
||||
Object.assign(profileMother, { ...data, ...meta });
|
||||
const motherHistory = new ProfileFamilyMotherHistory();
|
||||
Object.assign(motherHistory, { ...profileMother, id: undefined });
|
||||
profileMother.profileId = profile.id;
|
||||
await this.profileFamilyMotherRepo.save(profileMother, { data: req });
|
||||
setLogDataDiff(req, { before, after: profileMother });
|
||||
motherHistory.profileFamilyMotherId = profileMother.id;
|
||||
await this.profileFamilyMotherHistoryRepo.save(motherHistory, { data: req });
|
||||
}
|
||||
|
||||
//Salary
|
||||
if (item.bodySalarys && item.bodySalarys != null) {
|
||||
const dest_item = await this.salaryRepo.findOne({
|
||||
|
|
@ -5293,7 +5406,17 @@ export class CommandController extends Controller {
|
|||
// Create Keycloak
|
||||
const checkUser = await getUserByUsername(profile.citizenId);
|
||||
if (checkUser.length == 0) {
|
||||
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
|
||||
let password = profile.citizenId;
|
||||
if (profile.birthDate != null) {
|
||||
const gregorianYear = profile.birthDate.getFullYear() + 543;
|
||||
|
||||
const formattedDate =
|
||||
profile.birthDate.toISOString().slice(8, 10) +
|
||||
profile.birthDate.toISOString().slice(5, 7) +
|
||||
gregorianYear;
|
||||
password = formattedDate;
|
||||
}
|
||||
const userKeycloakId = await createUser(profile.citizenId, password, {
|
||||
firstName: profile.firstName,
|
||||
lastName: profile.lastName,
|
||||
// email: profile.email,
|
||||
|
|
|
|||
|
|
@ -2655,4 +2655,241 @@ export class ImportDataController extends Controller {
|
|||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
OrgRank(value: string) {
|
||||
switch (value.trim().toUpperCase()) {
|
||||
case "DEPARTMENT":
|
||||
return "หน่วยงาน";
|
||||
case "OFFICE":
|
||||
return "ส่วนราชการระดับกอง/สำนักงาน หรือเทียบเท่า";
|
||||
case "DIVISION":
|
||||
return "ส่วนราชการระดับส่วน/กลุ่มภารกิจ";
|
||||
case "SECTION":
|
||||
return "ส่วนราชการระดับฝ่าย/กลุ่มงาน หรือเทียบเท่า";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
OrgRankSub(value: string) {
|
||||
switch (value.trim().toUpperCase()) {
|
||||
case "BUREAU":
|
||||
return "สำนัก";
|
||||
case "OFFICE":
|
||||
return "สำนักงาน";
|
||||
case "DISTRICT":
|
||||
return "สำนักงานเขต";
|
||||
case "DIVISION":
|
||||
return "กอง";
|
||||
case "INSTITUTION":
|
||||
return "สถาบัน";
|
||||
case "HOSPITAL":
|
||||
return "โรงพยาบาล";
|
||||
case "CENTER":
|
||||
return "ศูนย์";
|
||||
case "MEDICAL":
|
||||
return "ศูนย์บริการการแพทย์";
|
||||
case "HEALTHMAJOR":
|
||||
return "ศูนย์บริการสาธารณสุข";
|
||||
case "UNIT":
|
||||
return "หน่วย";
|
||||
case "SECTION":
|
||||
return "ส่วน";
|
||||
case "FACTION":
|
||||
return "ฝ่าย";
|
||||
case "GROUPWORK":
|
||||
return "กลุ่มงาน";
|
||||
case "HEALTHBRANCH":
|
||||
return "ศูนย์บริการสาธารณสุขสาขา";
|
||||
case "TRAINING":
|
||||
return "ศูนย์ฝึกอาชีพ";
|
||||
case "SCHOOL":
|
||||
return "โรงเรียนฝึกอาชีพ";
|
||||
case "ELDERLY":
|
||||
return "บ้านพักผู้สูงอายุ";
|
||||
case "PARK":
|
||||
return "สวนสาธารณะ";
|
||||
case "FIRESTATION":
|
||||
return "สถานีดับเพลิง";
|
||||
case "WORK":
|
||||
return "งาน";
|
||||
case "PRIMARYSCHOOL":
|
||||
return "โรงเรียนประถมศึกษา";
|
||||
case "SECONDARYSCHOOL":
|
||||
return "โรงเรียนมัธยมศึกษา";
|
||||
case "MISSION":
|
||||
return "กลุ่มภารกิจ";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @summary Import Org
|
||||
*/
|
||||
@Post("ExportOrg")
|
||||
async ExportOrg(@Request() request: { user: Record<string, any> }) {
|
||||
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true },
|
||||
// where: { id: "30e594c9-a65b-485e-a4c5-71aa497e6b8a" },
|
||||
});
|
||||
if (orgRevision == null) return new HttpSuccess();
|
||||
//create root
|
||||
const orgRaw = await this.orgRootRepo.find({
|
||||
where: { orgRevisionId: orgRevision.id },
|
||||
order: {
|
||||
orgRootOrder: "ASC",
|
||||
},
|
||||
});
|
||||
let order = 1;
|
||||
let result = [];
|
||||
for await (const item of orgRaw) {
|
||||
console.log(item.orgRootOrder);
|
||||
const data = {
|
||||
ORDER: order,
|
||||
HRMS_DEP_CODE: "",
|
||||
HRMS_DIV_CODE: "",
|
||||
DEPARTMENT_CODE: item.DEPARTMENT_CODE,
|
||||
DIVISION_CODE: item.DIVISION_CODE,
|
||||
SECTION_CODE: item.SECTION_CODE,
|
||||
JOB_CODE: item.JOB_CODE,
|
||||
orgRoot: item.orgRootName,
|
||||
orgChild1: "",
|
||||
orgChild2: "",
|
||||
orgChild3: "",
|
||||
orgChild4: "",
|
||||
orgShortname: item.orgRootShortName,
|
||||
orgRank: this.OrgRank(item.orgRootRank),
|
||||
orgSubRank: this.OrgRankSub(item.orgRootRankSub),
|
||||
};
|
||||
await result.push(data);
|
||||
order++;
|
||||
const org1Raw = await this.orgChild1Repo.find({
|
||||
where: { orgRevisionId: orgRevision.id, orgRootId: item.id },
|
||||
order: {
|
||||
orgChild1Order: "ASC",
|
||||
},
|
||||
relations: ["orgRoot"],
|
||||
});
|
||||
for await (const item1 of org1Raw) {
|
||||
const data1 = {
|
||||
ORDER: order,
|
||||
HRMS_DEP_CODE: "",
|
||||
HRMS_DIV_CODE: "",
|
||||
DEPARTMENT_CODE: item1.DEPARTMENT_CODE,
|
||||
DIVISION_CODE: item1.DIVISION_CODE,
|
||||
SECTION_CODE: item1.SECTION_CODE,
|
||||
JOB_CODE: item1.JOB_CODE,
|
||||
orgRoot: item1.orgRoot.orgRootName,
|
||||
orgChild1: item1.orgChild1Name,
|
||||
orgChild2: "",
|
||||
orgChild3: "",
|
||||
orgChild4: "",
|
||||
orgShortname: item1.orgChild1ShortName,
|
||||
orgRank: this.OrgRank(item1.orgChild1Rank),
|
||||
orgSubRank: this.OrgRankSub(item1.orgChild1RankSub),
|
||||
};
|
||||
await result.push(data1);
|
||||
order++;
|
||||
const org2Raw = await this.orgChild2Repo.find({
|
||||
where: { orgRevisionId: orgRevision.id, orgRootId: item.id, orgChild1Id: item1.id },
|
||||
order: {
|
||||
orgChild2Order: "ASC",
|
||||
},
|
||||
relations: ["orgRoot", "orgChild1"],
|
||||
});
|
||||
for await (const item2 of org2Raw) {
|
||||
const data2 = {
|
||||
ORDER: order,
|
||||
HRMS_DEP_CODE: "",
|
||||
HRMS_DIV_CODE: "",
|
||||
DEPARTMENT_CODE: item2.DEPARTMENT_CODE,
|
||||
DIVISION_CODE: item2.DIVISION_CODE,
|
||||
SECTION_CODE: item2.SECTION_CODE,
|
||||
JOB_CODE: item2.JOB_CODE,
|
||||
orgRoot: item2.orgRoot.orgRootName,
|
||||
orgChild1: item2.orgChild1.orgChild1Name,
|
||||
orgChild2: item2.orgChild2Name,
|
||||
orgChild3: "",
|
||||
orgChild4: "",
|
||||
orgShortname: item2.orgChild2ShortName,
|
||||
orgRank: this.OrgRank(item2.orgChild2Rank),
|
||||
orgSubRank: this.OrgRankSub(item2.orgChild2RankSub),
|
||||
};
|
||||
await result.push(data2);
|
||||
order++;
|
||||
const org3Raw = await this.orgChild3Repo.find({
|
||||
where: {
|
||||
orgRevisionId: orgRevision.id,
|
||||
orgRootId: item.id,
|
||||
orgChild1Id: item1.id,
|
||||
orgChild2Id: item2.id,
|
||||
},
|
||||
order: {
|
||||
orgChild3Order: "ASC",
|
||||
},
|
||||
relations: ["orgRoot", "orgChild1", "orgChild2"],
|
||||
});
|
||||
for await (const item3 of org3Raw) {
|
||||
const data3 = {
|
||||
ORDER: order,
|
||||
HRMS_DEP_CODE: "",
|
||||
HRMS_DIV_CODE: "",
|
||||
DEPARTMENT_CODE: item3.DEPARTMENT_CODE,
|
||||
DIVISION_CODE: item3.DIVISION_CODE,
|
||||
SECTION_CODE: item3.SECTION_CODE,
|
||||
JOB_CODE: item3.JOB_CODE,
|
||||
orgRoot: item3.orgRoot.orgRootName,
|
||||
orgChild1: item3.orgChild1.orgChild1Name,
|
||||
orgChild2: item3.orgChild2.orgChild2Name,
|
||||
orgChild3: item3.orgChild3Name,
|
||||
orgChild4: "",
|
||||
orgShortname: item3.orgChild3ShortName,
|
||||
orgRank: this.OrgRank(item3.orgChild3Rank),
|
||||
orgSubRank: this.OrgRankSub(item3.orgChild3RankSub),
|
||||
};
|
||||
await result.push(data3);
|
||||
order++;
|
||||
const org4Raw = await this.orgChild4Repo.find({
|
||||
where: {
|
||||
orgRevisionId: orgRevision.id,
|
||||
orgRootId: item.id,
|
||||
orgChild1Id: item1.id,
|
||||
orgChild2Id: item2.id,
|
||||
orgChild3Id: item3.id,
|
||||
},
|
||||
order: {
|
||||
orgChild4Order: "ASC",
|
||||
},
|
||||
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3"],
|
||||
});
|
||||
for await (const item4 of org4Raw) {
|
||||
const data4 = {
|
||||
ORDER: order,
|
||||
HRMS_DEP_CODE: "",
|
||||
HRMS_DIV_CODE: "",
|
||||
DEPARTMENT_CODE: item4.DEPARTMENT_CODE,
|
||||
DIVISION_CODE: item4.DIVISION_CODE,
|
||||
SECTION_CODE: item4.SECTION_CODE,
|
||||
JOB_CODE: item4.JOB_CODE,
|
||||
orgRoot: item4.orgRoot.orgRootName,
|
||||
orgChild1: item4.orgChild1.orgChild1Name,
|
||||
orgChild2: item4.orgChild2.orgChild2Name,
|
||||
orgChild3: item4.orgChild3.orgChild3Name,
|
||||
orgChild4: item4.orgChild4Name,
|
||||
orgShortname: item4.orgChild4ShortName,
|
||||
orgRank: this.OrgRank(item4.orgChild4Rank),
|
||||
orgSubRank: this.OrgRankSub(item4.orgChild4RankSub),
|
||||
};
|
||||
await result.push(data4);
|
||||
order++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new HttpSuccess({
|
||||
template: "exportRawOrg",
|
||||
reportName: "exportRawOrg",
|
||||
data: { data: result },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,25 +232,10 @@ export class ProfileSalaryController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const record = await this.salaryRepo.find({
|
||||
where: {
|
||||
profileId: profile.id,
|
||||
// commandCode: In(["5", "6", "7"])
|
||||
commandCode: In([
|
||||
"0",
|
||||
"9",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"8",
|
||||
"10",
|
||||
"11",
|
||||
"12",
|
||||
"13",
|
||||
"14",
|
||||
"15",
|
||||
"16",
|
||||
]),
|
||||
where: {
|
||||
profileId: profile.id,
|
||||
// commandCode: In(["5", "6", "7"])
|
||||
commandCode: In(["5", "6", "7"]),
|
||||
},
|
||||
order: { order: "ASC" },
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue