wuyi 1 рік тому
батько
коміт
f88af18968

+ 3 - 0
src/operator_config/entities/operator-config.entiy.ts

@@ -26,6 +26,9 @@ export class OperatorConfig {
     @Column({ nullable: true })
     area: string
 
+    @Column({ default: 1 })
+    weighting: number
+
     @Column({ nullable: true })
     remark: string
 

+ 10 - 0
src/rcs-number/rcs-number.service.ts

@@ -86,7 +86,17 @@ export class RcsNumberService {
             if (availableOperatorConfigs.length === 0) {
                 throw new Error(`无可用国家`)
             }
+
             operatorConfig = availableOperatorConfigs[Math.floor(Math.random() * availableOperatorConfigs.length)]
+            let totalWeight = availableOperatorConfigs.reduce((sum, config) => sum + config.weighting, 0);
+            let randomWeight = Math.random() * totalWeight;
+            for (let config of availableOperatorConfigs) {
+                randomWeight -= config.weighting;
+                if (randomWeight < 0) {
+                    operatorConfig = config
+                    break
+                }
+            }
         }
 
         const channels = await this.channelService.all()