| | |
| | | package com.consum.base.cache; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import com.consum.base.Constants; |
| | | import com.consum.base.FinSysTenantCacheProvider; |
| | | import com.consum.base.service.FinSysTenantServiceImpl; |
| | | import com.consum.base.service.FinSysTenantService; |
| | | import com.consum.model.po.FinSysTenant; |
| | | import com.walker.infrastructure.ApplicationRuntimeException; |
| | | import com.walker.infrastructure.utils.JsonUtils; |
| | | import com.walker.support.redis.cache.RedisCacheProvider; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 区划缓存 |
| | | * @作者:power |
| | | * @时间:2023/7/20 20:35 |
| | | * |
| | | * @作者:power @时间:2023/7/20 20:35 |
| | | */ |
| | | public class RedisFinSysTenantCache extends RedisCacheProvider<FinSysTenant> implements FinSysTenantCacheProvider { |
| | | public RedisFinSysTenantCache(){ |
| | | public RedisFinSysTenantCache() { |
| | | this.setUseRedis(true); |
| | | this.setLoadPage(false); |
| | | } |
| | | |
| | | @Override |
| | | public FinSysTenant get(String code) { |
| | | FinSysTenant finSysTenant = this.getCacheData(code); |
| | | if(finSysTenant == null){ |
| | | if (finSysTenant == null) { |
| | | finSysTenant = this.finSysTenantService.queryOneByCode(code); |
| | | if(finSysTenant == null){ |
| | | if (finSysTenant == null) { |
| | | logger.warn("从数据库未查询到区划,无法缓存,code = {}", code); |
| | | return null; |
| | | } |
| | | |
| | | // 2023-07-26,时克英,区划相对固定,无需设置失效时间,让他永远存储吧。 |
| | | // this.putCacheData(code, finSysTenant,7200); |
| | | // this.putCacheData(code, finSysTenant,7200); |
| | | this.putCacheData(code, finSysTenant); |
| | | } |
| | | return finSysTenant; |
| | |
| | | @Override |
| | | public FinSysTenant getById(String id) { |
| | | FinSysTenant finSysTenant = this.getCacheData(id); |
| | | if(finSysTenant == null){ |
| | | if (finSysTenant == null) { |
| | | finSysTenant = this.finSysTenantService.get(new FinSysTenant(Long.parseLong(id))); |
| | | if(finSysTenant == null){ |
| | | if (finSysTenant == null) { |
| | | logger.warn("从数据库未查询到区划,无法缓存,id = {}", id); |
| | | return null; |
| | | } |
| | |
| | | public List<FinSysTenant> selectAll() { |
| | | List<FinSysTenant> allTree = new ArrayList<>(); |
| | | FinSysTenant temp = null; |
| | | for(String value : this.getCache().getIterator(null)) { |
| | | for (String value : this.getCache().getIterator(null)) { |
| | | try { |
| | | temp = JsonUtils.jsonStringToObject(value, FinSysTenant.class); |
| | | } catch (Exception ex) { |
| | | throw new ApplicationRuntimeException("redis存储'EbProductBrand'解析错吴:"+ value,ex); |
| | | throw new ApplicationRuntimeException("redis存储'EbProductBrand'解析错吴:" + value, ex); |
| | | } |
| | | allTree.add(temp); |
| | | } |
| | |
| | | return FinSysTenant.class; |
| | | } |
| | | |
| | | public void setFinSysTenantService(FinSysTenantServiceImpl finSysTenantService) { |
| | | public void setFinSysTenantService(FinSysTenantService finSysTenantService) { |
| | | this.finSysTenantService = finSysTenantService; |
| | | } |
| | | |
| | | private FinSysTenantServiceImpl finSysTenantService; |
| | | private FinSysTenantService finSysTenantService; |
| | | } |