2024-09-05 13:59:43 +07:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Post,
|
|
|
|
|
Route,
|
|
|
|
|
Security,
|
|
|
|
|
Tags,
|
|
|
|
|
Body,
|
|
|
|
|
Request,
|
|
|
|
|
SuccessResponse,
|
|
|
|
|
Response,
|
|
|
|
|
Get,
|
|
|
|
|
Query,
|
|
|
|
|
} from "tsoa";
|
|
|
|
|
import { AppDataSource } from "../database/data-source";
|
|
|
|
|
import HttpSuccess from "../interfaces/http-success";
|
|
|
|
|
import HttpStatusCode from "../interfaces/http-status";
|
|
|
|
|
import HttpError from "../interfaces/http-error";
|
|
|
|
|
import { RequestWithUser } from "../middlewares/user";
|
|
|
|
|
import { setLogDataDiff } from "../interfaces/utils";
|
|
|
|
|
import { Personal, PostPersonal } from "../entities/Personal";
|
|
|
|
|
import permission from "../interfaces/permission";
|
|
|
|
|
import { Assign } from "../entities/Assign";
|
|
|
|
|
|
2024-09-05 16:56:22 +07:00
|
|
|
@Route("api/v1/probation/personal")
|
2024-09-05 13:59:43 +07:00
|
|
|
@Tags("Personal")
|
|
|
|
|
@Security("bearerAuth")
|
|
|
|
|
@Response(
|
|
|
|
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
2024-10-08 17:54:23 +07:00
|
|
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
2024-09-05 13:59:43 +07:00
|
|
|
)
|
|
|
|
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
|
|
|
|
export class PersonalController extends Controller {
|
|
|
|
|
private personalRepository = AppDataSource.getRepository(Personal);
|
|
|
|
|
private assignRepository = AppDataSource.getRepository(Assign);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API ข้อมูลบุคคลในระบบทดลองงาน
|
|
|
|
|
*
|
|
|
|
|
* @summary เพิ่มคนเข้าระบบทดลองงาน
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Post("add")
|
2024-10-08 17:54:23 +07:00
|
|
|
async AddPersonal(
|
|
|
|
|
@Body() requestBody: PostPersonal,
|
|
|
|
|
@Request() request: RequestWithUser
|
|
|
|
|
) {
|
2024-09-05 13:59:43 +07:00
|
|
|
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
|
|
|
|
|
|
|
|
|
const checkPersonal: number = await this.personalRepository.count({
|
|
|
|
|
where: { personal_id: requestBody.id },
|
|
|
|
|
});
|
|
|
|
|
if (checkPersonal > 0) {
|
2024-10-08 17:54:23 +07:00
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.BAD_REQUEST,
|
|
|
|
|
"ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว"
|
|
|
|
|
);
|
2024-09-05 13:59:43 +07:00
|
|
|
}
|
|
|
|
|
|
2024-10-08 17:54:23 +07:00
|
|
|
let organization = await (requestBody.orgChild4Name
|
|
|
|
|
? requestBody.orgChild4Name + "/"
|
|
|
|
|
: "");
|
|
|
|
|
organization += await (requestBody.orgChild3Name
|
|
|
|
|
? requestBody.orgChild3Name + "/"
|
|
|
|
|
: "");
|
|
|
|
|
organization += await (requestBody.orgChild2Name
|
|
|
|
|
? requestBody.orgChild2Name + "/"
|
|
|
|
|
: "");
|
|
|
|
|
organization += await (requestBody.orgChild1Name
|
|
|
|
|
? requestBody.orgChild1Name + "/"
|
|
|
|
|
: "");
|
|
|
|
|
organization += await (requestBody.orgRootName
|
|
|
|
|
? requestBody.orgRootName
|
|
|
|
|
: "");
|
2024-09-05 13:59:43 +07:00
|
|
|
|
|
|
|
|
const personalData = Object.assign(new Personal());
|
|
|
|
|
personalData.personal_id = requestBody.id;
|
2024-10-08 17:54:23 +07:00
|
|
|
personalData.order_number = requestBody.order_number
|
|
|
|
|
? requestBody.order_number
|
|
|
|
|
: "";
|
2024-09-05 13:59:43 +07:00
|
|
|
personalData.probation_status = 1;
|
|
|
|
|
personalData.createdUserId = request.user.sub;
|
|
|
|
|
personalData.createdFullName = request.user.name;
|
|
|
|
|
personalData.updateUserId = request.user.sub;
|
|
|
|
|
personalData.updateFullName = request.user.name;
|
|
|
|
|
|
2024-10-08 17:54:23 +07:00
|
|
|
personalData.idcard = requestBody.idcard;
|
2024-09-05 13:59:43 +07:00
|
|
|
personalData.prefixName = requestBody.prefix;
|
|
|
|
|
personalData.firstName = requestBody.firstName;
|
|
|
|
|
personalData.lastName = requestBody.lastName;
|
|
|
|
|
personalData.isProbation = requestBody.isProbation ? 1 : 0;
|
2024-10-08 17:54:23 +07:00
|
|
|
personalData.positionLevelName = requestBody.posLevelName
|
|
|
|
|
? requestBody.posLevelName
|
|
|
|
|
: "";
|
|
|
|
|
personalData.positionName = requestBody.position
|
|
|
|
|
? requestBody.position
|
|
|
|
|
: "";
|
2024-09-05 13:59:43 +07:00
|
|
|
personalData.positionLineName = requestBody.posLineName;
|
|
|
|
|
personalData.positionTypeName = requestBody.posTypeName;
|
|
|
|
|
personalData.posNo = requestBody.posNo ? requestBody.posNo : "";
|
|
|
|
|
personalData.orgRootName = requestBody.orgRootName;
|
|
|
|
|
personalData.organization = organization;
|
|
|
|
|
|
|
|
|
|
const before = null;
|
|
|
|
|
const personal = await this.personalRepository.save(personalData, {
|
|
|
|
|
data: request,
|
|
|
|
|
});
|
|
|
|
|
setLogDataDiff(request, { before, after: personal });
|
|
|
|
|
|
|
|
|
|
return new HttpSuccess();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API รายการบุคคลในระบบทดลองงาน
|
|
|
|
|
*
|
|
|
|
|
* @summary รายชื่อคนที่อยู่ในระบบทดลองงาน
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Get("list")
|
2024-10-07 16:15:16 +07:00
|
|
|
async ListPersonal(
|
|
|
|
|
@Query() status: string = "",
|
|
|
|
|
@Query("page") page: number = 1,
|
|
|
|
|
@Query("pageSize") pageSize: number = 10,
|
|
|
|
|
@Request() request: RequestWithUser
|
|
|
|
|
) {
|
2024-09-05 13:59:43 +07:00
|
|
|
await new permission().PermissionList(request, "SYS_PROBATION");
|
2024-10-07 16:15:16 +07:00
|
|
|
const conditions: any = {};
|
|
|
|
|
if (status) {
|
|
|
|
|
conditions.probation_status = status;
|
|
|
|
|
}
|
2024-10-08 17:54:23 +07:00
|
|
|
|
2024-10-07 16:15:16 +07:00
|
|
|
const [lists, total] = await this.personalRepository.findAndCount({
|
2024-09-05 13:59:43 +07:00
|
|
|
order: { createdAt: "DESC" },
|
2024-10-07 16:15:16 +07:00
|
|
|
where: conditions,
|
|
|
|
|
skip: (page - 1) * pageSize,
|
|
|
|
|
take: pageSize,
|
2024-09-05 13:59:43 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!lists) {
|
2024-10-08 17:54:23 +07:00
|
|
|
throw new HttpError(
|
|
|
|
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
|
|
|
"ไม่สามารถแสดงข้อมูลได้"
|
|
|
|
|
);
|
2024-09-05 13:59:43 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let result: any = [];
|
|
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
|
lists.map(async (item, index) => {
|
|
|
|
|
const probation_no = await this.assignRepository.count({
|
2024-10-07 16:15:16 +07:00
|
|
|
where: {
|
|
|
|
|
personal_id: item.personal_id,
|
|
|
|
|
},
|
2024-09-05 13:59:43 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await result.push({
|
|
|
|
|
personal_id: item.personal_id,
|
|
|
|
|
ordering: index + 1,
|
|
|
|
|
name: item.prefixName + item.firstName + " " + item.lastName,
|
2024-10-08 17:54:23 +07:00
|
|
|
idcard: item.idcard,
|
|
|
|
|
prefixName: item.prefixName,
|
|
|
|
|
firstName: item.firstName,
|
|
|
|
|
lastName: item.lastName,
|
2024-09-05 13:59:43 +07:00
|
|
|
position_line: item.positionName,
|
|
|
|
|
position_level: item.positionLevelName,
|
|
|
|
|
position_type: item.positionTypeName,
|
|
|
|
|
organization: item.organization,
|
|
|
|
|
probation_no: probation_no,
|
|
|
|
|
order_number: item.order_number,
|
|
|
|
|
probation_status: item.probation_status,
|
|
|
|
|
});
|
2024-10-08 17:54:23 +07:00
|
|
|
})
|
2024-09-05 13:59:43 +07:00
|
|
|
);
|
|
|
|
|
|
2024-10-07 16:15:16 +07:00
|
|
|
return new HttpSuccess({ data: result, total: total });
|
2024-09-05 13:59:43 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API ข้อมูลบุคคลในระบบทดลองงาน
|
|
|
|
|
*
|
|
|
|
|
* @summary ข้อมูลคนที่อยูาในระบบทดลองงาน
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Get("")
|
2024-10-08 17:54:23 +07:00
|
|
|
async GetPersonal(
|
|
|
|
|
@Request() request: RequestWithUser,
|
|
|
|
|
@Query() personal_id: string
|
|
|
|
|
) {
|
2024-09-06 15:17:42 +07:00
|
|
|
await new permission().PermissionGet(request, "SYS_PROBATION");
|
2024-09-05 13:59:43 +07:00
|
|
|
const person = await this.personalRepository.findOne({
|
|
|
|
|
where: { personal_id: personal_id },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!person) {
|
2024-09-06 09:37:29 +07:00
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
2024-09-05 13:59:43 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const probation_no = await this.assignRepository.count({
|
|
|
|
|
where: { personal_id: person.personal_id },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await {
|
|
|
|
|
personal_id: person.personal_id,
|
|
|
|
|
name: person.prefixName + person.firstName + " " + person.lastName,
|
|
|
|
|
position_line: person.positionName,
|
|
|
|
|
position_level: person.positionLevelName,
|
|
|
|
|
position_type: person.positionTypeName,
|
|
|
|
|
organization: person.organization,
|
|
|
|
|
probation_no: probation_no,
|
|
|
|
|
order_number: person.order_number,
|
|
|
|
|
probation_status: person.probation_status,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new HttpSuccess(result);
|
|
|
|
|
}
|
|
|
|
|
}
|