|
@ -15,10 +15,13 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
import java.sql.Connection;
|
|
import java.sql.Connection;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.SQLException;
|
|
import java.sql.SQLException;
|
|
import java.sql.Statement;
|
|
import java.sql.Statement;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
|
@ -79,6 +82,53 @@ public class RsDictionaryEntryService extends BaseJpaService<RsDictionaryEntry,
|
|
return rsDictionaryEntry.getName();
|
|
return rsDictionaryEntry.getName();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取所有字典项
|
|
|
|
*
|
|
|
|
* @param dict
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<String> getCacheEntries(String dict) {
|
|
|
|
String key = "rs:dict-entry:" + dict + ":*";
|
|
|
|
Set<String> keys = redisClient.keys(key);
|
|
|
|
RsDictionary rsDictionary = rsDictionaryService.findByCode(dict);
|
|
|
|
if (rsDictionary == null) {
|
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
List<RsDictionaryEntry> entries = new ArrayList<>();
|
|
|
|
if (rsDictionary.getDynamic() == 0) {
|
|
|
|
entries = dictionaryEntryDao.findByDictCode(dict);
|
|
|
|
} else {
|
|
|
|
String sql = "select count(1) from (" + rsDictionary.getSql() + ") a";
|
|
|
|
Integer size = jdbcTemplate.queryForObject(sql, (resultSet, i) -> resultSet.getInt(1));
|
|
|
|
|
|
|
|
if (keys.size() != size) {
|
|
|
|
sql = "select code, name from (" + rsDictionary.getSql() + ") a";
|
|
|
|
entries = jdbcTemplate.query(sql, new BeanPropertyRowMapper(RsDictionaryEntry.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HashMap<String, Serializable> map = new HashMap<>(entries.size());
|
|
|
|
ArrayList<String> list = new ArrayList<>();
|
|
|
|
if (keys.size() != entries.size() && entries.size() != 0) {
|
|
|
|
entries.forEach(rsDictionaryEntry -> {
|
|
|
|
String codeKey = "rs:dict-entry:" + dict + ":" + rsDictionaryEntry.getCode();
|
|
|
|
list.add(rsDictionaryEntry.getCode());
|
|
|
|
keys.add(codeKey);
|
|
|
|
map.put(codeKey, rsDictionary.getName());
|
|
|
|
});
|
|
|
|
|
|
|
|
redisClient.multiSetData(map);
|
|
|
|
} else {
|
|
|
|
keys.forEach(value -> {
|
|
|
|
list.add(value.replace("rs:dict-entry:" + dict + ":", ""));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 清空资源字典缓存,资源字典更新时需要调用
|
|
* 清空资源字典缓存,资源字典更新时需要调用
|
|
*
|
|
*
|
|
@ -88,7 +138,7 @@ public class RsDictionaryEntryService extends BaseJpaService<RsDictionaryEntry,
|
|
public void deleteCacheValue(String dict) {
|
|
public void deleteCacheValue(String dict) {
|
|
String key = "rs:dict-entry:" + dict + ":*";
|
|
String key = "rs:dict-entry:" + dict + ":*";
|
|
Set<String> keys = redisClient.keys(key);
|
|
Set<String> keys = redisClient.keys(key);
|
|
keys.forEach(k -> redisClient.delete(k));
|
|
|
|
|
|
redisClient.delete(keys);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|