Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-10-17 16:40:35 +07:00
commit bd3cb33a5e
8 changed files with 316 additions and 84 deletions

View file

@ -19,7 +19,7 @@ import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { Command } from "../entities/Command";
import { Brackets, LessThan, MoreThan, Double, In, Not ,Between } from "typeorm";
import { Brackets, LessThan, MoreThan, Double, In, Not, Between } from "typeorm";
import { CommandType } from "../entities/CommandType";
import { CommandSend } from "../entities/CommandSend";
import { Profile, CreateProfileAllFields } from "../entities/Profile";
@ -262,7 +262,7 @@ export class CommandController extends Controller {
commandYear: _data.commandYear,
commandAffectDate: _data.commandAffectDate,
commandExcecuteDate: _data.commandExcecuteDate,
assignFullName: _data.createdFullName,
assignFullName: null, //xxxxxxxxxxxxxxx
createdFullName: _data.createdFullName,
status: _data.status,
issue: _data.issue,
@ -1013,11 +1013,10 @@ export class CommandController extends Controller {
if (command.commandExcecuteDate == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล");
let profiles = command && command.commandRecives.length > 0
? command.commandRecives
.filter((x) => x.profileId != null)
.map((x) => x.profileId)
: [];
let profiles =
command && command.commandRecives.length > 0
? command.commandRecives.filter((x) => x.profileId != null).map((x) => x.profileId)
: [];
await new CallAPI()
.PostData(request, "/placement/noti/profiles", {
@ -1073,12 +1072,12 @@ export class CommandController extends Controller {
const command = await this.commandRepository.find({
relations: ["commandType", "commandRecives"],
where:{
where: {
commandExcecuteDate: Between(today, tomorrow),
status: "WAITING"
}
status: "WAITING",
},
});
const data = {
client_id: "gettoken",
client_secret: process.env.AUTH_ACCOUNT_SECRET,
@ -1100,27 +1099,27 @@ export class CommandController extends Controller {
]);
if (_data == null) {
return new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง");
}
}
command.forEach(async (x) => {
const path = this.commandTypePath(x.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
const msg = {
data: {
id: x.id,
status: "REPORTED",
lastUpdateUserId: "system",
lastUpdateFullName: "system",
// lastUpdateUserId: _data.user.sub,
// lastUpdateFullName: _data.user.name,
lastUpdatedAt: new Date(),
},
user: _data.user,
token: _data.access_token,
};
sendToQueue(msg);
})
const path = this.commandTypePath(x.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
const msg = {
data: {
id: x.id,
status: "REPORTED",
lastUpdateUserId: "system",
lastUpdateFullName: "system",
// lastUpdateUserId: _data.user.sub,
// lastUpdateFullName: _data.user.name,
lastUpdatedAt: new Date(),
},
user: _data.user,
token: _data.access_token,
};
sendToQueue(msg);
});
return new HttpSuccess();
}
@ -2286,7 +2285,7 @@ export class CommandController extends Controller {
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
lastName: profile.lastName,
email: profile.email,
// email: profile.email,
});
if (typeof userKeycloakId !== "string") {
throw new Error(userKeycloakId.errorMessage);
@ -2305,6 +2304,7 @@ export class CommandController extends Controller {
);
if (!result) throw new Error("Failed. Cannot set user's role.");
profile.keycloak = userKeycloakId;
profile.email = item.bodyProfile.email;
await this.profileRepository.save(profile);
setLogDataDiff(req, { before, after: profile });
}
@ -2773,7 +2773,7 @@ export class CommandController extends Controller {
case "C-PM-05":
return "/placement/appointment/appoint/report";
case "C-PM-06":
return "/placement/appointment/slip/report";
return "/placement/slip/report";
case "C-PM-07":
return "/placement/appointment/move/report";
case "C-PM-08":
@ -2781,7 +2781,7 @@ export class CommandController extends Controller {
case "C-PM-09":
return "/retirement/other/out/report";
case "C-PM-10":
return "/xxxxxx";
return "/probation/report/command10/officer/report";
case "C-PM-11":
return "/probation/report/command11/officer/report";
case "C-PM-12":
@ -2839,7 +2839,7 @@ export class CommandController extends Controller {
case "C-PM-38":
return "/org/command/command38/officer/report";
case "C-PM-39":
return "/placement/slip/report";
return "/placement/appointment/slip/report";
case "C-PM-40":
return "/org/command/command40/officer/report";
case "C-PM-41":

View file

@ -3,13 +3,25 @@ import { Controller, Example, Get, Path, Response, Route, SuccessResponse, Tags
import { DateTime } from "@elastic/elasticsearch/lib/api/types";
import { Double } from "typeorm";
import { AppDataSource } from "../database/data-source";
import { OrgRevision } from "../entities/OrgRevision";
import { Profile } from "../entities/Profile";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
interface DPISResponse {
/**
*
*/
status: number;
/**
*
*/
message: string;
/**
*
*/
result?: DPISResult;
}
@ -33,6 +45,7 @@ interface DPISResult {
educations: ProfileEducationResult[];
leaves: ProfileLeaveResult[];
salaries: ProfileSalaryResult[];
organization: ProfileOrgResult;
}
interface ProfileLeaveResult {
@ -42,6 +55,33 @@ interface ProfileLeaveResult {
totalLeave: number;
}
interface ProfileOrgResult {
/**
*
*/
orgRootName: string;
/**
* 1
*/
orgChild1Name: string;
/**
* 2
*/
orgChild2Name: string;
/**
* 3
*/
orgChild3Name: string;
/**
* 4
*/
orgChild4Name: string;
}
interface ProfileEducationResult {
country: string;
degree: string;
@ -70,6 +110,7 @@ interface ProfileSalaryResult {
@SuccessResponse(HttpStatus.OK, "สำเร็จ")
export class DPISController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
/**
*
@ -101,6 +142,13 @@ export class DPISController extends Controller {
leaveReason: null,
positionLevel: "ปฏิบัติงาน",
positionType: "ทั่วไป",
organization: {
orgRootName: "",
orgChild1Name: "",
orgChild2Name: "",
orgChild3Name: "",
orgChild4Name: "",
},
educations: [],
salaries: [
{
@ -144,8 +192,10 @@ export class DPISController extends Controller {
profileSalary: true,
profileEducations: true,
profileLeaves: true,
current_holders: true,
},
where: { citizenId: citizenId },
//relations: ["current_holders", "current_holders.orgRoot"],
order: {
profileSalary: {
date: "DESC",
@ -159,6 +209,10 @@ export class DPISController extends Controller {
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
var current_holder = profile.current_holders?.find((x) => x.orgRevisionId == findRevision?.id);
const mapProfile: DPISResult = {
citizenId: profile.citizenId,
@ -178,6 +232,14 @@ export class DPISController extends Controller {
positionLevel: profile.posLevel ? profile.posLevel.posLevelName : "",
positionType: profile.posType ? profile.posType.posTypeName : "",
organization: {
orgRootName: current_holder?.orgRoot?.orgRootName || "",
orgChild1Name: current_holder?.orgChild1?.orgChild1Name || "",
orgChild2Name: current_holder?.orgChild2?.orgChild2Name || "",
orgChild3Name: current_holder?.orgChild3?.orgChild3Name || "",
orgChild4Name: current_holder?.orgChild4?.orgChild4Name || "",
},
// educations
educations: profile.profileEducations.map((item) => {
return {

View file

@ -3514,10 +3514,10 @@ export class ProfileController extends Controller {
},
relations: ["orgChild1"],
});
if (posMasters == null || posMasters.orgRoot == null) {
if (posMasters == null || posMasters.orgChild1 == null) {
return new HttpSuccess(false);
}
return new HttpSuccess(posMasters);
return new HttpSuccess(posMasters.orgChild1.isOfficer);
}
/**
@ -3978,12 +3978,18 @@ export class ProfileController extends Controller {
// await new permission().PermissionOrgUserGet(request, "SYS_REGISTRY_OFFICER", id);//ไม่แน่ใจOFFปิดไว้ก่อน
const profile = await this.profileRepo.findOne({
where: { id: id },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot", "profileSalary"],
relations: [
"posLevel",
"posType",
"current_holders",
"current_holders.orgRoot",
"profileSalary",
],
order: {
profileSalary: {
order: "DESC",
}
}
},
},
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");

View file

@ -1,4 +1,4 @@
import { Body, Controller, Post, Request, Route, Security, Tags } from "tsoa";
import { Body, Controller, Get, Path, Post, Request, Route, Security, Tags } from "tsoa";
import { AppDataSource } from "../database/data-source";
import { RequestWithUser } from "../middlewares/user";
import HttpError from "../interfaces/http-error";
@ -14,6 +14,8 @@ import { StateUserComment } from "../entities/StateUserComment";
import { MetaWorkflow } from "../entities/MetaWorkflow";
import { MetaState } from "../entities/MetaState";
import { MetaStateOperator } from "../entities/MetaStateOperator";
import { PosMaster } from "../entities/PosMaster";
import { IsNull, Not } from "typeorm";
@Route("api/v1/org/workflow")
@Tags("Workflow")
@ -29,6 +31,7 @@ export class WorkflowController extends Controller {
private metaWorkflowRepo = AppDataSource.getRepository(MetaWorkflow);
private metaStateRepo = AppDataSource.getRepository(MetaState);
private metaStateOperatorRepo = AppDataSource.getRepository(MetaStateOperator);
private posMasterRepo = AppDataSource.getRepository(PosMaster);
@Post("add-workflow")
public async checkWorkflow(
@ -66,12 +69,19 @@ export class WorkflowController extends Controller {
lastUpdatedAt: new Date(),
};
const workflow = new Workflow();
Object.assign(workflow, { ...metaWorkflow, id: undefined, ...meta });
this.workflowRepo.save(workflow);
Object.assign(workflow, {
...metaWorkflow,
id: undefined,
...meta,
...body,
system: body.sysName,
});
await this.workflowRepo.save(workflow);
const metaState = await this.metaStateRepo.find({
where: {
metaWorkflowId: metaWorkflow.id,
},
order: { order: "ASC" },
});
await Promise.all(
@ -79,15 +89,19 @@ export class WorkflowController extends Controller {
const state = new State();
Object.assign(state, { ...item, id: undefined, workflowId: workflow.id, ...meta });
await this.stateRepo.save(state);
if (state.order == 1) {
workflow.stateId = state.id;
await this.workflowRepo.save(workflow);
}
const metaStateOperator = await this.metaStateOperatorRepo.find({
where: {
metaStateId: item.id,
},
});
await Promise.all(
metaStateOperator.map(async (item) => {
metaStateOperator.map(async (item1) => {
const stateOperator = new StateOperator();
Object.assign(stateOperator, { ...item, id: undefined, stateId: state.id, ...meta });
Object.assign(stateOperator, { ...item1, id: undefined, stateId: state.id, ...meta });
await this.stateOperatorRepo.save(stateOperator);
}),
);
@ -97,12 +111,46 @@ export class WorkflowController extends Controller {
const stateOperatorUser = new StateOperatorUser();
Object.assign(stateOperatorUser, {
profileId: profile.id,
operator: "OWNER",
operator: "Owner",
order: 1,
workflowId: workflow.id,
...meta,
});
await this.stateOperatorUserRepo.save(stateOperatorUser);
const profileOfficer = await this.posMasterRepo.find({
where: {
posMasterAssigns: { assignId: body.sysName },
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
relations: ["orgChild1"],
});
await Promise.all(
profileOfficer.map(async (item, i) => {
if (item.orgChild1 == null || item.orgChild1.isOfficer == false) {
const stateOperatorUser = new StateOperatorUser();
Object.assign(stateOperatorUser, {
profileId: item.current_holderId,
operator: "Officer",
order: i + 2,
workflowId: workflow.id,
...meta,
});
await this.stateOperatorUserRepo.save(stateOperatorUser);
} else {
const stateOperatorUser = new StateOperatorUser();
Object.assign(stateOperatorUser, {
profileId: item.current_holderId,
operator: "PersonnelOfficer",
order: i + 2,
workflowId: workflow.id,
...meta,
});
await this.stateOperatorUserRepo.save(stateOperatorUser);
}
}),
);
return new HttpSuccess();
}
@ -174,7 +222,7 @@ export class WorkflowController extends Controller {
const workflow = await this.workflowRepo.findOne({
where: {
refId: body.refId,
system: body.system,
sysName: body.system,
},
relations: ["stateOperatorUsers"],
});
@ -207,7 +255,7 @@ export class WorkflowController extends Controller {
where: {
workflow: {
refId: body.refId,
system: body.system,
sysName: body.system,
},
profile: {
keycloak: req.user.sub,
@ -217,7 +265,6 @@ export class WorkflowController extends Controller {
});
if (!stateOperatorUser)
throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้");
const operator = await this.stateOperatorRepo.findOne({
where: {
operator: stateOperatorUser.operator,
@ -225,8 +272,25 @@ export class WorkflowController extends Controller {
},
relations: ["state"],
});
if (!operator)
throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในขั้นตอนนี้");
if (!operator) {
const state = await this.stateRepo.findOne({
where: {
id: stateOperatorUser.workflow.stateId,
},
});
return new HttpSuccess({
stateId: state?.id || null,
stateNo: state?.order || null,
stateName: state?.name || null,
operator: stateOperatorUser.operator,
can_view: false,
can_update: false,
can_operate: false,
can_change_state: false,
can_delete: false,
can_cancel: false,
});
}
return new HttpSuccess({
stateId: operator.state.id,
stateNo: operator.state.order,
@ -254,17 +318,29 @@ export class WorkflowController extends Controller {
where: {
workflow: {
refId: body.refId,
system: body.system,
sysName: body.system,
},
},
order: { order: "ASC", stateUserComments: { order: "ASC" } },
relations: ["stateUserComments"],
relations: ["stateUserComments", "stateUserComments.profile"],
});
const _state = state.map((x) => ({
stateId: x.id,
stateNo: x.order,
stateName: x.name,
stateUserComments: x.stateUserComments,
stateUserComments: x.stateUserComments.map((x) => ({
id: x.id,
prefix: x.profile.prefix,
firstName: x.profile.firstName,
lastName: x.profile.lastName,
profileId: x.profileId,
isAcceptSetting: x.isAcceptSetting,
isApproveSetting: x.isApproveSetting,
isReasonSetting: x.isReasonSetting,
isAccept: x.isAccept,
isApprove: x.isApprove,
reason: x.reason,
})),
}));
return new HttpSuccess(_state);
}
@ -278,24 +354,35 @@ export class WorkflowController extends Controller {
system: string;
},
) {
const stateOperatorUser = await this.stateOperatorUserRepo.findOne({
const stateOperatorUserNow = await this.stateOperatorUserRepo.findOne({
where: {
workflow: {
refId: body.refId,
system: body.system,
sysName: body.system,
},
profile: {
keycloak: req.user.sub,
},
},
});
if (!stateOperatorUser)
throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้");
const stateOperatorUser = await this.stateOperatorUserRepo.find({
where: {
workflow: {
refId: body.refId,
sysName: body.system,
},
profile: {
keycloak: Not(req.user.sub),
},
operator: stateOperatorUserNow?.operator || "",
},
});
await this.stateOperatorUserRepo.remove(stateOperatorUser);
const workflow = await this.workflowRepo.findOne({
where: {
refId: body.refId,
system: body.system,
sysName: body.system,
},
relations: ["stateOperatorUsers"],
});
@ -538,4 +625,71 @@ export class WorkflowController extends Controller {
profileId: stateUserComment?.profileId || null,
});
}
/**
*
*
*/
@Get("commander")
async getProfilePlacement(@Request() req: RequestWithUser) {
const posMasterUser = await this.posMasterRepo.findOne({
where: {
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
current_holder: { keycloak: req.user.sub },
},
});
if (!posMasterUser || !posMasterUser.orgRootId)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบตำแหน่งผู้ใช้งาน");
const posMasters = await this.posMasterRepo.find({
where: {
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
isDirector: true,
current_holderId: Not(IsNull()),
orgRootId: posMasterUser.orgRootId,
},
relations: ["current_holder", "orgRoot"],
});
let _posMasters = posMasters.map((data) => ({
id: data.current_holderId,
prefix: data.current_holder.prefix,
firstName: data.current_holder.firstName,
lastName: data.current_holder.lastName,
position: data.current_holder.position,
posLevel: data.current_holder.posLevel,
posType: data.current_holder.posType,
orgRoot: data.orgRoot.orgRootName,
}));
return new HttpSuccess(_posMasters);
}
/**
* API
*
* @summary
*
*/
@Get("keycloak/isofficer/{system}")
async getIsOfficerByKeycloak(@Path() system: string, @Request() req: RequestWithUser) {
const profile = await this.profileRepo.findOne({
where: {
keycloak: req.user.sub,
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน");
const profileOfficer = await this.posMasterRepo.findOne({
where: {
posMasterAssigns: { assignId: system },
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
current_holderId: profile.id,
},
relations: ["orgChild1"],
});
if (!profileOfficer) return new HttpSuccess({ isOfficer: false, isStaff: false });
let isOfficer = profileOfficer.orgChild1 == null ? false : profileOfficer.orgChild1.isOfficer;
return new HttpSuccess({ isOfficer: isOfficer, isStaff: !isOfficer });
}
}

View file

@ -1,6 +1,5 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { StateOperator } from "./StateOperator";
import { Workflow } from "./Workflow";
import { Profile } from "./Profile";
@ -21,14 +20,6 @@ export class StateOperatorUser extends EntityBase {
})
order: number;
@Column({
nullable: true,
comment: "ผู้ดำเนินการ",
length: 255,
default: null,
})
refId: string;
@Column({
nullable: true,
length: 40,

View file

@ -13,14 +13,6 @@ export class Workflow extends EntityBase {
})
refId: string;
@Column({
nullable: true,
comment: "system",
length: 255,
default: null,
})
system: string;
@Column({
nullable: true,
comment: "ชื่อ flow",

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableWorkflow81729073909711 implements MigrationInterface {
name = 'AddTableWorkflow81729073909711'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`workflow\` DROP COLUMN \`system\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`refId\``);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`refId\` varchar(255) NULL COMMENT 'ผู้ดำเนินการ'`);
await queryRunner.query(`ALTER TABLE \`workflow\` ADD \`system\` varchar(255) NULL COMMENT 'system'`);
}
}