Skip to content

Commit b5b0039

Browse files
authored
fix: modify about collect data by batch rtc_uuid (#852)
1 parent e5ee060 commit b5b0039

File tree

3 files changed

+92
-27
lines changed

3 files changed

+92
-27
lines changed

src/v1/controller/user/agreement/Get.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import { ServiceUserAgreement } from "../../../service/user/UserAgreement";
1111
auth: true,
1212
})
1313
export class AgreementGet extends AbstractController<RequestType, ResponseType> {
14-
public static readonly schema: FastifySchema<RequestType> = {
15-
};
14+
public static readonly schema: FastifySchema<RequestType> = {};
1615

1716
public readonly svc: {
1817
userAgreement: ServiceUserAgreement;
@@ -41,11 +40,7 @@ export class AgreementGet extends AbstractController<RequestType, ResponseType>
4140
}
4241
}
4342

44-
interface RequestType {
45-
querystring: {
46-
uid: string;
47-
};
48-
}
43+
interface RequestType {}
4944

5045
interface ResponseType {
5146
isAgree: boolean;

src/v1/controller/user/agreement/GetToRtc.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import { RoomUserDAO } from "../../../../dao";
21
import { AbstractController, ControllerClassParams } from "../../../../abstract/controller";
32
import { Status } from "../../../../constants/Project";
43
import { Controller } from "../../../../decorator/Controller";
54
import { FastifySchema, Response, ResponseError } from "../../../../types/Server";
65

76
import { ServiceUserAgreement } from "../../../service/user/UserAgreement";
7+
import { RoomUserModel } from "../../../../model/room/RoomUser";
8+
import { dataSource } from "../../../../thirdPartyService/TypeORMService";
9+
import { UserAgreementModel } from "./../../../../model/user/Agreement";
810

911
@Controller<RequestType, ResponseType>({
1012
method: "get",
1113
path: "private-polic/get",
1214
auth: false,
13-
skipAutoHandle: true,
15+
skipAutoHandle: false,
16+
enable: true
1417
})
1518
export class AgreementGetToRtc extends AbstractController<RequestType, ResponseType> {
1619
public static readonly schema: FastifySchema<RequestType> = {
@@ -45,24 +48,42 @@ export class AgreementGetToRtc extends AbstractController<RequestType, ResponseT
4548
const room_uuid = this.querystring.room_uuid;
4649
const rtcUids = rtcUidstr.split(",");
4750
const listMap:Map<string, boolean> = new Map();
48-
if (rtcUids.length > 0) {
49-
for (const rtc_uid of rtcUids) {
50-
const roomUserInfo = await RoomUserDAO().findOne(["user_uuid"], {
51-
rtc_uid,
52-
room_uuid
53-
});
54-
if (roomUserInfo) {
55-
const bol = await ServiceUserAgreement.hasCollectData(roomUserInfo.user_uuid);
56-
if (bol) {
57-
const isAgree = await ServiceUserAgreement.isAgreeCollectData(roomUserInfo.user_uuid);
58-
listMap.set(rtc_uid, isAgree);
59-
} else {
60-
// 默认就是同意
61-
listMap.set(rtc_uid, true);
51+
const length = rtcUids.length;
52+
if (length > 0) {
53+
let i = 0;
54+
const batchQueryRtcUids: string[][] = [];
55+
while (i < length) {
56+
const j = i + 50;
57+
batchQueryRtcUids.push(rtcUids.slice(i, j));
58+
i = j;
59+
}
60+
for (const rtc_uids of batchQueryRtcUids) {
61+
const roomUsersInfos = await dataSource
62+
.createQueryBuilder(RoomUserModel, "ru")
63+
.where("ru.room_uuid = :room_uuid", {
64+
room_uuid,
65+
})
66+
.andWhere("ru.rtc_uid IN (:...rtc_uids)", { rtc_uids })
67+
.getMany();
68+
69+
for (const rtc_uid of rtc_uids) {
70+
listMap.set(rtc_uid, false);
71+
}
72+
const collectInfos = await dataSource
73+
.createQueryBuilder(UserAgreementModel, "cInfo")
74+
.where("cInfo.user_uuid IN (:...user_uuid)", { user_uuid: roomUsersInfos.map(c=> c && c.user_uuid) })
75+
.getMany();
76+
77+
for (const rInfo of roomUsersInfos) {
78+
listMap.set(rInfo.rtc_uid, true);
79+
const rtc_uid = rInfo.rtc_uid;
80+
const user_uuid = rInfo.user_uuid;
81+
if (rtc_uid && user_uuid) {
82+
const cInfo = collectInfos.find(c=> c && (c.user_uuid === user_uuid));
83+
if (cInfo) {
84+
listMap.set(rtc_uid, cInfo.is_agree_collect_data);
85+
}
6286
}
63-
} else {
64-
// 查不到用户则默认不同意
65-
listMap.set(rtc_uid, false);
6687
}
6788
}
6889
}

src/v1/service/user/__tests__/userAgreement.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { RoomUserDAO, UserAgreementDAO } from "../../../../dao";
44
import { v4 } from "uuid";
55
import { ServiceUserAgreement } from "../UserAgreement";
66
import cryptoRandomString from "crypto-random-string";
7+
import { RoomUserModel } from "../../../../model/room/RoomUser";
8+
import { UserAgreementModel } from "../../../../model/user/Agreement";
79

810
const namespace = "[service][service-user][service-user-agreement]";
911

@@ -110,6 +112,7 @@ test(`${namespace} - get user by rtc_uuid collect agreement`, async ava => {
110112
const userUUID = v4();
111113
const roomUUID = v4();
112114
const rtcUUID = cryptoRandomString({ length: 6, type: "numeric" });
115+
const rtcUUID1 = cryptoRandomString({ length: 6, type: "numeric" });
113116

114117
await Promise.all([
115118
RoomUserDAO().insert({
@@ -132,12 +135,58 @@ test(`${namespace} - get user by rtc_uuid collect agreement`, async ava => {
132135

133136
ava.is(result?.user_uuid, userUUID);
134137

135-
const result1 = await UserAgreementDAO().findOne(["user_uuid"], {
138+
const result1 = await UserAgreementDAO().findOne(["user_uuid", "is_agree_collect_data"], {
136139
user_uuid: userUUID,
137140
});
138141

139142
ava.not(result1, undefined);
140143

141144
ava.is(result?.user_uuid, result1?.user_uuid);
142145

146+
const rtcUids = [rtcUUID, rtcUUID1];
147+
const length = rtcUids.length;
148+
const listMap:Map<string, boolean> = new Map();
149+
if (length > 0) {
150+
let i = 0;
151+
const batchQueryRtcUids: string[][] = [];
152+
while (i < length) {
153+
const j = i + 50;
154+
batchQueryRtcUids.push(rtcUids.slice(i, j));
155+
i = j;
156+
}
157+
for (const rtc_uids of batchQueryRtcUids) {
158+
const roomUsersInfos = await dataSource
159+
.createQueryBuilder(RoomUserModel, "ru")
160+
.where("ru.room_uuid = :room_uuid", {
161+
room_uuid:roomUUID,
162+
})
163+
.andWhere("ru.rtc_uid IN (:...rtc_uids)", { rtc_uids })
164+
.getMany();
165+
166+
for (const rtc_uid of rtc_uids) {
167+
listMap.set(rtc_uid, false);
168+
}
169+
const collectInfos = await dataSource
170+
.createQueryBuilder(UserAgreementModel, "cInfo")
171+
.where("cInfo.user_uuid IN (:...user_uuid)", { user_uuid: roomUsersInfos.map(c=> c && c.user_uuid) })
172+
.getMany();
173+
174+
for (const rInfo of roomUsersInfos) {
175+
listMap.set(rInfo.rtc_uid, true);
176+
const rtc_uid = rInfo.rtc_uid;
177+
const user_uuid = rInfo.user_uuid;
178+
if (rtc_uid && user_uuid) {
179+
const cInfo = collectInfos.find(c=> c && (c.user_uuid === user_uuid));
180+
if (cInfo) {
181+
listMap.set(rtc_uid, cInfo.is_agree_collect_data);
182+
}
183+
}
184+
}
185+
}
186+
}
187+
const obj = Object.fromEntries(listMap);
188+
189+
ava.is(result1?.is_agree_collect_data, obj?.[rtcUUID]);
190+
191+
ava.is(false, obj?.[rtcUUID1]);
143192
});

0 commit comments

Comments
 (0)