|
|
|
@ -57,6 +57,15 @@ public class DashboardPushTask { |
|
|
|
*/ |
|
|
|
private Map<String, Integer> lastDataHash = new HashMap<>(); |
|
|
|
|
|
|
|
/** |
|
|
|
* 库存趋势缓存(小时级刷新,秒级推送复用) |
|
|
|
* |
|
|
|
* <p>避免10秒推送任务高频查库,将趋势查询拆分为独立的小时任务。</p> |
|
|
|
*/ |
|
|
|
private volatile List<Map<String, Object>> rawMaterialTrendCache = Collections.emptyList(); |
|
|
|
private volatile List<Map<String, Object>> specifiedMaterialTrendCache = Collections.emptyList(); |
|
|
|
private volatile List<Map<String, Object>> finishedGoodsTrendCache = Collections.emptyList(); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private com.gaotao.modules.dashboard.dao.DashboardDao dashboardDao; |
|
|
|
|
|
|
|
@ -541,7 +550,38 @@ public class DashboardPushTask { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 每5秒检查智能立体仓库看板数据并推送 |
|
|
|
* 每1小时刷新一次智能立体仓库库存趋势缓存 |
|
|
|
* |
|
|
|
* <p>趋势数据变化频率低于秒级看板推送频率,拆分为小时级任务可降低数据库压力。</p> |
|
|
|
*/ |
|
|
|
@Scheduled(initialDelay = 0, fixedRate = 3600000) |
|
|
|
public void refreshWarehouseInventoryTrendCache() { |
|
|
|
// 检查总开关 |
|
|
|
if (!dashboardPushEnabled) { |
|
|
|
log.trace("看板推送已禁用,跳过库存趋势缓存刷新"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
List<Map<String, Object>> rawMaterialTrend = dashboardDao.queryRawMaterialInventoryTrend(); |
|
|
|
List<Map<String, Object>> specifiedMaterialTrend = dashboardDao.querySpecifiedMaterialInventoryTrend(); |
|
|
|
List<Map<String, Object>> finishedGoodsTrend = dashboardDao.queryFinishedGoodsInventoryTrend(); |
|
|
|
|
|
|
|
// 查询结果写入新对象再整体替换,避免10秒推送读取到中间态 |
|
|
|
rawMaterialTrendCache = rawMaterialTrend != null ? new ArrayList<>(rawMaterialTrend) : Collections.emptyList(); |
|
|
|
specifiedMaterialTrendCache = specifiedMaterialTrend != null ? new ArrayList<>(specifiedMaterialTrend) : Collections.emptyList(); |
|
|
|
finishedGoodsTrendCache = finishedGoodsTrend != null ? new ArrayList<>(finishedGoodsTrend) : Collections.emptyList(); |
|
|
|
|
|
|
|
log.info("刷新库存趋势缓存完成: 原材料{}条, 规格料{}条, 产成品{}条", |
|
|
|
rawMaterialTrendCache.size(), specifiedMaterialTrendCache.size(), finishedGoodsTrendCache.size()); |
|
|
|
} catch (Exception e) { |
|
|
|
// 刷新失败时保留上一次成功数据,避免看板趋势瞬间被清空 |
|
|
|
log.error("刷新库存趋势缓存失败,沿用上次缓存数据: {}", e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 每10秒检查智能立体仓库看板数据并推送 |
|
|
|
* |
|
|
|
* <p><b>数据来源:</b></p> |
|
|
|
* <ul> |
|
|
|
@ -623,15 +663,12 @@ public class DashboardPushTask { |
|
|
|
Map<String, Object> shipmentStats = new HashMap<>(); |
|
|
|
log.debug("发货统计: {}", shipmentStats); |
|
|
|
|
|
|
|
// 查询库存趋势数据 |
|
|
|
List<Map<String, Object>> rawMaterialTrend = dashboardDao.queryRawMaterialInventoryTrend(); |
|
|
|
log.debug("查询到原材料库存趋势数据: {}条", rawMaterialTrend != null ? rawMaterialTrend.size() : 0); |
|
|
|
|
|
|
|
List<Map<String, Object>> specifiedMaterialTrend = dashboardDao.querySpecifiedMaterialInventoryTrend(); |
|
|
|
log.debug("查询到规格料库存趋势数据: {}条", specifiedMaterialTrend != null ? specifiedMaterialTrend.size() : 0); |
|
|
|
|
|
|
|
List<Map<String, Object>> finishedGoodsTrend = dashboardDao.queryFinishedGoodsInventoryTrend(); |
|
|
|
log.debug("查询到产成品库存趋势数据: {}条", finishedGoodsTrend != null ? finishedGoodsTrend.size() : 0); |
|
|
|
// 使用小时级任务刷新后的库存趋势缓存,避免10秒推送高频查库 |
|
|
|
List<Map<String, Object>> rawMaterialTrend = new ArrayList<>(rawMaterialTrendCache); |
|
|
|
List<Map<String, Object>> specifiedMaterialTrend = new ArrayList<>(specifiedMaterialTrendCache); |
|
|
|
List<Map<String, Object>> finishedGoodsTrend = new ArrayList<>(finishedGoodsTrendCache); |
|
|
|
log.debug("使用库存趋势缓存数据: 原材料{}条, 规格料{}条, 产成品{}条", |
|
|
|
rawMaterialTrend.size(), specifiedMaterialTrend.size(), finishedGoodsTrend.size()); |
|
|
|
|
|
|
|
// 构造返回数据 |
|
|
|
Map<String, Object> resultData = new HashMap<>(); |
|
|
|
|