|
@@ -1,5 +1,6 @@
|
|
|
import { Injectable } from '@nestjs/common';
|
|
import { Injectable } from '@nestjs/common';
|
|
|
import { PrismaMongoService } from '../../prisma/prisma-mongo.service';
|
|
import { PrismaMongoService } from '../../prisma/prisma-mongo.service';
|
|
|
|
|
+import { RedisService } from '@box/db/redis/redis.service';
|
|
|
import {
|
|
import {
|
|
|
AdOrder,
|
|
AdOrder,
|
|
|
SystemParamSide,
|
|
SystemParamSide,
|
|
@@ -17,6 +18,7 @@ export class SysParamsService {
|
|
|
constructor(
|
|
constructor(
|
|
|
private readonly prisma: PrismaMongoService,
|
|
private readonly prisma: PrismaMongoService,
|
|
|
private readonly sysConfigReader: SysConfigReaderService,
|
|
private readonly sysConfigReader: SysConfigReaderService,
|
|
|
|
|
+ private readonly redis: RedisService,
|
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
getHomepageConstants() {
|
|
getHomepageConstants() {
|
|
@@ -86,6 +88,59 @@ export class SysParamsService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async getSysCnf() {
|
|
async getSysCnf() {
|
|
|
- return this.sysConfigReader.getAppConfig();
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ // Try to get from Redis cache first
|
|
|
|
|
+ const cacheKey = `box:app:sysconf`;
|
|
|
|
|
+ const conf = await this.redis.get(cacheKey);
|
|
|
|
|
+ if (conf) {
|
|
|
|
|
+ return JSON.parse(conf);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const appConf = this.sysConfigReader.getAppConfig();
|
|
|
|
|
+
|
|
|
|
|
+ if (appConf) {
|
|
|
|
|
+ // Store in Redis cache for future requests
|
|
|
|
|
+ await this.redis.setJson(cacheKey, appConf, 24 * 3600); // Cache for 1 hour
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return appConf;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ async getSysParams() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // Try to get from Redis cache first
|
|
|
|
|
+ const cacheKey = `box:app:sysparams`;
|
|
|
|
|
+ const conf = await this.redis.get(cacheKey);
|
|
|
|
|
+ if (conf) {
|
|
|
|
|
+ return JSON.parse(conf);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const params = await this.prisma.systemParam.findMany({
|
|
|
|
|
+ where: {
|
|
|
|
|
+ side: SystemParamSide.CLIENT,
|
|
|
|
|
+ },
|
|
|
|
|
+ orderBy: {
|
|
|
|
|
+ id: 'asc', // sequential order by ID
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const sysParams = params.map((p, idx) => ({
|
|
|
|
|
+ id: p.id.toString(),
|
|
|
|
|
+ content: p.value ?? '', // Use 'value' field as content
|
|
|
|
|
+ seq: idx,
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ if (sysParams) {
|
|
|
|
|
+ // Store in Redis cache for future requests
|
|
|
|
|
+ await this.redis.setJson(cacheKey, sysParams, 24 * 3600); // Cache for 1 hour
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return sysParams;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|