2025-09-30
消息记录查询
This commit is contained in:
@@ -21,9 +21,15 @@ export class ProgramGroupController {
|
|||||||
return await this.programGroupService.getList(programGroup);
|
return await this.programGroupService.getList(programGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 继续聊
|
||||||
/** 根据项目和用户获取群 */
|
/** 根据项目和用户获取群 */
|
||||||
@Get("one")
|
@Get("one")
|
||||||
async getOne(@Param() programGroup: ProgramGroupEntity) {
|
async getOne(@Param() programGroup: ProgramGroupEntity) {
|
||||||
return await this.programGroupService.getOne(programGroup);
|
return await this.programGroupService.getOne(programGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get(":groupId")
|
||||||
|
getGroup(@Param("groupId") groupId: number){
|
||||||
|
return this.programGroupService.getGroup(groupId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ export class ProgramGroupEntity {
|
|||||||
createTime: Date;
|
createTime: Date;
|
||||||
|
|
||||||
// 虚拟字段
|
// 虚拟字段
|
||||||
program: ProgramEntity;
|
program: ProgramEntity | null;
|
||||||
|
|
||||||
page: number = 1;
|
page: number = 1;
|
||||||
size: number = 10;
|
size: number = 10;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {Column, Entity, PrimaryGeneratedColumn} from "typeorm";
|
import {Column, Entity, PrimaryGeneratedColumn} from "typeorm";
|
||||||
import {UsersEntity} from "./users.entity";
|
import {UsersEntity} from "./users.entity";
|
||||||
|
import {format} from "date-fns";
|
||||||
|
|
||||||
@Entity("program_group_message", {schema: "test"})
|
@Entity("program_group_message", {schema: "test"})
|
||||||
export class ProgramGroupMessageEntity {
|
export class ProgramGroupMessageEntity {
|
||||||
@@ -31,6 +32,10 @@ export class ProgramGroupMessageEntity {
|
|||||||
name: "create_time",
|
name: "create_time",
|
||||||
comment: "发送时间",
|
comment: "发送时间",
|
||||||
default: () => "CURRENT_TIMESTAMP",
|
default: () => "CURRENT_TIMESTAMP",
|
||||||
|
transformer: {
|
||||||
|
to: (value: Date) => value,
|
||||||
|
from: (value: string) => value ? format(value, "yyyy-MM-dd HH:mm:ss") : null
|
||||||
|
}
|
||||||
})
|
})
|
||||||
createTime: Date;
|
createTime: Date;
|
||||||
|
|
||||||
@@ -38,4 +43,8 @@ export class ProgramGroupMessageEntity {
|
|||||||
height?: number;
|
height?: number;
|
||||||
|
|
||||||
userInfo: UsersEntity | null;
|
userInfo: UsersEntity | null;
|
||||||
|
|
||||||
|
sort: "create_desc" | "create_asc";
|
||||||
|
page: number;
|
||||||
|
size: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {Injectable} from "@nestjs/common";
|
import {Injectable} from "@nestjs/common";
|
||||||
import {ProgramGroupMessageEntity, ReadDto} from "../entity";
|
import {ProgramGroupMessageEntity, ReadDto, UsersEntity} from "../entity";
|
||||||
import {RedisService} from "./redis.service";
|
import {RedisService} from "./redis.service";
|
||||||
import {ResultData} from "../const/result";
|
import {ResultData} from "../const/result";
|
||||||
import {InjectRepository} from "@nestjs/typeorm";
|
import {InjectRepository} from "@nestjs/typeorm";
|
||||||
@@ -27,16 +27,39 @@ export class MessageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getList(message: ProgramGroupMessageEntity) {
|
async getList(message: ProgramGroupMessageEntity) {
|
||||||
|
try {
|
||||||
|
message.page = message.page || 1;
|
||||||
|
message.size = message.size || 10;
|
||||||
|
const offset = (message.page - 1) * message.size;
|
||||||
|
|
||||||
let queryBuilder = this.messageRepository.createQueryBuilder("message")
|
let queryBuilder = this.messageRepository.createQueryBuilder("message")
|
||||||
|
|
||||||
queryBuilder.leftJoinAndMapOne("message.userInfo", "users", "user", "message.create_id = user.id")
|
queryBuilder.leftJoinAndMapOne(
|
||||||
|
"message.userInfo",
|
||||||
|
UsersEntity,
|
||||||
|
"user",
|
||||||
|
"message.create_id = user.id"
|
||||||
|
).where("message.group_id = :groupId", {groupId: message.groupId})
|
||||||
|
|
||||||
let [item, total] = await queryBuilder.getManyAndCount()
|
queryBuilder
|
||||||
|
.orderBy('message.createTime', 'DESC')
|
||||||
|
.take(message.size || 10)
|
||||||
|
.skip(offset || 0);
|
||||||
|
|
||||||
return ResultData.success({
|
|
||||||
list: item,
|
let [items, total] = await queryBuilder.getManyAndCount()
|
||||||
total
|
|
||||||
})
|
let data = {
|
||||||
|
list: items,
|
||||||
|
total,
|
||||||
|
page: message.page || 1,
|
||||||
|
size: message.size || 10,
|
||||||
|
pages: Math.ceil(total / (message.size || 10))
|
||||||
|
}
|
||||||
|
return ResultData.success(data);
|
||||||
|
} catch (err) {
|
||||||
|
return ResultData.fail(500, err.message)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,4 +172,31 @@ export class ProgramGroupService {
|
|||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async getGroup(groupId: number) {
|
||||||
|
try {
|
||||||
|
let result = await this.programGroupRepository.findOne({
|
||||||
|
where: {
|
||||||
|
groupId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (result != null){
|
||||||
|
result.program = await this.programRepository.createQueryBuilder("program")
|
||||||
|
.leftJoinAndMapOne(
|
||||||
|
"program.linkman",
|
||||||
|
UsersEntity,
|
||||||
|
"linkman",
|
||||||
|
"program.linkman_id = linkman.id"
|
||||||
|
).where("program.id = :id", {id: result.programId})
|
||||||
|
.getOne()
|
||||||
|
return ResultData.success(result)
|
||||||
|
}else {
|
||||||
|
throw "未找到群组信息"
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
return ResultData.fail(500, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user