From 5a6dc3f25b838e8431c291061d7b923617a34643 Mon Sep 17 00:00:00 2001 From: XieChengzhi Date: Mon, 12 Aug 2024 19:19:05 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90feature=E3=80=91redis=E7=BC=93?= =?UTF-8?q?=E5=AD=98opekg=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FieldApplicationServiceImpl.java | 22 +++++++++++++++- .../common/constant/RedisConstant.java | 26 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) 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..27a04e6 100644 --- a/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java +++ b/src/main/java/com/easysoftware/application/filedapplication/FieldApplicationServiceImpl.java @@ -27,6 +27,7 @@ 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 +44,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 +62,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 +135,11 @@ public class FieldApplicationServiceImpl implements FieldApplicationService { */ @Resource private ArchNumGateway archNumGateway; + /** + * gateway. + */ + @Resource + private RedisGateway redisGateway; /** * Query menu by name. @@ -441,11 +449,23 @@ public class FieldApplicationServiceImpl implements FieldApplicationService { */ @Override public ResponseEntity queryStat() { + Long opekgNum; Long appNum = appGateway.queryTableLength(); + String opeknumString = redisGateway.get(RedisConstant.DISTINCT_OPEKGNUM); + + if (opeknumString != null) { + opekgNum = Long.parseLong(opeknumString); + } else { + opekgNum = oePkgGateway.queryTableLength(); + if(opekgNum != null && opekgNum > PackageConstant.SOFTWARE_NUM) { + redisGateway.setWithExpire(RedisConstant.DISTINCT_OPEKGNUM, String.valueOf(opekgNum), 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..9ce990c --- /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_opekg_nums. + */ + public static final String DISTINCT_OPEKGNUM = "distinct_opekg_num"; +} -- Gitee