Browse Source

fix: 增加仓库查询的缓存

pull/7/head
pref_mail@163.com 10 months ago
parent
commit
a3d6409490
  1. 73
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/feign/BasicdataWarehouseClient.java

73
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/feign/BasicdataWarehouseClient.java

@ -106,39 +106,19 @@ public class BasicdataWarehouseClient implements IBasicdataWarehouseClient {
@Override
public BasicdataWarehouseEntity getWarehouseEntityByWarehouseCode(String warehouseCode) {
QueryWrapper<BasicdataWarehouseEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("warehouse_code",warehouseCode)
.eq("is_deleted",0)
.eq("enable_status",2);
String key =RedisKeyConstant.BASIC_DATA_WAREHOUSE_KEY + warehouseCode;
BasicdataWarehouseEntity o = bladeRedis.get(key);
log.info(">>> 获取的仓库的信息 o ={}",o);
if(ObjectUtils.isNull(o)){
QueryWrapper<BasicdataWarehouseEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("warehouse_code",warehouseCode)
.eq("is_deleted",0)
.eq("enable_status",2);
List<BasicdataWarehouseEntity> list = warehouseWarehouseService.list(queryWrapper);
if(!Objects.isNull(list) && !list.isEmpty()){
// 寻找中心仓
for (BasicdataWarehouseEntity basicdataWarehouseEntity : list) {
if(basicdataWarehouseEntity.getFunctionType().equals("2")){
o = basicdataWarehouseEntity;
}
}
// 找不到 就去第一个
if(ObjectUtils.isNull(o)){
o= list.get(0);
}
// 设定缓存时间 1小时的缓存时间
bladeRedis.setEx(key,o, 60 * 60L);
}
List<BasicdataWarehouseEntity> list = warehouseWarehouseService.list(queryWrapper);
if(!Objects.isNull(list) && !list.isEmpty()){
return list.get(0);
}else{
return null;
}
return o;
}
@ -192,16 +172,39 @@ public class BasicdataWarehouseClient implements IBasicdataWarehouseClient {
String key =RedisKeyConstant.BASIC_DATA_WAREHOUSE_KEY + deptId;
BasicdataWarehouseEntity o = bladeRedis.get(key);
log.info(">>> 获取的仓库的信息 o ={}",o);
if(ObjectUtils.isNull(o)){
QueryWrapper<BasicdataWarehouseEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("department",deptId)
.eq("is_deleted",0)
.eq("enable_status",2);
List<BasicdataWarehouseEntity> list = warehouseWarehouseService.list(queryWrapper);
if(!Objects.isNull(list) && !list.isEmpty()){
// 寻找中心仓
for (BasicdataWarehouseEntity basicdataWarehouseEntity : list) {
if(basicdataWarehouseEntity.getFunctionType().equals("2")){
o = basicdataWarehouseEntity;
}
}
// 找不到 就去第一个
if(ObjectUtils.isNull(o)){
o= list.get(0);
}
// 设定缓存时间 1小时的缓存时间
bladeRedis.setEx(key,o, 60 * 60L);
}
}
return o;
QueryWrapper<BasicdataWarehouseEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("department",deptId)
.eq("is_deleted",0)
.eq("enable_status",2);
List<BasicdataWarehouseEntity> list = warehouseWarehouseService.list(queryWrapper);
return list.get(0);
}
@Override

Loading…
Cancel
Save