xiongzhu 1 год назад
Родитель
Сommit
7cb6880ec5
11 измененных файлов с 59 добавлено и 16 удалено
  1. 3 1
      .env
  2. 3 1
      .env.local
  3. 3 1
      .env.local.1
  4. 3 1
      .env.production.copy
  5. 3 1
      .env.production.nj
  6. 3 1
      .env.production.sz
  7. 2 1
      package.json
  8. 10 0
      src/app.module.ts
  9. 1 1
      src/device/device.service.ts
  10. 15 7
      src/rcs-number/rcs-number.service.ts
  11. 13 1
      yarn.lock

+ 3 - 1
.env

@@ -48,4 +48,6 @@ ALIYUN_OSS_CDN=https://cdn.raex.vip
 ALIYUN_SMS_SIGN=走马信息
 ALIYUN_SMS_TEMPLATE_CODE=SMS_175485688
 
-ALLOW_ADMIN_LOGIN=true
+ALLOW_ADMIN_LOGIN=true
+
+REDIS_HOST=192.168.6.26

+ 3 - 1
.env.local

@@ -48,4 +48,6 @@ ALIYUN_OSS_CDN=https://cdn.raex.vip
 ALIYUN_SMS_SIGN=走马信息
 ALIYUN_SMS_TEMPLATE_CODE=SMS_175485688
 
-ALLOW_ADMIN_LOGIN=true
+ALLOW_ADMIN_LOGIN=true
+
+REDIS_HOST=192.168.6.26

+ 3 - 1
.env.local.1

@@ -48,4 +48,6 @@ ALIYUN_OSS_CDN=https://cdn.raex.vip
 ALIYUN_SMS_SIGN=走马信息
 ALIYUN_SMS_TEMPLATE_CODE=SMS_175485688
 
-ALLOW_ADMIN_LOGIN=true
+ALLOW_ADMIN_LOGIN=true
+
+REDIS_HOST=192.168.6.26

+ 3 - 1
.env.production.copy

@@ -48,4 +48,6 @@ ALIYUN_OSS_CDN=https://cdn.raex.vip
 ALIYUN_SMS_SIGN=走马信息
 ALIYUN_SMS_TEMPLATE_CODE=SMS_175485688
 
-ALLOW_ADMIN_LOGIN=false
+ALLOW_ADMIN_LOGIN=false
+
+REDIS_HOST=192.168.6.26

+ 3 - 1
.env.production.nj

@@ -48,4 +48,6 @@ ALIYUN_OSS_CDN=https://cdn.raex.vip
 ALIYUN_SMS_SIGN=走马信息
 ALIYUN_SMS_TEMPLATE_CODE=SMS_175485688
 
-ALLOW_ADMIN_LOGIN=false
+ALLOW_ADMIN_LOGIN=false
+
+REDIS_HOST=127.0.0.1

+ 3 - 1
.env.production.sz

@@ -48,4 +48,6 @@ ALIYUN_OSS_CDN=https://cdn.raex.vip
 ALIYUN_SMS_SIGN=走马信息
 ALIYUN_SMS_TEMPLATE_CODE=SMS_175485688
 
-ALLOW_ADMIN_LOGIN=false
+ALLOW_ADMIN_LOGIN=false
+
+REDIS_HOST=127.0.0.1

+ 2 - 1
package.json

@@ -29,6 +29,7 @@
     "@fidm/x509": "^1.2.1",
     "@keyv/mysql": "^1.6.3",
     "@keyv/redis": "^2.5.7",
+    "@liaoliaots/nestjs-redis": "^10.0.0",
     "@nestjs/axios": "^2.0.0",
     "@nestjs/common": "^9.3.3",
     "@nestjs/config": "^2.3.1",
@@ -70,7 +71,7 @@
     "hbs": "^4.2.0",
     "http-proxy-agent": "^7.0.0",
     "https-proxy-agent": "^7.0.2",
-    "ioredis": "^5.3.2",
+    "ioredis": "^5.4.1",
     "isomorphic-fetch": "^3.0.0",
     "keyv": "^4.5.2",
     "mcc-mnc-list": "^1.1.11",

+ 10 - 0
src/app.module.ts

@@ -23,6 +23,7 @@ import { OperaterConfigModule } from './operator_config/operator_config.module'
 import { CarrierIdModule } from './carrier-id/carrier-id.module'
 import { OperationLogModule } from './operation-log/operation-log.module'
 import { PayOrderModule } from './pay-order/pay-order.module'
+import { RedisModule } from '@liaoliaots/nestjs-redis'
 
 @Module({
     imports: [
@@ -73,6 +74,15 @@ import { PayOrderModule } from './pay-order/pay-order.module'
                 logging: false
             })
         }),
+        RedisModule.forRootAsync({
+            imports: [ConfigModule],
+            inject: [ConfigService],
+            useFactory: (config: ConfigService) => ({
+                config: {
+                    host: config.get<string>('REDIS_HOST')
+                }
+            })
+        }),
         ScheduleModule.forRoot(),
         AliyunModule,
         SmsModule,

+ 1 - 1
src/device/device.service.ts

@@ -433,7 +433,7 @@ export class DeviceService implements OnModuleInit {
                     return
                 }
                 const devices = await this.deviceRepository.findBy({ online: true, canSend: true })
-                if (devices.filter((d) => !d.busy).length / devices.length < 0.8) return
+                if (devices.filter((d) => !d.busy).length / devices.length < 0.5) return
 
                 const currentNum = devices.filter((d) => d.storing).length
                 if (currentNum >= min) return

+ 15 - 7
src/rcs-number/rcs-number.service.ts

@@ -26,6 +26,8 @@ import { BlackList } from './entities/black-list.entity'
 import { hwyzm } from './impl/hwyzm.service'
 import { cowboy } from './impl/cowboy.service'
 import { SysConfigService } from 'src/sys-config/sys-config.service'
+import { RedisService } from '@liaoliaots/nestjs-redis'
+import Redis from 'ioredis'
 
 @Injectable()
 export class RcsNumberService {
@@ -35,6 +37,8 @@ export class RcsNumberService {
     private cloud037: cloud214
     private cloud041: cloud214
 
+    private readonly redis: Redis | null
+
     constructor(
         @InjectRepository(RcsNumber)
         private rcsNumberRepository: Repository<RcsNumber>,
@@ -55,12 +59,17 @@ export class RcsNumberService {
         private d38: d38,
         private xyz: xyz,
         private hwyzm: hwyzm,
-        private cowboy: cowboy
+        private cowboy: cowboy,
+        private readonly redisService: RedisService
     ) {
         this.cloud033 = new cloud214('100033', '1e40ca9795b1fc038db76512175d59b5', RcsNumberSource.cloud033)
         this.cloud034 = new cloud214('100034', 'ed7b3de69df3d6d9ddfaa7eb862272f5', RcsNumberSource.cloud034)
         this.cloud037 = new cloud214('100037', 'aaec6c21e54dc53b92e472df21a95bb7', RcsNumberSource.cloud037)
         this.cloud041 = new cloud214('100041', '30e8538b0773820ade32df9e2307ffb7', RcsNumberSource.cloud041)
+        this.redis = this.redisService.getOrThrow()
+        this.redis.get('hello').then((res) => {
+            console.log(res)
+        })
     }
 
     async findAll(req: PageRequest<RcsNumber>): Promise<Pagination<RcsNumber>> {
@@ -128,10 +137,10 @@ export class RcsNumberService {
             return (
                 (store ? storeNumberChannels.includes(channel.source.toString()) : true) &&
                 (channel.countryConfig.find(
-                        (config) =>
-                            config.countryCode.toLowerCase() === operatorConfig.country ||
-                            config.countryCode.toUpperCase() === operatorConfig.country
-                    )?.enabled ||
+                    (config) =>
+                        config.countryCode.toLowerCase() === operatorConfig.country ||
+                        config.countryCode.toUpperCase() === operatorConfig.country
+                )?.enabled ||
                     false)
             )
         })
@@ -331,8 +340,7 @@ export class RcsNumberService {
                     }
                     await this.rcsNumberRepository.update(number.id, update)
                 }
-            } catch (e) {
-            }
+            } catch (e) {}
         })
     }
 

+ 13 - 1
yarn.lock

@@ -963,6 +963,13 @@
   dependencies:
     ioredis "^5.4.1"
 
+"@liaoliaots/nestjs-redis@^10.0.0":
+  version "10.0.0"
+  resolved "https://registry.npmmirror.com/@liaoliaots/nestjs-redis/-/nestjs-redis-10.0.0.tgz#4afb60bc4659fe096c603fed11f7a087de1e4712"
+  integrity sha512-uCTmlzM4q+UYADwsJEQph0mbf4u0MrktFhByi50M5fNy/+fJoWlhSqrgvjtVKjHnqydxy1gyuU6vHJEOBp9cjg==
+  dependencies:
+    tslib "2.7.0"
+
 "@lukeed/csprng@^1.0.0":
   version "1.1.0"
   resolved "https://registry.npmmirror.com/@lukeed/csprng/-/csprng-1.1.0.tgz#1e3e4bd05c1cc7a0b2ddbd8a03f39f6e4b5e6cfe"
@@ -4809,7 +4816,7 @@ interpret@^1.0.0:
   resolved "https://registry.npmmirror.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
   integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==
 
-ioredis@^5.3.2, ioredis@^5.4.1:
+ioredis@^5.4.1:
   version "5.4.1"
   resolved "https://registry.npmmirror.com/ioredis/-/ioredis-5.4.1.tgz#1c56b70b759f01465913887375ed809134296f40"
   integrity sha512-2YZsvl7jopIa1gaePkeMtd9rAcSjOOjPtpcLlOeusyO+XH2SK5ZcT+UCrElPP+WVIInh2TzeI4XW9ENaSLVVHA==
@@ -7946,6 +7953,11 @@ tslib@2.5.3:
   resolved "https://registry.npmmirror.com/tslib/-/tslib-2.5.3.tgz#24944ba2d990940e6e982c4bea147aba80209913"
   integrity sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w==
 
+tslib@2.7.0:
+  version "2.7.0"
+  resolved "https://registry.npmmirror.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01"
+  integrity sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==
+
 tslib@^1.8.1:
   version "1.14.1"
   resolved "https://registry.npmmirror.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"