Commit 1927bb4e by xmh

commons:

1. <fix> 去除公共的 cors 配置, gateway 处理跨域即可

ops:
1. <refactor> 重构设备树形结构
1 parent 9d065ccc
......@@ -4,9 +4,6 @@ import com.viontech.fanxing.commons.base.DateConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import java.util.Date;
......@@ -22,17 +19,4 @@ public class WebConfig {
public Converter<String, Date> addNewConvert() {
return new DateConverter();
}
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.setAllowCredentials(true);
config.addAllowedMethod("*");
config.addAllowedHeader("*");
config.setMaxAge(3600L);
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
configSource.registerCorsConfiguration("/**", config);
return new CorsFilter(configSource);
}
}
......@@ -26,7 +26,7 @@ public class CacheUtil {
cache(key, o, timeUnit, duration, null, false);
}
public static void cache(String key, Object o, TimeUnit timeUnit, long duration, Callable callable, boolean accessExpireOnAccess) throws Exception {
public static void cache(String key, Object o, TimeUnit timeUnit, long duration, Callable callable, boolean updateExpireOnAccess) throws Exception {
log.info("对数据进行缓存,key:{},缓存时长:{},单位:{}", key, duration, timeUnit.toString());
if (o == null && callable == null) {
throw new RuntimeException("数据和load方法不能都为空");
......@@ -38,7 +38,7 @@ public class CacheUtil {
} else {
expire = timeUnit.toMillis(duration) + System.currentTimeMillis();
}
CacheInfo cacheInfo = new CacheInfo(key, o, timeUnit, duration, callable, accessExpireOnAccess, expire);
CacheInfo cacheInfo = new CacheInfo(key, o, timeUnit, duration, callable, updateExpireOnAccess, expire);
CACHE.put(key, cacheInfo);
}
......
......@@ -7,8 +7,7 @@ import java.util.List;
public class DictCodeVo extends DictCodeVoBase {
private List<DictCodeVo> children;
private List<ChannelVo> channels;
private List children;
private Boolean tree;
......@@ -20,22 +19,14 @@ public class DictCodeVo extends DictCodeVoBase {
super(dictCode);
}
public List<DictCodeVo> getChildren() {
public List getChildren() {
return children;
}
public void setChildren(List<DictCodeVo> children) {
public void setChildren(List children) {
this.children = children;
}
public List<ChannelVo> getChannels() {
return channels;
}
public DictCodeVo setChannels(List<ChannelVo> channels) {
this.channels = channels;
return this;
}
public Boolean getTree() {
return tree;
......
......@@ -51,12 +51,12 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
}
DictCodeVo noAddressChannel = new DictCodeVo();
noAddressChannel.setName("其他");
noAddressChannel.setChannels(new ArrayList<>());
noAddressChannel.setChildren(new ArrayList<>());
Map<String, List<ChannelVo>> addressUnid_channel_map = channels.stream()
.map(ChannelVo::new)
.filter(x -> {
if (StringUtils.isBlank(x.getAddressUnid())) {
noAddressChannel.getChannels().add(x);
noAddressChannel.getChildren().add(x);
return false;
}
return true;
......@@ -80,32 +80,34 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
String codeUnid = entry.getKey();
DictCodeVo dictCodeVo = unid_code_map.get(codeUnid);
if (dictCodeVo != null) {
dictCodeVo.setChannels(entry.getValue());
dictCodeVo.setChildren(entry.getValue());
}
}
right.removeIf(this::needRemoveFromTree);
if (noAddressChannel.getChannels().size() > 0) {
if (noAddressChannel.getChildren().size() > 0) {
right.add(noAddressChannel);
}
return right;
}
private boolean needRemoveFromTree(DictCodeVo dictCodeVo) {
if (dictCodeVo.getChildren() != null) {
Iterator<DictCodeVo> iterator = dictCodeVo.getChildren().iterator();
boolean remove = true;
while (iterator.hasNext()) {
DictCodeVo next = iterator.next();
if (needRemoveFromTree(next)) {
iterator.remove();
} else {
remove = false;
private boolean needRemoveFromTree(Object item) {
if (item instanceof DictCodeVo) {
DictCodeVo vo = (DictCodeVo) item;
if (vo.getChildren() != null && vo.getChildren().size() > 0) {
Iterator iterator = vo.getChildren().iterator();
boolean remove = true;
while (iterator.hasNext()) {
Object next = iterator.next();
if (needRemoveFromTree(next)) {
iterator.remove();
} else {
remove = false;
}
}
return remove;
} else {
return true;
}
return remove;
}
if (dictCodeVo.getChannels() == null) {
return dictCodeVo.getChildren() == null || dictCodeVo.getChildren().size() == 0;
}
return false;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!