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; ...@@ -4,9 +4,6 @@ import com.viontech.fanxing.commons.base.DateConverter;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter; 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; import java.util.Date;
...@@ -22,17 +19,4 @@ public class WebConfig { ...@@ -22,17 +19,4 @@ public class WebConfig {
public Converter<String, Date> addNewConvert() { public Converter<String, Date> addNewConvert() {
return new DateConverter(); 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 { ...@@ -26,7 +26,7 @@ public class CacheUtil {
cache(key, o, timeUnit, duration, null, false); 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()); log.info("对数据进行缓存,key:{},缓存时长:{},单位:{}", key, duration, timeUnit.toString());
if (o == null && callable == null) { if (o == null && callable == null) {
throw new RuntimeException("数据和load方法不能都为空"); throw new RuntimeException("数据和load方法不能都为空");
...@@ -38,7 +38,7 @@ public class CacheUtil { ...@@ -38,7 +38,7 @@ public class CacheUtil {
} else { } else {
expire = timeUnit.toMillis(duration) + System.currentTimeMillis(); 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); CACHE.put(key, cacheInfo);
} }
......
...@@ -7,8 +7,7 @@ import java.util.List; ...@@ -7,8 +7,7 @@ import java.util.List;
public class DictCodeVo extends DictCodeVoBase { public class DictCodeVo extends DictCodeVoBase {
private List<DictCodeVo> children; private List children;
private List<ChannelVo> channels;
private Boolean tree; private Boolean tree;
...@@ -20,22 +19,14 @@ public class DictCodeVo extends DictCodeVoBase { ...@@ -20,22 +19,14 @@ public class DictCodeVo extends DictCodeVoBase {
super(dictCode); super(dictCode);
} }
public List<DictCodeVo> getChildren() { public List getChildren() {
return children; return children;
} }
public void setChildren(List<DictCodeVo> children) { public void setChildren(List children) {
this.children = children; this.children = children;
} }
public List<ChannelVo> getChannels() {
return channels;
}
public DictCodeVo setChannels(List<ChannelVo> channels) {
this.channels = channels;
return this;
}
public Boolean getTree() { public Boolean getTree() {
return tree; return tree;
......
...@@ -51,12 +51,12 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan ...@@ -51,12 +51,12 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
} }
DictCodeVo noAddressChannel = new DictCodeVo(); DictCodeVo noAddressChannel = new DictCodeVo();
noAddressChannel.setName("其他"); noAddressChannel.setName("其他");
noAddressChannel.setChannels(new ArrayList<>()); noAddressChannel.setChildren(new ArrayList<>());
Map<String, List<ChannelVo>> addressUnid_channel_map = channels.stream() Map<String, List<ChannelVo>> addressUnid_channel_map = channels.stream()
.map(ChannelVo::new) .map(ChannelVo::new)
.filter(x -> { .filter(x -> {
if (StringUtils.isBlank(x.getAddressUnid())) { if (StringUtils.isBlank(x.getAddressUnid())) {
noAddressChannel.getChannels().add(x); noAddressChannel.getChildren().add(x);
return false; return false;
} }
return true; return true;
...@@ -80,22 +80,24 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan ...@@ -80,22 +80,24 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
String codeUnid = entry.getKey(); String codeUnid = entry.getKey();
DictCodeVo dictCodeVo = unid_code_map.get(codeUnid); DictCodeVo dictCodeVo = unid_code_map.get(codeUnid);
if (dictCodeVo != null) { if (dictCodeVo != null) {
dictCodeVo.setChannels(entry.getValue()); dictCodeVo.setChildren(entry.getValue());
} }
} }
right.removeIf(this::needRemoveFromTree); right.removeIf(this::needRemoveFromTree);
if (noAddressChannel.getChannels().size() > 0) { if (noAddressChannel.getChildren().size() > 0) {
right.add(noAddressChannel); right.add(noAddressChannel);
} }
return right; return right;
} }
private boolean needRemoveFromTree(DictCodeVo dictCodeVo) { private boolean needRemoveFromTree(Object item) {
if (dictCodeVo.getChildren() != null) { if (item instanceof DictCodeVo) {
Iterator<DictCodeVo> iterator = dictCodeVo.getChildren().iterator(); DictCodeVo vo = (DictCodeVo) item;
if (vo.getChildren() != null && vo.getChildren().size() > 0) {
Iterator iterator = vo.getChildren().iterator();
boolean remove = true; boolean remove = true;
while (iterator.hasNext()) { while (iterator.hasNext()) {
DictCodeVo next = iterator.next(); Object next = iterator.next();
if (needRemoveFromTree(next)) { if (needRemoveFromTree(next)) {
iterator.remove(); iterator.remove();
} else { } else {
...@@ -103,9 +105,9 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan ...@@ -103,9 +105,9 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
} }
} }
return remove; return remove;
} else {
return true;
} }
if (dictCodeVo.getChannels() == null) {
return dictCodeVo.getChildren() == null || dictCodeVo.getChildren().size() == 0;
} }
return false; return false;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!