no message
This commit is contained in:
parent
5643cc67c4
commit
566ac716ee
3 changed files with 253 additions and 53 deletions
|
|
@ -30,6 +30,8 @@ import { CommandSalary } from "../entities/CommandSalary";
|
||||||
import { CommandRecive } from "../entities/CommandRecive";
|
import { CommandRecive } from "../entities/CommandRecive";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
import Extension from "../interfaces/extension";
|
import Extension from "../interfaces/extension";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
import CallAPI from "../interfaces/call-api";
|
||||||
|
|
||||||
@Route("api/v1/org/command")
|
@Route("api/v1/org/command")
|
||||||
@Tags("Command")
|
@Tags("Command")
|
||||||
|
|
@ -47,6 +49,7 @@ export class CommandController extends Controller {
|
||||||
private commandSalaryRepository = AppDataSource.getRepository(CommandSalary);
|
private commandSalaryRepository = AppDataSource.getRepository(CommandSalary);
|
||||||
private commandReciveRepository = AppDataSource.getRepository(CommandRecive);
|
private commandReciveRepository = AppDataSource.getRepository(CommandRecive);
|
||||||
private profileRepository = AppDataSource.getRepository(Profile);
|
private profileRepository = AppDataSource.getRepository(Profile);
|
||||||
|
private profileEmployeeRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||||
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
|
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -276,7 +279,7 @@ export class CommandController extends Controller {
|
||||||
prefix: x.prefix,
|
prefix: x.prefix,
|
||||||
firstName: x.firstName,
|
firstName: x.firstName,
|
||||||
lastName: x.lastName,
|
lastName: x.lastName,
|
||||||
profileId: x.profileId,
|
// profileId: x.profileId,
|
||||||
order: x.order,
|
order: x.order,
|
||||||
remarkVertical: x.remarkVertical,
|
remarkVertical: x.remarkVertical,
|
||||||
remarkHorizontal: x.remarkHorizontal,
|
remarkHorizontal: x.remarkHorizontal,
|
||||||
|
|
@ -858,6 +861,15 @@ export class CommandController extends Controller {
|
||||||
) {
|
) {
|
||||||
command.status = "WAITING";
|
command.status = "WAITING";
|
||||||
} else {
|
} else {
|
||||||
|
let path = this.commandTypePath(command.commandType.name);
|
||||||
|
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
||||||
|
|
||||||
|
new CallAPI()
|
||||||
|
.PostData(request, path + "excecute", {
|
||||||
|
refIds: command.commandRecives.map((x) => x.refId),
|
||||||
|
})
|
||||||
|
.then(async (res) => {})
|
||||||
|
.catch(() => {});
|
||||||
command.status = "REPORTED";
|
command.status = "REPORTED";
|
||||||
}
|
}
|
||||||
command.lastUpdateUserId = request.user.sub;
|
command.lastUpdateUserId = request.user.sub;
|
||||||
|
|
@ -875,7 +887,7 @@ export class CommandController extends Controller {
|
||||||
* @param {string} id Id คำสั่ง
|
* @param {string} id Id คำสั่ง
|
||||||
*/
|
*/
|
||||||
@Get("tab4/cover/{id}")
|
@Get("tab4/cover/{id}")
|
||||||
async GetByIdTab4Cover(@Path() id: string) {
|
async GetByIdTab4Cover(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
const command = await this.commandRepository.findOne({
|
const command = await this.commandRepository.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
relations: ["commandType"],
|
relations: ["commandType"],
|
||||||
|
|
@ -918,38 +930,230 @@ export class CommandController extends Controller {
|
||||||
* @param {string} id Id คำสั่ง
|
* @param {string} id Id คำสั่ง
|
||||||
*/
|
*/
|
||||||
@Get("tab4/attachment/{id}")
|
@Get("tab4/attachment/{id}")
|
||||||
async GetByIdTab4Attachment(@Path() id: string) {
|
async GetByIdTab4Attachment(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
const command = await this.commandRepository.findOne({
|
const command = await this.commandRepository.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
relations: ["commandType"],
|
relations: ["commandType", "commandRecives"],
|
||||||
});
|
});
|
||||||
if (!command) {
|
if (!command) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||||
}
|
}
|
||||||
|
|
||||||
const _command = {
|
let _command: any = [];
|
||||||
issue: "...................................",
|
let path = this.commandTypePath(command.commandType.name);
|
||||||
commandNo: command.commandNo,
|
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
||||||
commandYear: command.commandYear,
|
|
||||||
commandTitle: command.issue,
|
new CallAPI()
|
||||||
detailHeader: command.detailHeader,
|
.PostData(request, path + "attachment", {
|
||||||
detailBody: command.detailBody,
|
refIds: command.commandRecives.map((x) => x.refId),
|
||||||
detailFooter: command.detailFooter,
|
})
|
||||||
commandDate:
|
.then(async (res) => {
|
||||||
command.commandAffectDate == null
|
console.log(res);
|
||||||
? ""
|
_command = res;
|
||||||
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(command.commandAffectDate)),
|
})
|
||||||
commandExcecuteDate:
|
.catch(() => {});
|
||||||
command.commandExcecuteDate == null
|
|
||||||
? ""
|
|
||||||
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(command.commandExcecuteDate)),
|
|
||||||
name: "...................................",
|
|
||||||
position: "...................................",
|
|
||||||
};
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
template: command.commandType.fileAttachment,
|
template: command.commandType.fileAttachment,
|
||||||
reportName: "xlsx-report",
|
reportName: "xlsx-report",
|
||||||
data: _command,
|
data: _command,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API สร้างรายการ body คำสั่ง
|
||||||
|
*
|
||||||
|
* @summary API สร้างรายการ body คำสั่ง
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post("person")
|
||||||
|
async PostPerson(
|
||||||
|
@Body()
|
||||||
|
requestBody: {
|
||||||
|
commandTypeId?: string;
|
||||||
|
commandNo?: string | null;
|
||||||
|
commandYear?: number | null;
|
||||||
|
commandId?: string | null;
|
||||||
|
persons: {
|
||||||
|
refId: string;
|
||||||
|
citizenId: string;
|
||||||
|
prefix: string;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
}[];
|
||||||
|
},
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
|
) {
|
||||||
|
let command = new Command();
|
||||||
|
if (
|
||||||
|
requestBody.commandId != undefined &&
|
||||||
|
requestBody.commandId != null &&
|
||||||
|
requestBody.commandId != ""
|
||||||
|
) {
|
||||||
|
const _command = await this.commandRepository.findOne({
|
||||||
|
where: { id: requestBody.commandId },
|
||||||
|
relations: ["commandRecives"],
|
||||||
|
order: {
|
||||||
|
commandRecives: {
|
||||||
|
order: "DESC",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!_command) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบคำสั่งนี้ในระบบ");
|
||||||
|
}
|
||||||
|
command = _command;
|
||||||
|
} else {
|
||||||
|
command = Object.assign(new Command(), requestBody);
|
||||||
|
const commandType = await this.commandTypeRepository.findOne({
|
||||||
|
where: { id: requestBody.commandTypeId },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!commandType) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
||||||
|
}
|
||||||
|
command.detailHeader = commandType.detailHeader;
|
||||||
|
command.detailBody = commandType.detailBody;
|
||||||
|
command.detailFooter = commandType.detailFooter;
|
||||||
|
command.isAttachment = commandType.isAttachment;
|
||||||
|
command.status = "NEW";
|
||||||
|
command.issue = commandType.name;
|
||||||
|
command.createdUserId = request.user.sub;
|
||||||
|
command.createdFullName = request.user.name;
|
||||||
|
command.createdAt = new Date();
|
||||||
|
command.lastUpdateUserId = request.user.sub;
|
||||||
|
command.lastUpdateFullName = request.user.name;
|
||||||
|
command.lastUpdatedAt = new Date();
|
||||||
|
await this.commandRepository.save(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = this.commandTypePath(command.commandType.name);
|
||||||
|
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
||||||
|
new CallAPI()
|
||||||
|
.PostData(request, path, {
|
||||||
|
refIds: requestBody.persons.map((x) => x.refId),
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
let order =
|
||||||
|
command.commandRecives == null || command.commandRecives.length <= 0
|
||||||
|
? 0
|
||||||
|
: command.commandRecives[0].order;
|
||||||
|
await Promise.all(
|
||||||
|
requestBody.persons.map(async (item) => {
|
||||||
|
const _commandRecive = await this.commandReciveRepository.findOne({
|
||||||
|
where: {
|
||||||
|
commandId: command.id,
|
||||||
|
refId: item.refId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (_commandRecive) return;
|
||||||
|
order = order + 1;
|
||||||
|
let commandRecive = new CommandRecive();
|
||||||
|
commandRecive = Object.assign(new CommandRecive(), item);
|
||||||
|
commandRecive.order = order;
|
||||||
|
commandRecive.commandId = command.id;
|
||||||
|
commandRecive.createdUserId = request.user.sub;
|
||||||
|
commandRecive.createdFullName = request.user.name;
|
||||||
|
commandRecive.createdAt = new Date();
|
||||||
|
commandRecive.lastUpdateUserId = request.user.sub;
|
||||||
|
commandRecive.lastUpdateFullName = request.user.name;
|
||||||
|
commandRecive.lastUpdatedAt = new Date();
|
||||||
|
await this.commandReciveRepository.save(commandRecive);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
return new HttpSuccess(command.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
commandTypePath(commandType: string) {
|
||||||
|
let path = null;
|
||||||
|
switch (commandType) {
|
||||||
|
case "C-PM-01":
|
||||||
|
path = "/placemant/main/report/";
|
||||||
|
case "C-PM-02":
|
||||||
|
path = "/placemant/recive/report/";
|
||||||
|
case "C-PM-03":
|
||||||
|
path = "/discipline/recive/report/";
|
||||||
|
case "C-PM-04":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-05":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-06":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-07":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-08":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-09":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-10":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-11":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-12":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-13":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-14":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-15":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-16":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-17":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-18":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-19":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-20":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-21":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-22":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-23":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-24":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-25":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-26":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-27":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-28":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-29":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-30":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-31":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-32":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-33":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-34":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-35":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-36":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-37":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-38":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-39":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-40":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
case "C-PM-41":
|
||||||
|
path = "/xxxxxx/";
|
||||||
|
default:
|
||||||
|
path = null;
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { Entity, Column, JoinColumn, ManyToOne, OneToMany, Double } from "typeorm";
|
import { Entity, Column, JoinColumn, ManyToOne, OneToMany, Double } from "typeorm";
|
||||||
import { EntityBase } from "./base/Base";
|
import { EntityBase } from "./base/Base";
|
||||||
import { Command } from "./Command";
|
import { Command } from "./Command";
|
||||||
import { Profile } from "./Profile";
|
|
||||||
|
|
||||||
@Entity("commandRecive")
|
@Entity("commandRecive")
|
||||||
export class CommandRecive extends EntityBase {
|
export class CommandRecive extends EntityBase {
|
||||||
|
|
@ -37,22 +36,6 @@ export class CommandRecive extends EntityBase {
|
||||||
})
|
})
|
||||||
lastName: string;
|
lastName: string;
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
comment: "ตำแหน่ง",
|
|
||||||
length: 255,
|
|
||||||
default: null,
|
|
||||||
})
|
|
||||||
position: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
comment: "หน่วยงาน",
|
|
||||||
length: 255,
|
|
||||||
default: null,
|
|
||||||
})
|
|
||||||
org: string;
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
comment: "ลำดับแสดงผล",
|
comment: "ลำดับแสดงผล",
|
||||||
|
|
@ -100,6 +83,14 @@ export class CommandRecive extends EntityBase {
|
||||||
})
|
})
|
||||||
mouthSalaryAmount: Double;
|
mouthSalaryAmount: Double;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
length: 40,
|
||||||
|
comment: "refId",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
refId: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
length: 40,
|
length: 40,
|
||||||
comment: "คีย์นอก(FK)ของตาราง command",
|
comment: "คีย์นอก(FK)ของตาราง command",
|
||||||
|
|
@ -110,15 +101,25 @@ export class CommandRecive extends EntityBase {
|
||||||
@JoinColumn({ name: "commandId" })
|
@JoinColumn({ name: "commandId" })
|
||||||
command: Command;
|
command: Command;
|
||||||
|
|
||||||
@Column({
|
// @Column({
|
||||||
length: 40,
|
// length: 40,
|
||||||
comment: "คีย์นอก(FK)ของตาราง profile",
|
// comment: "คีย์นอก(FK)ของตาราง profile",
|
||||||
})
|
// })
|
||||||
profileId: string;
|
// profileId: string;
|
||||||
|
|
||||||
@ManyToOne(() => Profile, (profile) => profile.commandRecives)
|
// @ManyToOne(() => Profile, (profile) => profile.commandRecives)
|
||||||
@JoinColumn({ name: "profileId" })
|
// @JoinColumn({ name: "profileId" })
|
||||||
profile: Profile;
|
// profile: Profile;
|
||||||
|
|
||||||
|
// @Column({
|
||||||
|
// length: 40,
|
||||||
|
// comment: "คีย์นอก(FK)ของตาราง profileEmployee",
|
||||||
|
// })
|
||||||
|
// profileEmployeeId: string;
|
||||||
|
|
||||||
|
// @ManyToOne(() => ProfileEmployee, (profileEmployee) => profileEmployee.commandRecives)
|
||||||
|
// @JoinColumn({ name: "profileEmployeeId" })
|
||||||
|
// profileEmployee: ProfileEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateCommandRecive {
|
export class CreateCommandRecive {
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,8 @@ import { ProfileDiscipline } from "./ProfileDiscipline";
|
||||||
import { ProfileEmployee } from "./ProfileEmployee";
|
import { ProfileEmployee } from "./ProfileEmployee";
|
||||||
import { ProfileEdit } from "./ProfileEdit";
|
import { ProfileEdit } from "./ProfileEdit";
|
||||||
import { ProfileDevelopment } from "./ProfileDevelopment";
|
import { ProfileDevelopment } from "./ProfileDevelopment";
|
||||||
import { OrgRoot } from "./OrgRoot";
|
|
||||||
import { PermissionOrg } from "./PermissionOrg";
|
import { PermissionOrg } from "./PermissionOrg";
|
||||||
import { CommandSend } from "./CommandSend";
|
import { CommandSend } from "./CommandSend";
|
||||||
import { CommandRecive } from "./CommandRecive";
|
|
||||||
import { DevelopmentRequest } from "./DevelopmentRequest";
|
import { DevelopmentRequest } from "./DevelopmentRequest";
|
||||||
|
|
||||||
@Entity("profile")
|
@Entity("profile")
|
||||||
|
|
@ -380,9 +378,6 @@ export class Profile extends EntityBase {
|
||||||
@OneToMany(() => CommandSend, (v) => v.profile)
|
@OneToMany(() => CommandSend, (v) => v.profile)
|
||||||
commandSends: CommandSend[];
|
commandSends: CommandSend[];
|
||||||
|
|
||||||
@OneToMany(() => CommandRecive, (v) => v.profile)
|
|
||||||
commandRecives: CommandRecive[];
|
|
||||||
|
|
||||||
@ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles)
|
@ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles)
|
||||||
@JoinColumn({ name: "posLevelId" })
|
@JoinColumn({ name: "posLevelId" })
|
||||||
posLevel: PosLevel;
|
posLevel: PosLevel;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue