no message

This commit is contained in:
kittapath 2024-10-09 16:20:43 +07:00
parent 428ed28b64
commit 7b83f91d73
7 changed files with 185 additions and 36 deletions

View file

@ -121,6 +121,7 @@ export class CommandController extends Controller {
*/ */
@Get("list") @Get("list")
async GetResult( async GetResult(
@Request() request: RequestWithUser,
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query() keyword: string = "", @Query() keyword: string = "",
@ -130,6 +131,9 @@ export class CommandController extends Controller {
) { ) {
const [commands, total] = await this.commandRepository const [commands, total] = await this.commandRepository
.createQueryBuilder("command") .createQueryBuilder("command")
.andWhere("command.createdUserId = :createdUserId", {
createdUserId: request.user.sub,
})
.andWhere( .andWhere(
status != null && status != undefined && status != "" status != null && status != undefined && status != ""
? "command.status IN (:...status)" ? "command.status IN (:...status)"

View file

@ -4828,6 +4828,7 @@ export class ProfileController extends Controller {
const isProbation: boolean = true; const isProbation: boolean = true;
const [findProfile, total] = await AppDataSource.getRepository(Profile) const [findProfile, total] = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.profileSalary", "profileSalary")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType") .leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.current_holders", "current_holders") .leftJoinAndSelect("profile.current_holders", "current_holders")
@ -4942,6 +4943,10 @@ export class ProfileController extends Controller {
lastName: item.lastName, lastName: item.lastName,
position: item.position, position: item.position,
idcard: item.citizenId, idcard: item.citizenId,
refCommandNo:
item.profileSalary.sort((a, b) => b.order - a.order).length == 0
? null
: item.profileSalary.sort((a, b) => b.order - a.order)[0].refCommandNo,
posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName, posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName,
posTypeName: item.posType == null ? null : item.posType.posTypeName, posTypeName: item.posType == null ? null : item.posType.posTypeName,
posNo: posMaster == null ? null : `${posMaster.posMasterNo}${shortName}`, posNo: posMaster == null ? null : `${posMaster.posMasterNo}${shortName}`,

View file

@ -7,6 +7,9 @@ import HttpSuccess from "../interfaces/http-success";
import { Workflow } from "../entities/Workflow"; import { Workflow } from "../entities/Workflow";
import { State } from "../entities/State"; import { State } from "../entities/State";
import { StateOperator } from "../entities/StateOperator"; import { StateOperator } from "../entities/StateOperator";
import { StateOperatorUser } from "../entities/StateOperatorUser";
import CallAPI from "../interfaces/call-api";
import { Profile } from "../entities/Profile";
@Route("api/v1/org/workflow") @Route("api/v1/org/workflow")
@Tags("AuthRole") @Tags("AuthRole")
@ -15,6 +18,56 @@ export class WorkflowController extends Controller {
private workflowRepo = AppDataSource.getRepository(Workflow); private workflowRepo = AppDataSource.getRepository(Workflow);
private stateRepo = AppDataSource.getRepository(State); private stateRepo = AppDataSource.getRepository(State);
private stateOperatorRepo = AppDataSource.getRepository(StateOperator); private stateOperatorRepo = AppDataSource.getRepository(StateOperator);
private stateOperatorUserRepo = AppDataSource.getRepository(StateOperatorUser);
private profileRepo = AppDataSource.getRepository(Profile);
@Post("check-workflow")
public async checkWorkflow(
@Request() req: RequestWithUser,
@Body()
body: {
sysName: string;
posLevelName: string;
posTypeName: string;
profiles: {
profile: string;
operator: string;
order: number;
}[];
},
) {
const workflow = await this.workflowRepo.findOne({
where: {
sysName: body.sysName,
posLevelName: body.posLevelName,
posTypeName: body.posTypeName,
},
relations: ["states"],
});
if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบกระบวนการนี้ได้");
await Promise.all(
body.profiles.map(async (item) => {
const operatoeUser = new StateOperatorUser();
operatoeUser.profile = item.profile;
operatoeUser.operator = item.operator.trim().toLocaleUpperCase();
operatoeUser.order = item.order;
operatoeUser.workflowId = workflow.id;
operatoeUser.createdUserId = req.user.sub;
operatoeUser.createdFullName = req.user.name;
operatoeUser.createdAt = new Date();
operatoeUser.lastUpdateUserId = req.user.sub;
operatoeUser.lastUpdateFullName = req.user.name;
operatoeUser.lastUpdatedAt = new Date();
await this.stateOperatorUserRepo.save(operatoeUser);
}),
);
return new HttpSuccess({
workflowId: workflow.id,
stateId: workflow.states.sort((a, b) => a.order - b.order)[0].id,
// stateName: workflow.states.sort((a, b) => a.order - b.order)[0].name,
// stateType: workflow.states.sort((a, b) => a.order - b.order)[0].type,
});
}
@Post("check-iscan") @Post("check-iscan")
public async checkIsCan( public async checkIsCan(
@ -23,20 +76,29 @@ export class WorkflowController extends Controller {
body: { body: {
workflowId: string; workflowId: string;
stateId: string; stateId: string;
operator: string; profile: string;
action: string; action: string;
}, },
) { ) {
const stateOperatorUser = await this.stateOperatorUserRepo.findOne({
where: {
profile: body.profile,
workflowId: body.workflowId,
},
});
if (!stateOperatorUser)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้");
const operator = await this.stateOperatorRepo.findOne({ const operator = await this.stateOperatorRepo.findOne({
where: { where: {
operator: body.operator, operator: stateOperatorUser.operator,
state: { id: body.stateId, workflow: { id: body.workflowId } }, state: { id: body.stateId, workflow: { id: body.workflowId } },
}, },
}); });
if (!operator) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!operator) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
let isCan = false; let isCan = false;
switch (body.action) { switch (body.action.trim().toLocaleUpperCase()) {
case "VIEW": case "VIEW":
isCan = operator.canView; isCan = operator.canView;
case "UPDATE": case "UPDATE":
@ -63,32 +125,38 @@ export class WorkflowController extends Controller {
} }
} }
@Post("check-workflow") @Post("check-iscan-all")
public async checkWorkflow( public async checkIsCanAll(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() @Body()
body: { body: {
sysName: string; workflowId: string;
posLevelName: string; stateId: string;
posTypeName: string;
}, },
) { ) {
const workflow = await this.workflowRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { where: {
sysName: body.sysName, keycloak: req.user.sub,
posLevelName: body.posLevelName,
posTypeName: body.posTypeName,
}, },
relations: ["states"],
}); });
if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const stateOperatorUser = await this.stateOperatorUserRepo.findOne({
where: {
profile: profile.id,
workflowId: body.workflowId,
},
});
if (!stateOperatorUser)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้");
return new HttpSuccess({ const operator = await this.stateOperatorRepo.findOne({
workflowId: workflow.id, where: {
stateId: workflow.states.sort((a, b) => a.order - b.order)[0].id, operator: stateOperatorUser.operator,
stateName: workflow.states.sort((a, b) => a.order - b.order)[0].name, state: { id: body.stateId, workflow: { id: body.workflowId } },
stateType: workflow.states.sort((a, b) => a.order - b.order)[0].type, },
}); });
if (!operator) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess(operator);
} }
@Post("state-next") @Post("state-next")
@ -103,6 +171,7 @@ export class WorkflowController extends Controller {
where: { where: {
id: body.stateId, id: body.stateId,
}, },
relations: ["stateOperators", "workflow", "workflow.stateOperatorUsers"],
}); });
if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const _state = await this.stateRepo.findOne({ const _state = await this.stateRepo.findOne({
@ -110,7 +179,43 @@ export class WorkflowController extends Controller {
order: state.order + 1, order: state.order + 1,
workflowId: state.workflowId, workflowId: state.workflowId,
}, },
relations: ["stateOperators"],
}); });
//noti
let profileNow = state.workflow.stateOperatorUsers
.filter((x) => state.stateOperators.map((s) => s.operator).includes(x.operator))
.map((x) => x.profile);
await new CallAPI()
.PostData(req, "/placement/noti/profiles", {
subject: `รายการถูกส่ง`,
body: `รายการถูกส่ง`,
receiverUserId: profileNow,
payload: "", //แนบไฟล์
isSendMail: true,
isSendInbox: true,
receiveDate: new Date(),
})
.catch((error) => {
console.error("Error calling API:", error);
});
if (_state != null) {
let profileNext = state.workflow.stateOperatorUsers
.filter((x) => _state.stateOperators.map((s) => s.operator).includes(x.operator))
.map((x) => x.profile);
await new CallAPI()
.PostData(req, "/placement/noti/profiles", {
subject: `ได้รับรายการ`,
body: `ได้รับรายการ`,
receiverUserId: profileNext,
payload: "", //แนบไฟล์
isSendMail: true,
isSendInbox: true,
receiveDate: new Date(),
})
.catch((error) => {
console.error("Error calling API:", error);
});
}
return new HttpSuccess({ return new HttpSuccess({
stateId: _state?.id || null, stateId: _state?.id || null,

View file

@ -72,7 +72,4 @@ export class StateOperator extends EntityBase {
@ManyToOne(() => State, (state) => state.stateOperators) @ManyToOne(() => State, (state) => state.stateOperators)
@JoinColumn({ name: "stateId" }) @JoinColumn({ name: "stateId" })
state: State; state: State;
@OneToMany(() => StateOperatorUser, (stateOperatorUser) => stateOperatorUser.stateOperator)
stateOperatorUsers: StateOperatorUser[];
} }

View file

@ -5,6 +5,14 @@ import { Workflow } from "./Workflow";
@Entity("stateOperatorUser") @Entity("stateOperatorUser")
export class StateOperatorUser extends EntityBase { export class StateOperatorUser extends EntityBase {
@Column({
nullable: true,
comment: "ผู้ดำเนินการ",
length: 255,
default: null,
})
operator: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "", comment: "",
@ -13,30 +21,30 @@ export class StateOperatorUser extends EntityBase {
}) })
profile: string; profile: string;
@Column({
nullable: true,
comment: "",
length: 255,
default: null,
})
type: string; //commander
@Column({ @Column({
nullable: true, nullable: true,
comment: "ลำดับ", comment: "ลำดับ",
default: null, default: null,
}) })
order: number; // order: number;
@Column({
nullable: true,
comment: "ผู้ดำเนินการ",
length: 255,
default: null,
})
refId: string;
@Column({ @Column({
nullable: true, nullable: true,
length: 40, length: 40,
comment: "คีย์นอก(FK)ของตาราง stateOperator", comment: "คีย์นอก(FK)ของตาราง workflow",
default: null, default: null,
}) })
stateOperatorId: string; workflowId: string;
@ManyToOne(() => StateOperator, (stateOperator) => stateOperator.stateOperatorUsers) @ManyToOne(() => Workflow, (workflow) => workflow.stateOperatorUsers)
@JoinColumn({ name: "stateOperatorId" }) @JoinColumn({ name: "workflowId" })
stateOperator: StateOperator; workflow: Workflow;
} }

View file

@ -1,6 +1,7 @@
import { Entity, Column, OneToMany } from "typeorm"; import { Entity, Column, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { State } from "./State"; import { State } from "./State";
import { StateOperatorUser } from "./StateOperatorUser";
@Entity("workflow") @Entity("workflow")
export class Workflow extends EntityBase { export class Workflow extends EntityBase {
@ -46,4 +47,7 @@ export class Workflow extends EntityBase {
default: null, default: null,
}) })
posTypeName: string; posTypeName: string;
@OneToMany(() => StateOperatorUser, (stateOperatorUser) => stateOperatorUser.workflow)
stateOperatorUsers: StateOperatorUser[];
} }

View file

@ -0,0 +1,26 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableWorkflow31728465477520 implements MigrationInterface {
name = 'AddTableWorkflow31728465477520'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP FOREIGN KEY \`FK_bef7391c37f03a3b809406beebf\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`stateOperatorId\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`type\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`operator\` varchar(255) NULL COMMENT 'ผู้ดำเนินการ'`);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`refId\` varchar(255) NULL COMMENT 'ผู้ดำเนินการ'`);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`workflowId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง workflow'`);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD CONSTRAINT \`FK_9499ff9ae0444f59f19800aca05\` FOREIGN KEY (\`workflowId\`) REFERENCES \`workflow\`(\`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_9499ff9ae0444f59f19800aca05\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`workflowId\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`refId\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`operator\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`type\` varchar(255) NULL`);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`stateOperatorId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง stateOperator'`);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD CONSTRAINT \`FK_bef7391c37f03a3b809406beebf\` FOREIGN KEY (\`stateOperatorId\`) REFERENCES \`stateOperator\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
}