From dc0dc99a5aac1cf1cdb6f57fa5b0150ecc84a2d8 Mon Sep 17 00:00:00 2001 From: XieChengzhi Date: Mon, 12 Aug 2024 17:43:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90feature=E3=80=91redis=E7=BC=93?= =?UTF-8?q?=E5=AD=98opekg=E6=95=B0=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FieldApplicationServiceImpl.java | 23 +++++++++++++--- .../common/constant/RedisConstant.java | 26 +++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/easysoftware/common/constant/RedisConstant.java diff --git a/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java b/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java index 494de13..f2f7f55 100644 --- a/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java +++ b/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java @@ -26,7 +26,7 @@ import com.easysoftware.application.oepackage.dto.OEPackageSearchCondition; import com.easysoftware.application.rpmpackage.RPMPackageService; import com.easysoftware.application.rpmpackage.dto.RPMPackageSearchCondition; import com.easysoftware.application.rpmpackage.vo.RPMPackageDetailVo; -import com.easysoftware.common.constant.PackageConstant; +import com.easysoftware.common.constant.RedisConstant; import com.easysoftware.common.entity.MessageCode; import com.easysoftware.common.exception.ParamErrorException; import com.easysoftware.common.exception.enumvalid.AppCategoryEnum; @@ -43,6 +43,7 @@ import com.easysoftware.domain.oepackage.gateway.OEPackageGateway; import com.easysoftware.domain.rpmpackage.gateway.RPMPackageGateway; import com.easysoftware.infrastructure.fieldapplication.gatewayimpl.converter.FieldApplicationConverter; import com.easysoftware.ranking.Ranker; +import com.easysoftware.redis.RedisGateway; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; @@ -60,6 +61,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; @Service public class FieldApplicationServiceImpl implements FieldApplicationService { @@ -132,6 +134,11 @@ public class FieldApplicationServiceImpl implements FieldApplicationService { */ @Resource private ArchNumGateway archNumGateway; + /** + * gateway. + */ + @Resource + private RedisGateway redisGateway; /** * Query menu by name. @@ -441,11 +448,21 @@ public class FieldApplicationServiceImpl implements FieldApplicationService { */ @Override public ResponseEntity queryStat() { - Long appNum = appGateway.queryTableLength(); + Long appNum; + Long opekgNum = oePkgGateway.queryTableLength(); + String appnumString = redisGateway.get(RedisConstant.DISTINCT_APP_PKG); + + if (appnumString != null) { + appNum = Long.parseLong(appnumString); + } else { + appNum = appGateway.queryTableLength(); + redisGateway.setWithExpire(RedisConstant.DISTINCT_APP_PKG, String.valueOf(appNum), 90, TimeUnit.MINUTES); + } Map res = new HashMap<>(); res.put("apppkg", appNum); - res.put("total", PackageConstant.SOFTWARE_NUM); + res.put("total", opekgNum); + return ResultUtil.success(HttpStatus.OK, res); } diff --git a/src/main/java/com/easysoftware/common/constant/RedisConstant.java b/src/main/java/com/easysoftware/common/constant/RedisConstant.java new file mode 100644 index 0000000..6b4bb28 --- /dev/null +++ b/src/main/java/com/easysoftware/common/constant/RedisConstant.java @@ -0,0 +1,26 @@ +/* Copyright (c) 2024 openEuler Community + EasySoftware is licensed under the Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. +*/ + +package com.easysoftware.common.constant; + +public final class RedisConstant { + + // Private constructor to prevent instantiation of the RedisConstant class + private RedisConstant() { + // private constructor to hide the implicit public one + throw new AssertionError("RedisConstant class cannot be instantiated."); + } + + /** + * Key of distinct application packages. + */ + public static final String DISTINCT_APP_PKG = "distinct_apppkg_num"; +} -- Gitee From 1811790604b4a140cbceaafa4e794497e3df48ce Mon Sep 17 00:00:00 2001 From: XieChengzhi Date: Mon, 12 Aug 2024 17:50:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90feature=E3=80=91redis=E7=BC=93?= =?UTF-8?q?=E5=AD=98opekgNum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FieldApplicationServiceImpl.java | 14 +++++++------- .../common/constant/RedisConstant.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java b/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java index f2f7f55..a962624 100644 --- a/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java +++ b/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java @@ -448,15 +448,15 @@ public class FieldApplicationServiceImpl implements FieldApplicationService { */ @Override public ResponseEntity queryStat() { - Long appNum; - Long opekgNum = oePkgGateway.queryTableLength(); - String appnumString = redisGateway.get(RedisConstant.DISTINCT_APP_PKG); + Long opekgNum; + Long appNum = appGateway.queryTableLength(); + String opeknumString = redisGateway.get(RedisConstant.DISTINCT_OPEKGNUM); - if (appnumString != null) { - appNum = Long.parseLong(appnumString); + if (opeknumString != null) { + opekgNum = Long.parseLong(opeknumString); } else { - appNum = appGateway.queryTableLength(); - redisGateway.setWithExpire(RedisConstant.DISTINCT_APP_PKG, String.valueOf(appNum), 90, TimeUnit.MINUTES); + opekgNum = oePkgGateway.queryTableLength(); + redisGateway.setWithExpire(RedisConstant.DISTINCT_OPEKGNUM, String.valueOf(opekgNum), 90, TimeUnit.MINUTES); } Map res = new HashMap<>(); diff --git a/src/main/java/com/easysoftware/common/constant/RedisConstant.java b/src/main/java/com/easysoftware/common/constant/RedisConstant.java index 6b4bb28..19f5c7f 100644 --- a/src/main/java/com/easysoftware/common/constant/RedisConstant.java +++ b/src/main/java/com/easysoftware/common/constant/RedisConstant.java @@ -22,5 +22,5 @@ public final class RedisConstant { /** * Key of distinct application packages. */ - public static final String DISTINCT_APP_PKG = "distinct_apppkg_num"; + public static final String DISTINCT_OPEKGNUM = "distinct_opekg_num"; } -- Gitee