提交 edcc4126 authored 作者: zjm's avatar zjm

fix(库房模块): 添加库房的缓存

添加库房的缓存
上级 3306f2a2
......@@ -2,14 +2,8 @@ package com.tykj.dev.device.confirmcheck.entity.cache;
import com.tykj.dev.config.cache.ConfigCache;
import com.tykj.dev.config.repository.SystemConfigDao;
import com.tykj.dev.device.user.cache.AreaCache;
import com.tykj.dev.device.user.cache.AreaExhibitionCache;
import com.tykj.dev.device.user.cache.UnitsCache;
import com.tykj.dev.device.user.cache.UserCache;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.dao.AreaExhibitionDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.dao.UserDao;
import com.tykj.dev.device.user.cache.*;
import com.tykj.dev.device.user.subject.dao.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -38,6 +32,10 @@ public class CacheBeanConfig {
@Autowired
AreaExhibitionDao areaExhibitionDao;
@Autowired
UnitStoreLocationDao unitStoreLocationDao;
@Bean
public AreaCache initAreaCache() {
return new AreaCache(areaRepo.findAll());
......@@ -61,4 +59,10 @@ public class CacheBeanConfig {
public ConfigCache initConfigCache(){
return new ConfigCache(systemConfigDao.findAll());
}
@Bean
public StoreCache initStoreCache(){
return new StoreCache(unitStoreLocationDao.findAllByTypeName("存放位置"));
}
}
package com.tykj.dev.device.user.cache;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.UnitStoreLocation;
import com.tykj.dev.device.user.subject.service.UnitStoreLocationService;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* AreaCache.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/9/22 at 5:33 下午
*/
@Data
public class StoreCache {
private Map<Integer, String> idMap;
public StoreCache(List<UnitStoreLocation> unitStoreLocations) {
idMap = unitStoreLocations.stream().collect(Collectors.toMap(UnitStoreLocation::getId, UnitStoreLocation::getStoreName));
}
public StoreCache refresh(List<UnitStoreLocation> unitStoreLocations) {
idMap = unitStoreLocations.stream().collect(Collectors.toMap(UnitStoreLocation::getId, UnitStoreLocation::getStoreName));
return this;
}
public String idToName(Integer id){
return idMap.getOrDefault(id, "");
}
}
package com.tykj.dev.device.user.subject.service.impl;
import com.tykj.dev.device.user.base.req.UnitStoreLocationVo;
import com.tykj.dev.device.user.cache.StoreCache;
import com.tykj.dev.device.user.subject.dao.UnitStoreLocationDao;
import com.tykj.dev.device.user.subject.entity.UnitStoreLocation;
import com.tykj.dev.device.user.subject.service.UnitStoreLocationService;
......@@ -29,6 +30,9 @@ public class UnitStoreLocationServiceImpl implements UnitStoreLocationService {
@Autowired
UnitStoreLocationDao unitStoreLocationDao;
@Autowired
StoreCache storeCache;
@Override
public List<UnitStoreLocation> findAllByUnitIdAndTypeName(UnitStoreLocationVo unitStoreLocationVo) {
return unitStoreLocationDao.findAllByUnitIdAndTypeName(unitStoreLocationVo.getUnitId(),unitStoreLocationVo.getTypeName()).stream().sorted(Comparator.comparing(UnitStoreLocation::getShowOrder)).collect(Collectors.toList());
......@@ -70,7 +74,9 @@ public class UnitStoreLocationServiceImpl implements UnitStoreLocationService {
throw new ApiException(ResponseEntity.status(20020).body("区域名称重复"));
}
}
return unitStoreLocationDao.save(unitStoreLocation);
unitStoreLocation= unitStoreLocationDao.save(unitStoreLocation);
storeCache.refresh(unitStoreLocationDao.findAllByTypeName("存放位置"));
return unitStoreLocation;
}
@Override
......@@ -86,6 +92,8 @@ public class UnitStoreLocationServiceImpl implements UnitStoreLocationService {
@Override
public UnitStoreLocation update(UnitStoreLocation unitStoreLocation) {
return unitStoreLocationDao.save(unitStoreLocation);
unitStoreLocation= unitStoreLocationDao.save(unitStoreLocation);
storeCache.refresh(unitStoreLocationDao.findAllByTypeName("存放位置"));
return unitStoreLocation;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论