From 4be25324dd4fc0c83830c3fbd45c90fcdacfc051 Mon Sep 17 00:00:00 2001 From: gongbaoxiong Date: Sat, 13 Jul 2024 10:28:32 +0800 Subject: [PATCH] =?UTF-8?q?opt:=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=8D=95=E6=8D=AE=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nl/common/base/RestBusinessTemplate.java | 2 +- .../eas/service/IeasOutInBillService.java | 9 ++++++++ .../service/impl/EasOutInBillServiceImpl.java | 23 ++++++++++++++++++- .../org/nl/wms/schedule/EasBillSchedule.java | 22 ++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/nlsso-server/src/main/java/org/nl/common/base/RestBusinessTemplate.java b/nlsso-server/src/main/java/org/nl/common/base/RestBusinessTemplate.java index a4a1ec5..0c9e45a 100644 --- a/nlsso-server/src/main/java/org/nl/common/base/RestBusinessTemplate.java +++ b/nlsso-server/src/main/java/org/nl/common/base/RestBusinessTemplate.java @@ -64,7 +64,7 @@ public class RestBusinessTemplate { try { callback.execute(); result.setCode(ResultCode.SUCCESS.getCode()); - result.setDesc("推送中,如未审核成功,请查看单据审核结果信息。"); + result.setDesc("正在推送,如未审核成功,请查看单据审核结果信息。"); } catch (BadRequestException e) { log.error("", e); ResultCode code = e.getCode() == null ? ResultCode.FAILED : e.getCode(); diff --git a/nlsso-server/src/main/java/org/nl/wms/database/eas/service/IeasOutInBillService.java b/nlsso-server/src/main/java/org/nl/wms/database/eas/service/IeasOutInBillService.java index 129afcb..8dbfe33 100644 --- a/nlsso-server/src/main/java/org/nl/wms/database/eas/service/IeasOutInBillService.java +++ b/nlsso-server/src/main/java/org/nl/wms/database/eas/service/IeasOutInBillService.java @@ -39,6 +39,15 @@ public interface IeasOutInBillService extends IService { List getBillsCount(); + /** + * 查询出入库单据数量 + * + * @return JSONObject + */ + List queryBillsCount(); + + + /** * 获取组织机构信息 * diff --git a/nlsso-server/src/main/java/org/nl/wms/database/eas/service/impl/EasOutInBillServiceImpl.java b/nlsso-server/src/main/java/org/nl/wms/database/eas/service/impl/EasOutInBillServiceImpl.java index 6b88137..79b0b91 100644 --- a/nlsso-server/src/main/java/org/nl/wms/database/eas/service/impl/EasOutInBillServiceImpl.java +++ b/nlsso-server/src/main/java/org/nl/wms/database/eas/service/impl/EasOutInBillServiceImpl.java @@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils; import org.nl.common.base.CommonPage; import org.nl.common.enums.wms.EasBillTypeEnum; import org.nl.common.exception.BadRequestException; +import org.nl.common.utils.RedisUtils; import org.nl.common.utils.SecurityUtils; import org.nl.config.IdUtil; import org.nl.wms.database.eas.dao.*; @@ -30,6 +31,7 @@ import org.nl.wms.ext.srm.WmsToSrmService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -45,6 +47,7 @@ import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import java.util.stream.Collectors; @@ -83,10 +86,28 @@ public class EasOutInBillServiceImpl extends ServiceImpl getBillsCount() { + String cacheKey = "billCounts"; + //从Redis中获取缓存数据 + List cachedCounts = (List) redisUtils.get(cacheKey); + if (cachedCounts != null) { + return cachedCounts; + } + List allCounts = queryBillsCount(); + // 将结果存入Redis,设置过期时间为1小时 + redisUtils.set(cacheKey, allCounts, 1, TimeUnit.HOURS); + return allCounts; + } + /** * 首页显示出入库单据数量 */ - public List getBillsCount() { + public List queryBillsCount() { AtomicReference receiptCount = new AtomicReference<>(0L); AtomicReference allocationCount = new AtomicReference<>(0L); AtomicReference> inOutBillList = new AtomicReference<>(); diff --git a/nlsso-server/src/main/java/org/nl/wms/schedule/EasBillSchedule.java b/nlsso-server/src/main/java/org/nl/wms/schedule/EasBillSchedule.java index fe99310..e43bb90 100644 --- a/nlsso-server/src/main/java/org/nl/wms/schedule/EasBillSchedule.java +++ b/nlsso-server/src/main/java/org/nl/wms/schedule/EasBillSchedule.java @@ -3,11 +3,13 @@ import cn.dev33.satoken.annotation.SaIgnore; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.nl.common.utils.RedisUtils; import org.nl.common.websocket.SendHomeWebSocketServer; import org.nl.config.IdUtil; import org.nl.system.service.user.dao.SysUser; import org.nl.system.service.user.dao.mapper.SysUserMapper; import org.nl.wms.database.eas.dao.EasOutInBillDetail; +import org.nl.wms.database.eas.dao.HomeBillCounts; import org.nl.wms.database.eas.dao.mapper.EasOutInBillDetailMapper; import org.nl.wms.database.eas.service.IeasOutInBillService; import org.springframework.scheduling.annotation.Async; @@ -19,6 +21,7 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.nl.wms.database.eas.dao.EasOutInBill; @@ -42,6 +45,15 @@ public class EasBillSchedule { @Resource private SysUserMapper sysUserMapper; + @Resource + private IeasOutInBillService ieasOutInBillService; + + + + @Resource + private RedisUtils redisUtils; + + /** * eas单据数据同步 */ @@ -130,6 +142,16 @@ public class EasBillSchedule { } + /** + * 首页单据查询 + */ + @Async("taskExecutor") + @Scheduled(cron = "0/30 * * * * *") + public void updateRedisCache() { + List billsCount = ieasOutInBillService.queryBillsCount(); + redisUtils.set("billCounts", billsCount, 1, TimeUnit.HOURS); + } + /** * 首页信息推送 */