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