wuyi 2 лет назад
Родитель
Сommit
11358c7dba

+ 4 - 1
src/moments/dto/moments.dto.ts

@@ -1,4 +1,4 @@
-import { IsNumber, IsString } from 'class-validator'
+import { IsBoolean, IsNumber, IsString } from 'class-validator'
 
 export class MomentsDto {
     @IsNumber()
@@ -6,4 +6,7 @@ export class MomentsDto {
 
     @IsString()
     content: string
+
+    @IsBoolean()
+    isPush: boolean
 }

+ 4 - 1
src/moments/entities/moments.entity.ts

@@ -22,9 +22,12 @@ export class Moments {
     @Column({ default: 0 })
     momentsLikeCount: number
 
-    @Column({ default: true })
+    @Column({ default: false })
     isDel: boolean
 
+    @Column({ default: true })
+    isPush: boolean
+
     @CreateDateColumn()
     createdAt: Date
 

+ 7 - 4
src/moments/moments.service.ts

@@ -54,6 +54,7 @@ export class MomentsService {
 
         const query = await this.momentsRepository.createQueryBuilder('moments')
             .where('moments.isDel = false')
+            .andWhere('moments.isPush = true')
 
         if (req.search) {
             const searchOptions = req.search as FindManyOptions<Moments>;
@@ -140,14 +141,15 @@ export class MomentsService {
     }
 
     public async automaticallySendMoments() {
-        const message = "我需要你以类似于朋友圈的方式发一条此时此刻的动态,尽量符合角色性格."
+        //const message = "我需要你以类似于朋友圈的方式发一条此时此刻的动态,尽量符合角色性格."
         const chatRoleList = await this.chatRoleRepository.createQueryBuilder().getMany()
 
         chatRoleList.forEach(async role => {
-            const text = await this.chatService.sendMessage(role.condition, message)
+            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)
         })
     }
@@ -155,7 +157,7 @@ export class MomentsService {
 
     public async delay() {
         const momentsList = await this.momentsRepository.createQueryBuilder('moments')
-            .where('moments.isDel = true')
+            .where('moments.isPush = false')
             .getMany()
 
         momentsList.forEach(moments => {
@@ -163,7 +165,8 @@ export class MomentsService {
             const minutes = Math.floor(Math.random() * 60)
             console.log(moments.userId + '的动态将在' + hours + '小时' + minutes + '分后发布')
             setTimeout(async () => {
-                moments.isDel = false
+                moments.isPush = true
+                moments.createdAt = new Date()
                 await this.momentsRepository.save(moments)
                 const chatRole = await this.chatRoleRepository.findOneBy({ id: moments.userId })
                 chatRole.dynamicNumber += 1