Merge branch 'develop' into develop-Bright
This commit is contained in:
commit
35942b52ba
4 changed files with 105 additions and 111 deletions
|
|
@ -1091,9 +1091,8 @@ export class CommandController extends Controller {
|
|||
}
|
||||
|
||||
async cronjobCommand(@Request() request?: RequestWithUser) {
|
||||
console.log(request);
|
||||
const today = new Date();
|
||||
today.setHours(7, 0, 0, 0); //+7 เพื่อให้ตรง local time (อาจจะต้องใช้ moment)
|
||||
today.setUTCHours(0, 0, 0, 0);
|
||||
const tomorrow = new Date(today);
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import permission from "../interfaces/permission";
|
|||
import { PermissionOrg } from "../entities/PermissionOrg";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { AuthRole } from "../entities/AuthRole";
|
||||
import { sendToQueue, sendToQueueOrg } from "../services/rabbitmq";
|
||||
|
||||
@Route("api/v1/org")
|
||||
@Tags("Organization")
|
||||
|
|
@ -120,7 +121,6 @@ export class OrganizationController extends Controller {
|
|||
@Body() requestBody: CreateOrgRevision,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
console.log("fucntion draft");
|
||||
//new main revision
|
||||
const before = null;
|
||||
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
|
||||
|
|
@ -3414,76 +3414,18 @@ export class OrganizationController extends Controller {
|
|||
orgRevisionDraft.orgRevisionIsCurrent = true;
|
||||
orgRevisionDraft.orgRevisionIsDraft = false;
|
||||
await this.orgRevisionRepository.save(orgRevisionDraft);
|
||||
|
||||
const posMaster = await this.posMasterRepository.find({
|
||||
where: { orgRevisionId: orgRevisionDraft.id },
|
||||
relations: [
|
||||
"orgRoot",
|
||||
"orgChild4",
|
||||
"orgChild3",
|
||||
"orgChild2",
|
||||
"orgChild1",
|
||||
"positions",
|
||||
"positions.posLevel",
|
||||
"positions.posType",
|
||||
"positions.posExecutive",
|
||||
],
|
||||
});
|
||||
await Promise.all(
|
||||
posMaster.map(async (item) => {
|
||||
// if(item.next_holderId != null){
|
||||
if (item.next_holderId != null) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { id: item.next_holderId == null ? "" : item.next_holderId },
|
||||
});
|
||||
const position = await item.positions.find((x) => x.positionIsSelected == true);
|
||||
const _null: any = null;
|
||||
if (profile != null) {
|
||||
profile.posLevelId = position?.posLevelId ?? _null;
|
||||
profile.posTypeId = position?.posTypeId ?? _null;
|
||||
profile.position = position?.positionName ?? _null;
|
||||
await this.profileRepo.save(profile);
|
||||
}
|
||||
// const profileSalary = await this.salaryRepository.findOne({
|
||||
// where: { profileId: item.next_holderId },
|
||||
// order: { createdAt: "DESC" },
|
||||
// });
|
||||
|
||||
// const shortName =
|
||||
// item != null && item.orgChild4 != null
|
||||
// ? `${item.orgChild4.orgChild4ShortName}${item.posMasterNo}`
|
||||
// : item != null && item?.orgChild3 != null
|
||||
// ? `${item.orgChild3.orgChild3ShortName}${item.posMasterNo}`
|
||||
// : item != null && item?.orgChild2 != null
|
||||
// ? `${item.orgChild2.orgChild2ShortName}${item.posMasterNo}`
|
||||
// : item != null && item?.orgChild1 != null
|
||||
// ? `${item.orgChild1.orgChild1ShortName}${item.posMasterNo}`
|
||||
// : item != null && item?.orgRoot != null
|
||||
// ? `${item.orgRoot.orgRootShortName}${item.posMasterNo}`
|
||||
// : null;
|
||||
// await new FunctionMain().newSalaryFunction(request, {
|
||||
// profileId: item.next_holderId,
|
||||
// date: new Date(),
|
||||
// amount: profileSalary?.amount ?? null,
|
||||
// positionSalaryAmount: profileSalary?.positionSalaryAmount ?? null,
|
||||
// mouthSalaryAmount: profileSalary?.mouthSalaryAmount ?? null,
|
||||
// posNo: shortName,
|
||||
// position: position?.positionName ?? _null,
|
||||
// positionLine: position?.positionField ?? _null,
|
||||
// positionPathSide: position?.positionArea ?? _null,
|
||||
// positionExecutive: position?.posExecutive?.posExecutiveName ?? _null,
|
||||
// positionType: position?.posType?.posTypeName ?? _null,
|
||||
// positionLevel: position?.posLevel?.posLevelName ?? _null,
|
||||
// refCommandNo: null,
|
||||
// templateDoc: "ปรับโครงสร้าง",
|
||||
// });
|
||||
}
|
||||
item.current_holderId = item.next_holderId;
|
||||
item.next_holderId = null;
|
||||
await this.posMasterRepository.save(item);
|
||||
// }
|
||||
}),
|
||||
);
|
||||
const msg = {
|
||||
data: {
|
||||
id: orgRevisionDraft.id,
|
||||
status: "NOW",
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
lastUpdatedAt: new Date(),
|
||||
},
|
||||
user: request.user,
|
||||
token: request.headers["authorization"],
|
||||
};
|
||||
sendToQueueOrg(msg);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -3492,7 +3434,10 @@ export class OrganizationController extends Controller {
|
|||
*/
|
||||
async cronjobRevision() {
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day
|
||||
today.setUTCHours(0, 0, 0, 0); // Set time to the beginning of the day
|
||||
const tomorrow = new Date(today);
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
|
||||
const orgRevisionPublish = await this.orgRevisionRepository
|
||||
.createQueryBuilder("orgRevision")
|
||||
.where("orgRevision.orgRevisionIsDraft = false")
|
||||
|
|
@ -3503,8 +3448,9 @@ export class OrganizationController extends Controller {
|
|||
.createQueryBuilder("orgRevision")
|
||||
.where("orgRevision.orgRevisionIsDraft = true")
|
||||
.andWhere("orgRevision.orgRevisionIsCurrent = false")
|
||||
.andWhere("DATE(orgRevision.orgPublishDate) = :today", { today })
|
||||
.andWhere("orgRevision.orgPublishDate BETWEEN :today AND :tomorrow", { today, tomorrow })
|
||||
.getOne();
|
||||
|
||||
if (!orgRevisionDraft) {
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -3517,17 +3463,26 @@ export class OrganizationController extends Controller {
|
|||
orgRevisionDraft.orgRevisionIsDraft = false;
|
||||
await this.orgRevisionRepository.save(orgRevisionDraft);
|
||||
|
||||
const posMaster = await this.posMasterRepository.find({
|
||||
where: { orgRevisionId: orgRevisionDraft.id },
|
||||
});
|
||||
posMaster.forEach(async (item) => {
|
||||
// if(item.next_holderId != null){
|
||||
item.current_holderId = item.next_holderId;
|
||||
item.next_holderId = null;
|
||||
await this.posMasterRepository.save(item);
|
||||
// }
|
||||
});
|
||||
|
||||
// const posMaster = await this.posMasterRepository.find({
|
||||
// where: { orgRevisionId: orgRevisionDraft.id },
|
||||
// });
|
||||
// posMaster.forEach(async (item) => {
|
||||
// // if(item.next_holderId != null){
|
||||
// item.current_holderId = item.next_holderId;
|
||||
// item.next_holderId = null;
|
||||
// await this.posMasterRepository.save(item);
|
||||
// // }
|
||||
// });
|
||||
const msg = {
|
||||
data: {
|
||||
id: orgRevisionDraft.id,
|
||||
status: "ON_SCHEDULE",
|
||||
lastUpdateUserId: "system",
|
||||
lastUpdateFullName: "system",
|
||||
lastUpdatedAt: new Date(),
|
||||
}
|
||||
};
|
||||
sendToQueueOrg(msg);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue