โครงสร้างเพิ่มอัพโหลด user
This commit is contained in:
parent
be703f8e3b
commit
422b0f3b87
7 changed files with 636 additions and 70 deletions
|
|
@ -11,6 +11,7 @@ import {
|
|||
Path,
|
||||
Request,
|
||||
Query,
|
||||
UploadedFile,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { In, Not } from "typeorm";
|
||||
|
|
@ -47,6 +48,10 @@ import { StrategyChild2 } from "../entities/StrategyChild2";
|
|||
import { StrategyChild3 } from "../entities/StrategyChild3";
|
||||
import { StrategyChild4 } from "../entities/StrategyChild4";
|
||||
import { StrategyChild5 } from "../entities/StrategyChild5";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import { UseInterceptors } from "@nestjs/common";
|
||||
import { FileInterceptor } from "@nestjs/platform-express";
|
||||
import * as xlsx from "xlsx";
|
||||
|
||||
@Route("api/v1/development/main")
|
||||
@Tags("Development")
|
||||
|
|
@ -1572,13 +1577,21 @@ export class DevelopmentController extends Controller {
|
|||
const getDevelopment = await this.developmentHistoryRepository.find({
|
||||
where: { developmentId: id },
|
||||
relations: ["posLevel", "posType", "employeePosLevel", "employeePosType"],
|
||||
order: {
|
||||
isDone: "ASC",
|
||||
citizenId: "ASC",
|
||||
},
|
||||
});
|
||||
const _getDevelopment = getDevelopment.map((item) => ({
|
||||
id: item.id,
|
||||
citizenId: item.citizenId,
|
||||
type: item.type,
|
||||
idcard: item.citizenId,
|
||||
fullName: item.prefix + item.firstName + " " + item.lastName,
|
||||
prefix: item.prefix,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
position: item.position,
|
||||
posType:
|
||||
posTypeName:
|
||||
item.type == "OFFICER"
|
||||
? item.posType
|
||||
? item.posType.posTypeName
|
||||
|
|
@ -1586,7 +1599,7 @@ export class DevelopmentController extends Controller {
|
|||
: item.employeePosType
|
||||
? item.employeePosType.posTypeName
|
||||
: null,
|
||||
posLevel:
|
||||
posLevelName:
|
||||
item.type == "OFFICER"
|
||||
? item.posLevel
|
||||
? item.posLevel.posLevelName
|
||||
|
|
@ -1595,14 +1608,63 @@ export class DevelopmentController extends Controller {
|
|||
? item.employeePosLevel.posLevelName
|
||||
: null,
|
||||
posExecutive: item.posExecutive,
|
||||
root: item.root,
|
||||
order: item.order,
|
||||
dateOrder: item.dateOrder,
|
||||
org: item.root,
|
||||
trainingDays: item.trainingDays,
|
||||
commandNumber: item.order,
|
||||
commandDate: item.dateOrder,
|
||||
isDone: item.isDone,
|
||||
}));
|
||||
return new HttpSuccess(_getDevelopment);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 ส่งบันทึกทะเบียนประวัติ
|
||||
*
|
||||
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 ส่งบันทึกทะเบียนประวัติ #
|
||||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
@Get("tab6/done/{id}")
|
||||
async GetDevelopemtTab6DoneById(
|
||||
@Path() id: string,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const getDevelopment = await this.developmentHistoryRepository.find({
|
||||
where: { developmentId: id, isDone: false, type: "OFFICER" },
|
||||
relations: ["development"],
|
||||
});
|
||||
await Promise.all(
|
||||
getDevelopment.map(async (x) => {
|
||||
const _data = Object.assign(new DevelopmentHistory(), x);
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/profile/training", {
|
||||
profileId: x.profileId,
|
||||
name: x.development == null ? null : x.development.projectName,
|
||||
topic: x.development == null ? null : x.development.topicAcademic,
|
||||
yearly: x.development == null ? null : x.development.year,
|
||||
place: x.development == null ? null : x.development.addressAcademic,
|
||||
duration: x.development == null ? null : x.development.totalDate,
|
||||
department: x.development == null ? null : x.development.root,
|
||||
numberOrder: x.order,
|
||||
dateOrder: x.dateOrder,
|
||||
startDate: x.development == null ? null : x.development.dateStart,
|
||||
endDate: x.development == null ? null : x.development.dateEnd,
|
||||
isDate: true,
|
||||
})
|
||||
.then((x) => {
|
||||
_data.isDone = true;
|
||||
})
|
||||
.catch((x) => {
|
||||
_data.isDone = false;
|
||||
});
|
||||
_data.lastUpdateUserId = request.user.sub;
|
||||
_data.lastUpdateFullName = request.user.name;
|
||||
await this.developmentHistoryRepository.save(_data);
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess(getDevelopment);
|
||||
}
|
||||
|
||||
/**
|
||||
* API list หน่วยงาน
|
||||
*
|
||||
|
|
@ -1630,48 +1692,93 @@ export class DevelopmentController extends Controller {
|
|||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
@Get("zxczxc/{id}")
|
||||
@Post("tab6/{id}")
|
||||
@UseInterceptors(FileInterceptor("file"))
|
||||
async UploadUserDevelopemtById(
|
||||
@Path() id: string,
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const getDevelopment = await this.developmentRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ["developmentHistory"],
|
||||
relations: {
|
||||
developmentHistorys: true,
|
||||
},
|
||||
});
|
||||
if (!getDevelopment) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
||||
}
|
||||
await this.developmentHistoryRepository.remove(getDevelopment.developmentHistorys);
|
||||
const workbook = xlsx.read(file.buffer, { type: "buffer" });
|
||||
const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet
|
||||
const sheet = workbook.Sheets[sheetName];
|
||||
const getDevelopments = xlsx.utils.sheet_to_json(sheet);
|
||||
|
||||
// await Promise.all(
|
||||
// positions.map(async (x) => {
|
||||
// const data = Object.assign(new DevelopmentHistory(), x);
|
||||
// if (x.posTypeId != null) {
|
||||
// const checkId = await this.posTypeRepository.findOne({
|
||||
// where: { id: x.posTypeId },
|
||||
// });
|
||||
// if (!checkId) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
|
||||
// }
|
||||
// }
|
||||
// if (x.posLevelId != null) {
|
||||
// const checkId = await this.posLevelRepository.findOne({
|
||||
// where: { id: x.posLevelId },
|
||||
// });
|
||||
// if (!checkId) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
|
||||
// }
|
||||
// }
|
||||
// data.developmentId = getDevelopment.id;
|
||||
// data.createdUserId = request.user.sub;
|
||||
// data.createdFullName = request.user.name;
|
||||
// data.lastUpdateUserId = request.user.sub;
|
||||
// data.lastUpdateFullName = request.user.name;
|
||||
// await this.plannedGoalPositionRepository.save(data);
|
||||
// }),
|
||||
// );
|
||||
|
||||
return new HttpSuccess();
|
||||
await Promise.all(
|
||||
getDevelopments.map(async (item: any) => {
|
||||
if (item["รหัสประจำตัวประชาชน"] == undefined || item["รหัสประจำตัวประชาชน"].length != 13)
|
||||
return;
|
||||
const oldProfile = getDevelopment.developmentHistorys.find(
|
||||
(x) => x.citizenId == item["รหัสประจำตัวประชาชน"],
|
||||
);
|
||||
if (oldProfile != null) return;
|
||||
if (item["ประเภท"] == undefined) return;
|
||||
if (item["ประเภท"] == "ข้าราชการกรุงเทพมหานครสามัญ") {
|
||||
await new CallAPI()
|
||||
.GetData(request, `org/unauthorize/officer/citizen/${item["รหัสประจำตัวประชาชน"]}`)
|
||||
.then(async (x: any) => {
|
||||
let development = Object.assign(new DevelopmentHistory(), x);
|
||||
development.order =
|
||||
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined
|
||||
? null
|
||||
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"];
|
||||
development.dateOrder =
|
||||
item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined
|
||||
? null
|
||||
: new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]);
|
||||
development.trainingDays =
|
||||
item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"];
|
||||
development.developmentId = id;
|
||||
development.createdUserId = request.user.sub;
|
||||
development.createdFullName = request.user.name;
|
||||
development.lastUpdateUserId = request.user.sub;
|
||||
development.lastUpdateFullName = request.user.name;
|
||||
await this.developmentHistoryRepository.save(development);
|
||||
})
|
||||
.catch((x) => {
|
||||
return;
|
||||
});
|
||||
} else {
|
||||
await new CallAPI()
|
||||
.GetData(request, `org/unauthorize/employee/citizen/${item["รหัสประจำตัวประชาชน"]}`)
|
||||
.then(async (x: any) => {
|
||||
let development = Object.assign(new DevelopmentHistory(), x);
|
||||
development.order =
|
||||
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined
|
||||
? null
|
||||
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"];
|
||||
development.dateOrder =
|
||||
item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined
|
||||
? null
|
||||
: new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]);
|
||||
development.trainingDays =
|
||||
item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"];
|
||||
development.posLevelId = null;
|
||||
development.posTypeId = null;
|
||||
development.employeePosLevelId = x.posLevelId;
|
||||
development.employeePosTypeId = x.posTypeId;
|
||||
development.developmentId = id;
|
||||
development.createdUserId = request.user.sub;
|
||||
development.createdFullName = request.user.name;
|
||||
development.lastUpdateUserId = request.user.sub;
|
||||
development.lastUpdateFullName = request.user.name;
|
||||
await this.developmentHistoryRepository.save(development);
|
||||
})
|
||||
.catch((x) => {
|
||||
return;
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess(getDevelopments);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue