parent
ddef6e4cbd
commit
78354c7933
9 changed files with 258 additions and 61 deletions
@ -0,0 +1,60 @@ |
|||||||
|
package net.mingsoft.cms.upgrade; |
||||||
|
|
||||||
|
import net.mingsoft.basic.util.SpringUtil; |
||||||
|
import net.mingsoft.cms.biz.ICategoryBiz; |
||||||
|
import net.mingsoft.cms.entity.CategoryEntity; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author by 铭飞开源团队 |
||||||
|
* @Description |
||||||
|
* @date 2020/6/19 15:58 |
||||||
|
*/ |
||||||
|
public class Upgrade { |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新栏目分类的顶级节点和叶子节点 |
||||||
|
*/ |
||||||
|
public void upgrade(){ |
||||||
|
ICategoryBiz categoryBiz = SpringUtil.getBean(ICategoryBiz.class); |
||||||
|
List<CategoryEntity> list = categoryBiz.queryAll(); |
||||||
|
|
||||||
|
list.forEach(x->{ |
||||||
|
|
||||||
|
//将parentId第一行设为顶级节点
|
||||||
|
String topId = "0"; |
||||||
|
String parentId = x.getParentids(); |
||||||
|
if (parentId != null) { |
||||||
|
topId = parentId.split(",")[0]; |
||||||
|
} |
||||||
|
x.setTopId(topId); |
||||||
|
|
||||||
|
String id = x.getId(); |
||||||
|
boolean leaf = true; |
||||||
|
//判断是否叶子,循环查找,如果有节点的父节点中包含该节点的id则判断为否跳出循环
|
||||||
|
for (int i = 0; i< list.size(); i++) { |
||||||
|
String pId = list.get(i).getParentids(); |
||||||
|
if (pId == null) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
leaf = !pId.contains(id); |
||||||
|
//如果不是叶子就跳出循环,不需要再判断了
|
||||||
|
if (!leaf) { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
x.setLeaf(leaf); |
||||||
|
//更新
|
||||||
|
Map<String, String> fields = new HashMap<>(); |
||||||
|
fields.put("leaf", x.getLeaf()?"1":"0"); |
||||||
|
fields.put("top_id", x.getTopId()); |
||||||
|
Map<String, String> where = new HashMap<>(); |
||||||
|
where.put("id", x.getId()); |
||||||
|
categoryBiz.updateBySQL("cms_category", fields, where); |
||||||
|
}); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,167 @@ |
|||||||
|
package net.mingsoft.config; |
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource; |
||||||
|
import com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator; |
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature; |
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||||
|
import net.mingsoft.basic.filter.XSSEscapeFilter; |
||||||
|
import net.mingsoft.basic.interceptor.ActionInterceptor; |
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean; |
||||||
|
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.core.Ordered; |
||||||
|
import org.springframework.http.converter.HttpMessageConverter; |
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
||||||
|
import org.springframework.web.context.request.RequestContextListener; |
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
||||||
|
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; |
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.concurrent.ExecutorService; |
||||||
|
import java.util.concurrent.LinkedBlockingQueue; |
||||||
|
import java.util.concurrent.ThreadPoolExecutor; |
||||||
|
import java.util.concurrent.TimeUnit; |
||||||
|
|
||||||
|
@Configuration |
||||||
|
public class WebConfig implements WebMvcConfigurer { |
||||||
|
|
||||||
|
|
||||||
|
@Bean |
||||||
|
public ActionInterceptor actionInterceptor() { |
||||||
|
return new ActionInterceptor(); |
||||||
|
} |
||||||
|
|
||||||
|
// @Bean
|
||||||
|
// public ConfigurationCustomizer configurationCustomizer() {
|
||||||
|
// return configuration -> configuration.setUseDeprecatedExecutor(false);
|
||||||
|
// }
|
||||||
|
// 最新版
|
||||||
|
// @Bean
|
||||||
|
// public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
// MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
// interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.));
|
||||||
|
// return interceptor;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 增加对rest api鉴权的spring mvc拦截器 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void addInterceptors(InterceptorRegistry registry) { |
||||||
|
// 排除配置
|
||||||
|
registry.addInterceptor(actionInterceptor()).excludePathPatterns("/static/**", "/app/**", "/webjars/**", |
||||||
|
"/*.html", "/*.htm"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) { |
||||||
|
String uploadMapping = MSProperties.upload.mapping; |
||||||
|
String uploadFloderPath = MSProperties.upload.path; |
||||||
|
String template = MSProperties.upload.template; |
||||||
|
String htmlDir = MSProperties.htmlDir; |
||||||
|
registry.addResourceHandler(uploadMapping).addResourceLocations(File.separator + uploadFloderPath + File.separator, "file:" + uploadFloderPath + File.separator); |
||||||
|
registry.addResourceHandler("/template/**").addResourceLocations(File.separator + template + File.separator, "file:" + template + File.separator); |
||||||
|
registry.addResourceHandler("/"+htmlDir+"/**").addResourceLocations("/"+htmlDir+"/", "file:"+htmlDir+"/"); |
||||||
|
//三种映射方式 webapp下、当前目录下、jar内
|
||||||
|
registry.addResourceHandler("/app/**").addResourceLocations("/app/", "file:app/", "classpath:/app/"); |
||||||
|
registry.addResourceHandler("/static/**").addResourceLocations("/static/", "file:static/", "classpath:/static/", "classpath:/META-INF/resources/"); |
||||||
|
registry.addResourceHandler("/api/**").addResourceLocations("/api/", "file:api/", "classpath:/api/"); |
||||||
|
if (new File(uploadFloderPath).isAbsolute()) { |
||||||
|
//如果指定了绝对路径,上传的文件都映射到uploadMapping下
|
||||||
|
registry.addResourceHandler(uploadMapping).addResourceLocations("file:" + uploadFloderPath + File.separator |
||||||
|
//映射其他路径文件
|
||||||
|
//,file:F://images
|
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* druid数据库连接池监控 |
||||||
|
*/ |
||||||
|
@Bean |
||||||
|
public BeanTypeAutoProxyCreator beanTypeAutoProxyCreator() { |
||||||
|
BeanTypeAutoProxyCreator beanTypeAutoProxyCreator = new BeanTypeAutoProxyCreator(); |
||||||
|
beanTypeAutoProxyCreator.setTargetBeanType(DruidDataSource.class); |
||||||
|
beanTypeAutoProxyCreator.setInterceptorNames("druidStatInterceptor"); |
||||||
|
return beanTypeAutoProxyCreator; |
||||||
|
} |
||||||
|
|
||||||
|
//XSS过滤器
|
||||||
|
@Bean |
||||||
|
public FilterRegistrationBean xssFilterRegistration() { |
||||||
|
XSSEscapeFilter xssFilter = new XSSEscapeFilter(); |
||||||
|
FilterRegistrationBean registration = new FilterRegistrationBean(); |
||||||
|
registration.setName("XSSFilter"); |
||||||
|
registration.addUrlPatterns("/*"); |
||||||
|
registration.setOrder(Ordered.HIGHEST_PRECEDENCE); |
||||||
|
xssFilter.includes.add(".*/search.do"); |
||||||
|
Map<String, String> initParameters = new HashMap(); |
||||||
|
boolean enable = true; |
||||||
|
initParameters.put("isIncludeRichText", "false"); |
||||||
|
registration.setInitParameters(initParameters); |
||||||
|
registration.setFilter(xssFilter); |
||||||
|
registration.setEnabled(enable); |
||||||
|
return registration; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* RequestContextListener注册 |
||||||
|
*/ |
||||||
|
@Bean |
||||||
|
public ServletListenerRegistrationBean<RequestContextListener> requestContextListenerRegistration() { |
||||||
|
return new ServletListenerRegistrationBean<>(new RequestContextListener()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置默认首页 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void addViewControllers(ViewControllerRegistry registry) { |
||||||
|
registry.addViewController("/").setViewName("forward:/index"); |
||||||
|
registry.setOrder(Ordered.HIGHEST_PRECEDENCE); |
||||||
|
WebMvcConfigurer.super.addViewControllers(registry); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 解决com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException 问题,提交实体不存在的字段异常 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
||||||
|
// TODO Auto-generated method stub
|
||||||
|
converters.add(mappingJackson2HttpMessageConverter()); |
||||||
|
WebMvcConfigurer.super.configureMessageConverters(converters); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Bean |
||||||
|
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { |
||||||
|
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); |
||||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||||
|
|
||||||
|
//添加此配置
|
||||||
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
||||||
|
converter.setObjectMapper(objectMapper); |
||||||
|
return converter; |
||||||
|
} |
||||||
|
|
||||||
|
@Bean |
||||||
|
public ExecutorService crawlExecutorPool() { |
||||||
|
// 创建线程池
|
||||||
|
ExecutorService pool = |
||||||
|
new ThreadPoolExecutor(20, 20, |
||||||
|
0L, TimeUnit.MILLISECONDS, |
||||||
|
new LinkedBlockingQueue<Runnable>()); |
||||||
|
return pool; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue