no message

This commit is contained in:
kittapath 2024-11-19 10:43:25 +07:00
parent 8f0624d27b
commit b089d9279a
8 changed files with 374 additions and 88 deletions

View file

@ -3,7 +3,7 @@ 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 { In } from "typeorm";
import { In, LessThan } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { OrgChild1 } from "../entities/OrgChild1";
@ -11,6 +11,7 @@ import { OrgChild2 } from "../entities/OrgChild2";
import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
import Extension from "../interfaces/extension";
import HttpStatus from "../interfaces/http-status";
@Route("api/v1/org/report")
@Tags("Report")
@Security("bearerAuth")
@ -2843,6 +2844,189 @@ export class ReportController extends Controller {
return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } });
}
/**
* API Report2
*
* @summary Report2
*
*/
@Get("report2-history/{rootId}")
async findReport2History(@Path() rootId: string) {
const orgRootData = await this.orgRootRepository.find({
where: {
id: rootId,
},
order: { orgRootOrder: "ASC" },
relations: [
"orgRevision",
"posMasters",
"posMasters.orgRoot",
"posMasters.orgChild1",
"posMasters.orgChild2",
"posMasters.orgChild3",
"posMasters.orgChild4",
"posMasters.current_holder",
"posMasters.current_holder.posLevel",
"posMasters.current_holder.posType",
"posMasters.current_holder.profileSalary",
"posMasters.current_holder.profileEducations",
"posMasters.current_holder.current_holders",
"posMasters.current_holder.current_holders.positions",
"posMasters.current_holder.current_holders.orgRoot",
"posMasters.current_holder.current_holders.orgChild1",
"posMasters.current_holder.current_holders.orgChild2",
"posMasters.current_holder.current_holders.orgChild3",
"posMasters.current_holder.current_holders.orgChild4",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
"posMasters.positions.posExecutive",
],
});
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null;
const orgChild1Data = await this.child1Repository.find({
where: {
orgRootId: In(orgRootIds),
},
order: { orgChild1Order: "ASC" },
relations: [
"posMasters",
"posMasters.orgRoot",
"posMasters.orgChild1",
"posMasters.orgChild2",
"posMasters.orgChild3",
"posMasters.orgChild4",
"posMasters.current_holder",
"posMasters.current_holder.posLevel",
"posMasters.current_holder.posType",
"posMasters.current_holder.profileSalary",
"posMasters.current_holder.profileEducations",
"posMasters.current_holder.current_holders",
"posMasters.current_holder.current_holders.positions",
"posMasters.current_holder.current_holders.orgRoot",
"posMasters.current_holder.current_holders.orgChild1",
"posMasters.current_holder.current_holders.orgChild2",
"posMasters.current_holder.current_holders.orgChild3",
"posMasters.current_holder.current_holders.orgChild4",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
"posMasters.positions.posExecutive",
],
});
const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null;
const orgChild2Data = await this.child2Repository.find({
where: {
orgChild1: In(orgChild1Ids),
},
order: { orgChild2Order: "ASC" },
relations: [
"posMasters",
"posMasters.orgRoot",
"posMasters.orgChild1",
"posMasters.orgChild2",
"posMasters.orgChild3",
"posMasters.orgChild4",
"posMasters.current_holder",
"posMasters.current_holder.posLevel",
"posMasters.current_holder.posType",
"posMasters.current_holder.profileSalary",
"posMasters.current_holder.profileEducations",
"posMasters.current_holder.current_holders",
"posMasters.current_holder.current_holders.positions",
"posMasters.current_holder.current_holders.orgRoot",
"posMasters.current_holder.current_holders.orgChild1",
"posMasters.current_holder.current_holders.orgChild2",
"posMasters.current_holder.current_holders.orgChild3",
"posMasters.current_holder.current_holders.orgChild4",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
"posMasters.positions.posExecutive",
],
});
const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null;
const orgChild3Data = await this.child3Repository.find({
where: {
orgChild2: In(orgChild2Ids),
},
order: { orgChild3Order: "ASC" },
relations: [
"posMasters",
"posMasters.orgRoot",
"posMasters.orgChild1",
"posMasters.orgChild2",
"posMasters.orgChild3",
"posMasters.orgChild4",
"posMasters.current_holder",
"posMasters.current_holder.posLevel",
"posMasters.current_holder.posType",
"posMasters.current_holder.profileSalary",
"posMasters.current_holder.profileEducations",
"posMasters.current_holder.current_holders",
"posMasters.current_holder.current_holders.positions",
"posMasters.current_holder.current_holders.orgRoot",
"posMasters.current_holder.current_holders.orgChild1",
"posMasters.current_holder.current_holders.orgChild2",
"posMasters.current_holder.current_holders.orgChild3",
"posMasters.current_holder.current_holders.orgChild4",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
"posMasters.positions.posExecutive",
],
});
const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null;
const orgChild4Data = await this.child4Repository.find({
where: {
orgChild3: In(orgChild3Ids),
},
order: { orgChild4Order: "ASC" },
relations: [
"posMasters",
"posMasters.orgRoot",
"posMasters.orgChild1",
"posMasters.orgChild2",
"posMasters.orgChild3",
"posMasters.orgChild4",
"posMasters.current_holder",
"posMasters.current_holder.posLevel",
"posMasters.current_holder.posType",
"posMasters.current_holder.profileSalary",
"posMasters.current_holder.profileEducations",
"posMasters.current_holder.current_holders",
"posMasters.current_holder.current_holders.positions",
"posMasters.current_holder.current_holders.orgRoot",
"posMasters.current_holder.current_holders.orgChild1",
"posMasters.current_holder.current_holders.orgChild2",
"posMasters.current_holder.current_holders.orgChild3",
"posMasters.current_holder.current_holders.orgChild4",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
"posMasters.positions.posExecutive",
],
});
if (orgRootData.length < 0) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบโครงสร้าง");
const _orgRevisionActive = await this.orgRevisionRepository.find({
where: { createdAt: LessThan(orgRootData[0]?.createdAt ?? new Date()) },
order: { createdAt: "DESC" },
skip: 1,
relations: [
"posMasters",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
"posMasters.positions.posExecutive",
],
});
return new HttpSuccess();
}
/**
* API Report3
*
@ -4088,7 +4272,6 @@ export class ReportController extends Controller {
@Get("report4/{rootId}")
async findReport4(@Path() rootId: string) {
const orgRootData = await this.orgRootRepository.find({
where: {
id: rootId,
@ -4103,86 +4286,91 @@ export class ReportController extends Controller {
],
});
let data: any = [];
var _data = [{
type: "ทั่วไป",
level: "ปฎิบัติงาน",
total: "0",
remark: "-"
},
{
type: "",
level: "ชำนาญงาน",
total: "0",
remark: "-"
},
{
type: "",
level: "อาวุโส",
total: "0",
remark: "-"
},
{
type: "",
level: "รวม",
total: "0",
remark: ""
},
{
type: "วิชาการ",
level: "ปฎิบัติการ",
total: "0",
remark: "-"
},
{
type: "",
level: "ชำนาญการ",
total: "0",
remark: "-"
},
{
type: "",
level: "รวม",
total: "0",
remark: ""
},
{
type: "อำนวยการ",
level: "ต้น",
total: "0",
remark: "-"
},
{
type: "",
level: "สูง",
total: "0",
remark: "-"
},
{
type: "",
level: "รวม",
total: "0",
remark: ""
},
{
type: "บริหาร",
level: "ต้น",
total: "0",
remark: "-"
},
{
type: "",
level: "สูง",
total: "0",
remark: "-"
},
{
type: "",
level: "รวม",
total: "0",
remark: ""
}
]
var _data = [
{
type: "ทั่วไป",
level: "ปฎิบัติงาน",
total: "0",
remark: "-",
},
{
type: "",
level: "ชำนาญงาน",
total: "0",
remark: "-",
},
{
type: "",
level: "อาวุโส",
total: "0",
remark: "-",
},
{
type: "",
level: "รวม",
total: "0",
remark: "",
},
{
type: "วิชาการ",
level: "ปฎิบัติการ",
total: "0",
remark: "-",
},
{
type: "",
level: "ชำนาญการ",
total: "0",
remark: "-",
},
{
type: "",
level: "รวม",
total: "0",
remark: "",
},
{
type: "อำนวยการ",
level: "ต้น",
total: "0",
remark: "-",
},
{
type: "",
level: "สูง",
total: "0",
remark: "-",
},
{
type: "",
level: "รวม",
total: "0",
remark: "",
},
{
type: "บริหาร",
level: "ต้น",
total: "0",
remark: "-",
},
{
type: "",
level: "สูง",
total: "0",
remark: "-",
},
{
type: "",
level: "รวม",
total: "0",
remark: "",
},
];
data.push(_data);
return new HttpSuccess({ template: "report4", reportName: "report4", data: { dateCurrent: Extension.ToThaiShortDate(new Date()) , data: _data } });
return new HttpSuccess({
template: "report4",
reportName: "report4",
data: { dateCurrent: Extension.ToThaiShortDate(new Date()), data: _data },
});
}
}

View file

@ -21,6 +21,7 @@ import { PosMasterAct } from "../entities/PosMasterAct";
import { getAllJSDocTagsOfKind } from "typescript";
import { viewDirectorActing } from "../entities/view/viewDirectorActing";
import { viewDirector } from "../entities/view/viewDirector";
import { ProfileEmployee } from "../entities/ProfileEmployee";
@Route("api/v1/org/workflow")
@Tags("Workflow")
@ -32,6 +33,7 @@ export class WorkflowController extends Controller {
private stateOperatorUserRepo = AppDataSource.getRepository(StateOperatorUser);
private stateUserCommentRepo = AppDataSource.getRepository(StateUserComment);
private profileRepo = AppDataSource.getRepository(Profile);
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
private metaWorkflowRepo = AppDataSource.getRepository(MetaWorkflow);
private metaStateRepo = AppDataSource.getRepository(MetaState);
@ -51,12 +53,21 @@ export class WorkflowController extends Controller {
posTypeName: string;
},
) {
const profile = await this.profileRepo.findOne({
let profileType = "OFFICER";
let profile: any = await this.profileRepo.findOne({
where: {
keycloak: req.user.sub,
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน");
if (!profile) {
profileType = "EMPLOYEE";
profile = await this.profileEmployeeRepo.findOne({
where: {
keycloak: req.user.sub,
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน");
}
const metaWorkflow = await this.metaWorkflowRepo.findOne({
where: {
@ -81,6 +92,7 @@ export class WorkflowController extends Controller {
id: undefined,
...meta,
...body,
profileType: profileType,
system: body.sysName,
});
await this.workflowRepo.save(workflow);
@ -117,7 +129,9 @@ export class WorkflowController extends Controller {
const stateOperatorUser = new StateOperatorUser();
Object.assign(stateOperatorUser, {
profileId: profile.id,
profileId: profileType == "OFFICER" ? profile.id : null,
profileEmployeeId: profileType != "OFFICER" ? profile.id : null,
profileType: profileType,
operator: "Owner",
order: 1,
workflowId: workflow.id,
@ -205,14 +219,22 @@ export class WorkflowController extends Controller {
action: string;
},
) {
const stateOperatorUser = await this.stateOperatorUserRepo.findOne({
let stateOperatorUser = await this.stateOperatorUserRepo.findOne({
where: {
profileId: body.profileId,
workflowId: body.workflowId,
},
});
if (!stateOperatorUser)
throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้");
if (!stateOperatorUser) {
stateOperatorUser = await this.stateOperatorUserRepo.findOne({
where: {
profileEmployeeId: body.profileId,
workflowId: body.workflowId,
},
});
if (!stateOperatorUser)
throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้");
}
const operator = await this.stateOperatorRepo.findOne({
where: {

View file

@ -34,6 +34,7 @@ import { ProfileEdit } from "./ProfileEdit";
import { ProfileDevelopment } from "./ProfileDevelopment";
import { DevelopmentRequest } from "./DevelopmentRequest";
import { RoleKeycloak } from "./RoleKeycloak";
import { StateOperatorUser } from "./StateOperatorUser";
@Entity("profileEmployee")
export class ProfileEmployee extends EntityBase {
@ -695,6 +696,9 @@ export class ProfileEmployee extends EntityBase {
@OneToMany(() => ProfileFamilyCouple, (v) => v.profile)
profileFamilyCouple: ProfileFamilyCouple[];
@OneToMany(() => StateOperatorUser, (v) => v.profile)
stateOperatorUsers: StateOperatorUser[];
//ที่อยู่
@Column({
nullable: true,

View file

@ -13,6 +13,14 @@ export class RoleKeycloak extends EntityBase {
})
name: string;
@Column({
nullable: true,
comment: "คำอธิบาย",
length: 255,
default: null,
})
description: string;
@ManyToMany(() => Profile, (profile) => profile.roleKeycloaks)
profiles: Profile[];

View file

@ -2,6 +2,7 @@ import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { Workflow } from "./Workflow";
import { Profile } from "./Profile";
import { ProfileEmployee } from "./ProfileEmployee";
@Entity("stateOperatorUser")
export class StateOperatorUser extends EntityBase {
@ -13,6 +14,14 @@ export class StateOperatorUser extends EntityBase {
})
operator: string;
@Column({
nullable: true,
comment: "ผู้ใช้งาน",
length: 255,
default: null,
})
profileType: string;
@Column({
nullable: true,
comment: "ลำดับ",
@ -44,4 +53,17 @@ export class StateOperatorUser extends EntityBase {
@ManyToOne(() => Profile, (profile) => profile.stateOperatorUsers)
@JoinColumn({ name: "profileId" })
profile: Profile;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง profileEmployee",
type: "uuid",
default: null,
})
profileEmployeeId: string;
@ManyToOne(() => ProfileEmployee, (profileEmployee) => profileEmployee.stateOperatorUsers)
@JoinColumn({ name: "profileEmployeeId" })
profileEmployee: ProfileEmployee;
}

View file

@ -13,6 +13,14 @@ export class Workflow extends EntityBase {
})
refId: string;
@Column({
nullable: true,
comment: "ผู้ใช้งาน",
length: 255,
default: null,
})
profileType: string;
@Column({
nullable: true,
comment: "ชื่อ flow",

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdataWorkflowAddRmployee1731941837869 implements MigrationInterface {
name = 'UpdataWorkflowAddRmployee1731941837869'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`workflow\` ADD \`profileType\` varchar(255) NULL COMMENT 'ผู้ใช้งาน'`);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`profileType\` varchar(255) NULL COMMENT 'ผู้ใช้งาน'`);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง profileEmployee'`);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD CONSTRAINT \`FK_7039ce6f8c316e5bbdc879e801b\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP FOREIGN KEY \`FK_7039ce6f8c316e5bbdc879e801b\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`profileEmployeeId\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`profileType\``);
await queryRunner.query(`ALTER TABLE \`workflow\` DROP COLUMN \`profileType\``);
}
}

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdataWorkflowAddRmployee11731987222018 implements MigrationInterface {
name = 'UpdataWorkflowAddRmployee11731987222018'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`roleKeycloak\` ADD \`description\` varchar(255) NULL COMMENT 'คำอธิบาย'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`roleKeycloak\` DROP COLUMN \`description\``);
}
}