|
1 | | -import { RoomUserDAO } from "../../../../dao"; |
2 | 1 | import { AbstractController, ControllerClassParams } from "../../../../abstract/controller"; |
3 | 2 | import { Status } from "../../../../constants/Project"; |
4 | 3 | import { Controller } from "../../../../decorator/Controller"; |
5 | 4 | import { FastifySchema, Response, ResponseError } from "../../../../types/Server"; |
6 | 5 |
|
7 | 6 | 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"; |
8 | 10 |
|
9 | 11 | @Controller<RequestType, ResponseType>({ |
10 | 12 | method: "get", |
11 | 13 | path: "private-polic/get", |
12 | 14 | auth: false, |
13 | | - skipAutoHandle: true, |
| 15 | + skipAutoHandle: false, |
| 16 | + enable: true |
14 | 17 | }) |
15 | 18 | export class AgreementGetToRtc extends AbstractController<RequestType, ResponseType> { |
16 | 19 | public static readonly schema: FastifySchema<RequestType> = { |
@@ -45,24 +48,42 @@ export class AgreementGetToRtc extends AbstractController<RequestType, ResponseT |
45 | 48 | const room_uuid = this.querystring.room_uuid; |
46 | 49 | const rtcUids = rtcUidstr.split(","); |
47 | 50 | 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 | + } |
62 | 86 | } |
63 | | - } else { |
64 | | - // 查不到用户则默认不同意 |
65 | | - listMap.set(rtc_uid, false); |
66 | 87 | } |
67 | 88 | } |
68 | 89 | } |
|
0 commit comments