|
|
@@ -1,11 +1,5 @@
|
|
|
import {
|
|
|
- Injectable,
|
|
|
- NotFoundException,
|
|
|
- HttpException,
|
|
|
- HttpStatus,
|
|
|
- BadRequestException,
|
|
|
- InternalServerErrorException,
|
|
|
- UnauthorizedException
|
|
|
+ Injectable
|
|
|
} from '@nestjs/common'
|
|
|
import { FindManyOptions, In, Repository, UpdateResult } from 'typeorm'
|
|
|
import { InjectRepository } from '@nestjs/typeorm'
|
|
|
@@ -146,11 +140,13 @@ export class MomentsService {
|
|
|
|
|
|
chatRoleList.forEach(async role => {
|
|
|
const text = await this.chatService.sendMessage(null, role.condition)
|
|
|
- const momentsDto = new MomentsDto
|
|
|
- momentsDto.content = text
|
|
|
- momentsDto.userId = role.id
|
|
|
- momentsDto.isPush = false
|
|
|
- await this.momentsRepository.save(momentsDto)
|
|
|
+ if (text.trim() !== '') {
|
|
|
+ const momentsDto = new MomentsDto
|
|
|
+ momentsDto.content = text
|
|
|
+ momentsDto.userId = role.id
|
|
|
+ momentsDto.isPush = false
|
|
|
+ await this.momentsRepository.save(momentsDto)
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -161,9 +157,19 @@ export class MomentsService {
|
|
|
.getMany()
|
|
|
|
|
|
momentsList.forEach(moments => {
|
|
|
- const hours = Math.floor(Math.random() * 12)
|
|
|
- const minutes = Math.floor(Math.random() * 60)
|
|
|
- console.log(moments.userId + '的动态将在' + hours + '小时' + minutes + '分后发布')
|
|
|
+
|
|
|
+ const targetTime = new Date();
|
|
|
+ targetTime.setHours(Math.floor(Math.random() * 12) + 10);
|
|
|
+ targetTime.setMinutes(Math.floor(Math.random() * 60));
|
|
|
+
|
|
|
+ const now = new Date();
|
|
|
+ const delayTime = targetTime.getTime() - now.getTime();
|
|
|
+
|
|
|
+ console.log(moments.userId + '的动态将在' + delayTime / 1000 / 60 + '分后发布')
|
|
|
+
|
|
|
+ if (delayTime < 0) {
|
|
|
+ delayTime == 0
|
|
|
+ }
|
|
|
setTimeout(async () => {
|
|
|
moments.isPush = true
|
|
|
moments.createdAt = new Date()
|
|
|
@@ -171,7 +177,8 @@ export class MomentsService {
|
|
|
const chatRole = await this.chatRoleRepository.findOneBy({ id: moments.userId })
|
|
|
chatRole.dynamicNumber += 1
|
|
|
await this.chatRoleRepository.save(chatRole)
|
|
|
- }, hours * 60 * 60 * 1000 + minutes * 60 * 1000)
|
|
|
+ }, delayTime)
|
|
|
+
|
|
|
})
|
|
|
}
|
|
|
|