2025-10-13
群组查询修改
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {Column, Entity, PrimaryGeneratedColumn} from "typeorm";
|
||||
import {ProgramEntity} from "./program.entity";
|
||||
import {format} from "date-fns";
|
||||
|
||||
@Entity("program_group", {schema: "test"})
|
||||
export class ProgramGroupEntity {
|
||||
@@ -22,6 +23,10 @@ export class ProgramGroupEntity {
|
||||
name: "create_time",
|
||||
comment: "创建时间",
|
||||
default: () => "CURRENT_TIMESTAMP",
|
||||
transformer: {
|
||||
from: (value: Date) => value ? format(value, "yyyy-MM-dd HH:mm:ss") : null,
|
||||
to: (value: number) => value,
|
||||
}
|
||||
})
|
||||
createTime: Date;
|
||||
|
||||
@@ -33,4 +38,7 @@ export class ProgramGroupEntity {
|
||||
|
||||
userUnread: any
|
||||
chargeUnread: any
|
||||
customerUnread: any
|
||||
|
||||
keyword: string | null;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,9 @@ export class ProgramGroupMessageEntity {
|
||||
|
||||
userInfo: UsersEntity | null;
|
||||
|
||||
userId: number;
|
||||
chargeId: number;
|
||||
|
||||
sort: "create_desc" | "create_asc";
|
||||
page: number;
|
||||
size: number;
|
||||
|
||||
@@ -100,6 +100,14 @@ export class ProgramGroupService {
|
||||
"program",
|
||||
"group.program_id = program.id"
|
||||
)
|
||||
|
||||
queryBuilder.leftJoinAndMapOne(
|
||||
"group.chargeUser",
|
||||
UsersEntity,
|
||||
"chargeUser",
|
||||
"group.charge_id = chargeUser.id"
|
||||
)
|
||||
|
||||
queryBuilder.leftJoinAndMapOne(
|
||||
"group.user",
|
||||
UsersEntity,
|
||||
@@ -123,11 +131,23 @@ export class ProgramGroupService {
|
||||
queryBuilder.orWhere("group.charge_id = :charge_id", {charge_id: programGroup.userId})
|
||||
}
|
||||
|
||||
if (programGroup.keyword != null){
|
||||
queryBuilder.andWhere(
|
||||
"(program.name LIKE :nameKeyword OR program.company LIKE :companyKeyword)",
|
||||
{
|
||||
nameKeyword: '%' + programGroup.keyword + '%',
|
||||
companyKeyword: '%' + programGroup.keyword + '%'
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
queryBuilder
|
||||
.orderBy("latest_message_time", 'DESC')
|
||||
.take(programGroup.size || 10)
|
||||
.skip(offset || 0);
|
||||
|
||||
// console.log(queryBuilder.getSql())
|
||||
|
||||
let [items, total] = await queryBuilder.getManyAndCount();
|
||||
|
||||
// 将未读数据(redis)塞入数据(list)中
|
||||
@@ -167,8 +187,10 @@ export class ProgramGroupService {
|
||||
let item = list[i];
|
||||
let userUnreadValue = await this.redisService.getValue(`${item.groupId}_${item.userId}`)
|
||||
let chargeUnreadValue = await this.redisService.getValue(`${item.groupId}_${item.chargeId}`)
|
||||
let customerUnreadValue = await this.redisService.getValue(`${item.groupId}_${item.customerId}`)
|
||||
item.userUnread = userUnreadValue == null ? [] : JSON.parse(userUnreadValue)
|
||||
item.chargeUnread = chargeUnreadValue == null ? [] : JSON.parse(chargeUnreadValue)
|
||||
item.customerUnread = customerUnreadValue == null ? [] : JSON.parse(customerUnreadValue)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user