From c2454e207120e2d88844c107c45c083947280db4 Mon Sep 17 00:00:00 2001
From: yuanye <418471657@qq.com>
Date: Fri, 19 Jul 2024 17:38:43 +0800
Subject: [PATCH] 1
---
.gitignore | 29 ++
bweb/pom.xml | 45 +++
bweb/src/main/java/com/BWebApplication.java | 30 ++
.../main/java/com/bweb/config/AuthConfig.java | 127 +++++++
.../java/com/bweb/config/ConfigListener.java | 24 ++
.../main/java/com/bweb/config/CorsConfig.java | 49 +++
.../java/com/bweb/config/MultipartConfig.java | 26 ++
.../java/com/bweb/config/RedisConfig.java | 109 ++++++
.../java/com/bweb/config/SwaggerConfig.java | 47 +++
.../main/java/com/bweb/config/SysConfig.java | 17 +
.../main/java/com/bweb/config/SysConst.java | 19 ++
.../com/bweb/controller/BsUserController.java | 117 +++++++
.../com/bweb/controller/CommonController.java | 49 +++
.../bweb/controller/FileUploadController.java | 98 ++++++
.../bweb/controller/SecMenuController.java | 301 +++++++++++++++++
.../bweb/controller/SecRoleController.java | 144 ++++++++
.../bweb/controller/SecUserController.java | 310 ++++++++++++++++++
.../controller/cms/CmsContentController.java | 156 +++++++++
bweb/src/main/resources/dev/application.yml | 89 +++++
bweb/src/main/resources/dev/config.properties | 1 +
bweb/src/main/resources/dev/logback.xml | 72 ++++
bweb/src/main/resources/pre/application.yml | 56 ++++
bweb/src/main/resources/pre/config.properties | 2 +
bweb/src/main/resources/pre/logback.xml | 72 ++++
bweb/src/main/resources/prod/application.yml | 86 +++++
.../src/main/resources/prod/config.properties | 1 +
bweb/src/main/resources/prod/logback.xml | 72 ++++
cweb/pom.xml | 45 +++
cweb/src/main/java/com/CWebApplication.java | 30 ++
.../main/java/com/cweb/config/AuthConfig.java | 130 ++++++++
.../java/com/cweb/config/ConfigListener.java | 25 ++
.../main/java/com/cweb/config/CorsConfig.java | 49 +++
.../java/com/cweb/config/MultipartConfig.java | 26 ++
.../java/com/cweb/config/RedisConfig.java | 110 +++++++
.../java/com/cweb/config/SwaggerConfig.java | 47 +++
.../main/java/com/cweb/config/SysConfig.java | 17 +
.../main/java/com/cweb/config/SysConst.java | 19 ++
.../com/cweb/config/WxMaConfiguration.java | 33 ++
.../com/cweb/controller/CommonController.java | 60 ++++
.../cweb/controller/FileUploadController.java | 103 ++++++
.../controller/cms/CmsContentController.java | 51 +++
cweb/src/main/resources/dev/application.yml | 89 +++++
cweb/src/main/resources/dev/config.properties | 1 +
cweb/src/main/resources/dev/logback.xml | 72 ++++
cweb/src/main/resources/pre/application.yml | 56 ++++
cweb/src/main/resources/pre/config.properties | 1 +
cweb/src/main/resources/pre/logback.xml | 72 ++++
cweb/src/main/resources/prod/application.yml | 86 +++++
.../src/main/resources/prod/config.properties | 1 +
cweb/src/main/resources/prod/logback.xml | 95 ++++++
pom.xml | 68 ++++
service/pom.xml | 260 +++++++++++++++
.../resources/dev/commonConfig.properties | 15 +
.../resources/pre/commonConfig.properties | 0
.../resources/prod/commonConfig.properties | 14 +
55 files changed, 3723 insertions(+)
create mode 100644 .gitignore
create mode 100644 bweb/pom.xml
create mode 100644 bweb/src/main/java/com/BWebApplication.java
create mode 100644 bweb/src/main/java/com/bweb/config/AuthConfig.java
create mode 100644 bweb/src/main/java/com/bweb/config/ConfigListener.java
create mode 100644 bweb/src/main/java/com/bweb/config/CorsConfig.java
create mode 100644 bweb/src/main/java/com/bweb/config/MultipartConfig.java
create mode 100644 bweb/src/main/java/com/bweb/config/RedisConfig.java
create mode 100644 bweb/src/main/java/com/bweb/config/SwaggerConfig.java
create mode 100644 bweb/src/main/java/com/bweb/config/SysConfig.java
create mode 100644 bweb/src/main/java/com/bweb/config/SysConst.java
create mode 100644 bweb/src/main/java/com/bweb/controller/BsUserController.java
create mode 100644 bweb/src/main/java/com/bweb/controller/CommonController.java
create mode 100644 bweb/src/main/java/com/bweb/controller/FileUploadController.java
create mode 100644 bweb/src/main/java/com/bweb/controller/SecMenuController.java
create mode 100644 bweb/src/main/java/com/bweb/controller/SecRoleController.java
create mode 100644 bweb/src/main/java/com/bweb/controller/SecUserController.java
create mode 100644 bweb/src/main/java/com/bweb/controller/cms/CmsContentController.java
create mode 100644 bweb/src/main/resources/dev/application.yml
create mode 100644 bweb/src/main/resources/dev/config.properties
create mode 100644 bweb/src/main/resources/dev/logback.xml
create mode 100644 bweb/src/main/resources/pre/application.yml
create mode 100644 bweb/src/main/resources/pre/config.properties
create mode 100644 bweb/src/main/resources/pre/logback.xml
create mode 100644 bweb/src/main/resources/prod/application.yml
create mode 100644 bweb/src/main/resources/prod/config.properties
create mode 100644 bweb/src/main/resources/prod/logback.xml
create mode 100644 cweb/pom.xml
create mode 100644 cweb/src/main/java/com/CWebApplication.java
create mode 100644 cweb/src/main/java/com/cweb/config/AuthConfig.java
create mode 100644 cweb/src/main/java/com/cweb/config/ConfigListener.java
create mode 100644 cweb/src/main/java/com/cweb/config/CorsConfig.java
create mode 100644 cweb/src/main/java/com/cweb/config/MultipartConfig.java
create mode 100644 cweb/src/main/java/com/cweb/config/RedisConfig.java
create mode 100644 cweb/src/main/java/com/cweb/config/SwaggerConfig.java
create mode 100644 cweb/src/main/java/com/cweb/config/SysConfig.java
create mode 100644 cweb/src/main/java/com/cweb/config/SysConst.java
create mode 100644 cweb/src/main/java/com/cweb/config/WxMaConfiguration.java
create mode 100644 cweb/src/main/java/com/cweb/controller/CommonController.java
create mode 100644 cweb/src/main/java/com/cweb/controller/FileUploadController.java
create mode 100644 cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java
create mode 100644 cweb/src/main/resources/dev/application.yml
create mode 100644 cweb/src/main/resources/dev/config.properties
create mode 100644 cweb/src/main/resources/dev/logback.xml
create mode 100644 cweb/src/main/resources/pre/application.yml
create mode 100644 cweb/src/main/resources/pre/config.properties
create mode 100644 cweb/src/main/resources/pre/logback.xml
create mode 100644 cweb/src/main/resources/prod/application.yml
create mode 100644 cweb/src/main/resources/prod/config.properties
create mode 100644 cweb/src/main/resources/prod/logback.xml
create mode 100644 pom.xml
create mode 100644 service/pom.xml
create mode 100644 service/src/main/resources/dev/commonConfig.properties
create mode 100644 service/src/main/resources/pre/commonConfig.properties
create mode 100644 service/src/main/resources/prod/commonConfig.properties
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d578bba
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,29 @@
+.idea
+log
+parent.iml
+
+service/target/*
+
+bweb/target/*
+bweb/log/*
+bweb/bweb.iml
+
+cweb/target/*
+cweb/log/*
+cweb/cweb.iml
+
+order/target/*
+order/log/*
+order/order.iml
+
+user/target/*
+user/log/*
+user/cweb.iml
+
+openapi/target/*
+openapi/log/*
+openapi/cweb.iml
+
+schedule/target/*
+schedule/log/*
+schedule/demo-schedule.iml
diff --git a/bweb/pom.xml b/bweb/pom.xml
new file mode 100644
index 0000000..9efab17
--- /dev/null
+++ b/bweb/pom.xml
@@ -0,0 +1,45 @@
+
+
+
+ com.cg
+ cg-parent
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ com.cg
+ bweb
+
+
+
+ com.cg
+ service
+ PACKT-SNAPSHOT
+
+
+
+
+
+
+ src/main/resources/${env}
+ false
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
diff --git a/bweb/src/main/java/com/BWebApplication.java b/bweb/src/main/java/com/BWebApplication.java
new file mode 100644
index 0000000..47b9e43
--- /dev/null
+++ b/bweb/src/main/java/com/BWebApplication.java
@@ -0,0 +1,30 @@
+package com;
+
+import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
+import com.alicp.jetcache.anno.config.EnableMethodCache;
+import com.cg.common.utils.SpringContextUtil;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import org.springframework.context.ApplicationContext;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+@SpringBootApplication
+// @ComponentScan
+@EnableTransactionManagement
+@EnableScheduling
+@EnableMethodCache(basePackages = "com.cg")
+@EnableCreateCacheAnnotation
+@ServletComponentScan
+@MapperScan("com.cg.dao")
+public class BWebApplication
+{
+ public static void main( String[] args )
+ {
+ ApplicationContext app = SpringApplication.run(BWebApplication.class, args);
+ SpringContextUtil.setApplicationContext(app);
+ }
+
+}
diff --git a/bweb/src/main/java/com/bweb/config/AuthConfig.java b/bweb/src/main/java/com/bweb/config/AuthConfig.java
new file mode 100644
index 0000000..c799dbf
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/config/AuthConfig.java
@@ -0,0 +1,127 @@
+package com.cweb.config;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.cg.common.security.UserCenter;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+@Configuration
+public class AuthConfig implements WebMvcConfigurer {
+
+ private static Logger log = LoggerFactory.getLogger(AuthConfig.class);
+
+ @Resource
+ private UserCenter userCenter;
+
+ /**
+ * 获取配置文件debug变量
+ */
+ @Value("${debug}")
+ private boolean debug = false;
+
+ /**
+ * 解决18位long类型数据转json失去精度问题
+ * @param converters
+ */
+ @Override
+ public void configureMessageConverters(List> converters){
+ MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
+
+ ObjectMapper objectMapper = jsonConverter.getObjectMapper();
+ SimpleModule simpleModule = new SimpleModule();
+ simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
+ simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
+ objectMapper.registerModule(simpleModule);
+
+ converters.add(jsonConverter);
+ }
+
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new HandlerInterceptorAdapter() {
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
+ Object handler) throws Exception {
+ if(debug){
+ return true;
+ }
+ String token = request.getHeader("Authorization");
+
+ if(StringUtils.isNotBlank(token) && userCenter.isLogin(token)){//如果未登录,将无法使用任何接口
+ return true;
+ } else if(request instanceof StandardMultipartHttpServletRequest) {
+ StandardMultipartHttpServletRequest re = (StandardMultipartHttpServletRequest)request;
+ if(userCenter.isLogin(re.getRequest())){
+ return true;
+ } else {
+ log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL());
+ response.setStatus(401);
+ return false;
+ }
+ } else{
+ log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL());
+ response.setStatus(401);
+ return false;
+ }
+ }
+ })
+ .addPathPatterns("/**")
+ .excludePathPatterns("/swagger-resources/**")
+ .excludePathPatterns("/**/api-docs")
+ .excludePathPatterns("/**/springfox-swagger-ui/**")
+ .excludePathPatterns("/**/swagger-ui.html")
+ .excludePathPatterns("/fileUpload/*")
+ .excludePathPatterns("/common/*")
+ .excludePathPatterns("/secMenu/queryMenuList")
+ ;
+ }
+
+ public String getIpAddress(HttpServletRequest request) {
+ // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址
+ String ip = request.getHeader("X-Forwarded-For");
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("Proxy-Client-IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("WL-Proxy-Client-IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_CLIENT_IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getRemoteAddr();
+ }
+ } else if (ip.length() > 15) {
+ String[] ips = ip.split(",");
+ for (int index = 0; index < ips.length; index++) {
+ String strIp = ips[index];
+ if (!("unknown".equalsIgnoreCase(strIp))) {
+ ip = strIp;
+ break;
+ }
+ }
+ }
+ return ip;
+ }
+
+}
diff --git a/bweb/src/main/java/com/bweb/config/ConfigListener.java b/bweb/src/main/java/com/bweb/config/ConfigListener.java
new file mode 100644
index 0000000..fb81053
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/config/ConfigListener.java
@@ -0,0 +1,24 @@
+package com.bweb.config;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.annotation.WebListener;
+
+@WebListener
+public class ConfigListener implements ServletContextListener {
+
+ @Autowired
+ private SysConfig sysConfig;
+
+ @Override
+ public void contextInitialized(ServletContextEvent sce) {
+ SysConst.setSysConfig(sysConfig);
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent sce) {
+ }
+
+}
diff --git a/bweb/src/main/java/com/bweb/config/CorsConfig.java b/bweb/src/main/java/com/bweb/config/CorsConfig.java
new file mode 100644
index 0000000..5f46ab3
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/config/CorsConfig.java
@@ -0,0 +1,49 @@
+package com.bweb.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @ClassName CorsConfig
+ * @Description: TODO ()
+ * @Author 胡锐
+ * @Date 2020/12/16
+ **/
+@Configuration
+public class CorsConfig extends WebMvcConfigurerAdapter {
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ registry.addMapping("/**")
+ .allowedOrigins("*")
+ .allowCredentials(true)
+ .allowedMethods("GET", "POST", "DELETE", "PUT")
+ .maxAge(3600);
+ }
+ private CorsConfiguration buildConfig() {
+ CorsConfiguration corsConfiguration = new CorsConfiguration();
+ List list = new ArrayList<>();
+ list.add("*");
+ corsConfiguration.setAllowedOrigins(list);
+ /*
+ // 请求常用的三种配置,*代表允许所有,当时你也可以自定义属性(比如header只能带什么,只能是post方式等等)
+ */
+ corsConfiguration.addAllowedOrigin("*");
+ corsConfiguration.addAllowedHeader("*");
+ corsConfiguration.addAllowedMethod("*");
+ return corsConfiguration;
+ }
+ @Bean
+ public CorsFilter corsFilter() {
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+ source.registerCorsConfiguration("/**", buildConfig());
+ return new CorsFilter(source);
+ }
+}
diff --git a/bweb/src/main/java/com/bweb/config/MultipartConfig.java b/bweb/src/main/java/com/bweb/config/MultipartConfig.java
new file mode 100644
index 0000000..267de74
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/config/MultipartConfig.java
@@ -0,0 +1,26 @@
+package com.bweb.config;
+
+import org.springframework.boot.web.servlet.MultipartConfigFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.servlet.MultipartConfigElement;
+
+@Configuration
+public class MultipartConfig {
+
+ /**
+ * 文件上传配置
+ * @return
+ */
+ @Bean
+ public MultipartConfigElement multipartConfigElement() {
+ MultipartConfigFactory factory = new MultipartConfigFactory();
+ //文件最大
+ factory.setMaxFileSize("300MB"); //KB,MB
+ //设置总上传数据总大小
+ factory.setMaxRequestSize("350MB");
+ return factory.createMultipartConfig();
+ }
+
+}
diff --git a/bweb/src/main/java/com/bweb/config/RedisConfig.java b/bweb/src/main/java/com/bweb/config/RedisConfig.java
new file mode 100644
index 0000000..0c5f530
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/config/RedisConfig.java
@@ -0,0 +1,109 @@
+package com.bweb.config;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.cache.annotation.CachingConfigurerSupport;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.*;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+
+@Configuration
+@EnableCaching //开启注解
+public class RedisConfig extends CachingConfigurerSupport {
+
+ /**
+ * retemplate相关配置
+ * @param factory
+ * @return
+ */
+ @Bean
+ public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
+
+ RedisTemplate template = new RedisTemplate<>();
+ // 配置连接工厂
+ template.setConnectionFactory(factory);
+
+ //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
+ Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class);
+
+ ObjectMapper om = new ObjectMapper();
+ // 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
+ om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+ // 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
+ om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
+ jacksonSeial.setObjectMapper(om);
+
+ // 值采用json序列化
+ template.setValueSerializer(jacksonSeial);
+ //使用StringRedisSerializer来序列化和反序列化redis的key值
+ template.setKeySerializer(new StringRedisSerializer());
+
+ // 设置hash key 和value序列化模式
+ template.setHashKeySerializer(new StringRedisSerializer());
+ template.setHashValueSerializer(jacksonSeial);
+ template.afterPropertiesSet();
+
+ return template;
+ }
+
+ /**
+ * 对hash类型的数据操作
+ *
+ * @param redisTemplate
+ * @return
+ */
+ @Bean
+ public HashOperations hashOperations(RedisTemplate redisTemplate) {
+ return redisTemplate.opsForHash();
+ }
+
+ /**
+ * 对redis字符串类型数据操作
+ *
+ * @param redisTemplate
+ * @return
+ */
+ @Bean
+ public ValueOperations valueOperations(RedisTemplate redisTemplate) {
+ return redisTemplate.opsForValue();
+ }
+
+ /**
+ * 对链表类型的数据操作
+ *
+ * @param redisTemplate
+ * @return
+ */
+ @Bean
+ public ListOperations listOperations(RedisTemplate redisTemplate) {
+ return redisTemplate.opsForList();
+ }
+
+ /**
+ * 对无序集合类型的数据操作
+ *
+ * @param redisTemplate
+ * @return
+ */
+ @Bean
+ public SetOperations setOperations(RedisTemplate redisTemplate) {
+ return redisTemplate.opsForSet();
+ }
+
+ /**
+ * 对有序集合类型的数据操作
+ *
+ * @param redisTemplate
+ * @return
+ */
+ @Bean
+ public ZSetOperations zSetOperations(RedisTemplate redisTemplate) {
+ return redisTemplate.opsForZSet();
+ }
+}
\ No newline at end of file
diff --git a/bweb/src/main/java/com/bweb/config/SwaggerConfig.java b/bweb/src/main/java/com/bweb/config/SwaggerConfig.java
new file mode 100644
index 0000000..b46dc9a
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/config/SwaggerConfig.java
@@ -0,0 +1,47 @@
+package com.bweb.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Contact;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+/**
+* SwaggerConfig.java
+* 项目名称:
+* 包:
+* 类名称: SwaggerConfig.java
+* 类描述: 构建restful api接口文档
+* 创建人:
+* 创建时间: 2017 下午4:23:45
+*/
+@Configuration
+@EnableSwagger2
+public class SwaggerConfig
+{
+
+ /**
+ * 描述api的基本信息
+ * 基本信息会展现在文档页面中
+ * @return [api的基本信息]
+ */
+ ApiInfo apiInfo()
+ {
+ return new ApiInfoBuilder().title("hgj-BWeb").description("提供给管理平台的接口").termsOfServiceUrl("").version("1.0.0")
+ .contact(new Contact("", "", "")).build();
+ }
+
+ @Bean
+ public Docket customImplementation()
+ {
+ return new Docket(DocumentationType.SWAGGER_2).select()
+ .apis(RequestHandlerSelectors.basePackage("com"))
+ .build().directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
+ .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class).apiInfo(apiInfo());
+ }
+
+}
diff --git a/bweb/src/main/java/com/bweb/config/SysConfig.java b/bweb/src/main/java/com/bweb/config/SysConfig.java
new file mode 100644
index 0000000..941c194
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/config/SysConfig.java
@@ -0,0 +1,17 @@
+package com.bweb.config;
+
+import lombok.Data;
+import lombok.Getter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.stereotype.Component;
+
+@Component("sysConfig")
+@ConfigurationProperties
+@PropertySource("classpath:/config.properties")
+@Data
+public class SysConfig {
+
+ private String fileUrl;
+
+}
diff --git a/bweb/src/main/java/com/bweb/config/SysConst.java b/bweb/src/main/java/com/bweb/config/SysConst.java
new file mode 100644
index 0000000..948513a
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/config/SysConst.java
@@ -0,0 +1,19 @@
+package com.bweb.config;
+
+public class SysConst {
+
+ private static SysConfig sysConfig;
+
+ public static void setSysConfig(SysConfig arg){
+ sysConfig = arg;
+ }
+
+ public static SysConfig getSysConfig(){
+ if (null == sysConfig) {
+ //防止空指针异常
+ sysConfig = new SysConfig();
+ return sysConfig;
+ }
+ return sysConfig;
+ }
+}
diff --git a/bweb/src/main/java/com/bweb/controller/BsUserController.java b/bweb/src/main/java/com/bweb/controller/BsUserController.java
new file mode 100644
index 0000000..298b6ec
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/controller/BsUserController.java
@@ -0,0 +1,117 @@
+package com.bweb.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.cg.common.exception.ErrorCode;
+import com.cg.common.exception.ErrorHelp;
+import com.cg.common.exception.SysCode;
+import com.cg.common.utils.ResponseMsgUtil;
+import com.cg.entity.BsUser;
+import com.cg.model.ResponseData;
+import com.cg.service.user.BsUserService;
+import com.cg.service.user.impl.BsUserServiceImpl;
+import com.cg.sysenum.SecUserStatusEnum;
+import com.cg.sysenum.UserStatusEnum;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @className: BsUserController
+ * @author: HuRui
+ * @date: 2024/5/6
+ **/
+@Controller
+@RequestMapping(value="/user")
+@Api(value="用户管理")
+public class BsUserController {
+ private static Logger log = LoggerFactory.getLogger(BsUserController.class);
+ @Resource
+ private BsUserService userService;
+
+
+ @RequestMapping(value="/restore",method = RequestMethod.POST)
+ @ResponseBody
+ @ApiOperation(value = "恢复")
+ public ResponseData restore(@RequestBody JSONObject body) {
+ try {
+ if (body == null || body.getLong("userId") == null) {
+ throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
+ }
+
+ // 查询用户详情
+ BsUser user = userService.getUser(body.getLong("userId"));
+ if (user == null) {
+ throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
+ }
+ user.setStatus(UserStatusEnum.status1.getCode());
+ userService.editData(user);
+
+ return ResponseMsgUtil.success("操作成功");
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+ @RequestMapping(value="/disable",method = RequestMethod.POST)
+ @ResponseBody
+ @ApiOperation(value = "禁用")
+ public ResponseData disable(@RequestBody JSONObject body) {
+ try {
+ if (body == null || body.getLong("userId") == null) {
+ throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
+ }
+ // 查询用户详情
+ BsUser user = userService.getUser(body.getLong("userId"));
+ if (user == null) {
+ throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
+ }
+ user.setStatus(SecUserStatusEnum.status2.getCode());
+ userService.editData(user);
+
+ // 退出当前登录信息
+ userService.loginOut(new BsUserServiceImpl().token(user));
+
+ return ResponseMsgUtil.success("操作成功");
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+ @RequestMapping(value="/queryUserList",method = RequestMethod.GET)
+ @ResponseBody
+ @ApiOperation(value = "查询用户列表")
+ public ResponseData queryUserList(@RequestParam(value = "name" , required = false) String name,
+ @RequestParam(value = "phone" , required = false) String phone,
+ @RequestParam(value = "status" , required = false) Integer status,
+ @RequestParam(value = "pageNum" , required = true) Integer pageNum,
+ @RequestParam(value = "pageSize" , required = true) Integer pageSize) {
+ try {
+ Map param = new HashMap<>();
+ param.put("name", name);
+ param.put("phone", phone);
+ param.put("status", status);
+
+ PageHelper.startPage(pageNum, pageSize);
+ return ResponseMsgUtil.success(new PageInfo<>(userService.getList(param)));
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+
+}
diff --git a/bweb/src/main/java/com/bweb/controller/CommonController.java b/bweb/src/main/java/com/bweb/controller/CommonController.java
new file mode 100644
index 0000000..d21990c
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/controller/CommonController.java
@@ -0,0 +1,49 @@
+package com.bweb.controller;
+
+import com.cg.common.utils.ResponseMsgUtil;
+import com.cg.model.ResponseData;
+import com.cg.service.SecDictionaryService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+@Controller
+@RequestMapping(value="/common")
+@Api(value="共用接口")
+public class CommonController {
+ Logger log = LoggerFactory.getLogger(CommonController.class);
+ @Resource
+ private SecDictionaryService secDictionaryService;
+
+ @RequestMapping(value="/queryDictionary",method = RequestMethod.GET)
+ @ResponseBody
+ @ApiOperation(value = "查询数据字典")
+ public ResponseData queryDictionary(@RequestParam(value = "codeType" , required = false) String codeType,
+ @RequestParam(value = "codeValue" , required = false) String codeValue) {
+ try {
+
+ if (StringUtils.isBlank(codeType) && StringUtils.isBlank(codeValue)) {
+ return ResponseMsgUtil.success(secDictionaryService.getDictionary());
+
+ } else if (StringUtils.isNotBlank(codeType) && StringUtils.isNotBlank(codeValue)) {
+ return ResponseMsgUtil.success(secDictionaryService.getDictionary(codeType, codeValue));
+
+ } else if (StringUtils.isNotBlank(codeType)) {
+ return ResponseMsgUtil.success(secDictionaryService.getDictionary(codeType));
+ }
+
+ return ResponseMsgUtil.success(null);
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+}
diff --git a/bweb/src/main/java/com/bweb/controller/FileUploadController.java b/bweb/src/main/java/com/bweb/controller/FileUploadController.java
new file mode 100644
index 0000000..6194fd3
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/controller/FileUploadController.java
@@ -0,0 +1,98 @@
+package com.bweb.controller;
+
+import com.cg.common.utils.DateUtil;
+import com.cg.common.utils.ResponseMsgUtil;
+import com.bweb.config.SysConfig;
+import com.cg.model.ResponseData;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import net.coobird.thumbnailator.Thumbnails;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.*;
+
+@RestController
+@RequestMapping(value="/fileUpload")
+@Api(value="文件上传")
+public class FileUploadController {
+
+ private static Logger log = LoggerFactory.getLogger(FileUploadController.class);
+
+ @Resource
+ private SysConfig sysConfig;
+
+ @RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
+ @ApiOperation(value = "上传文件(超过500KB压缩)")
+ @ResponseBody
+ public ResponseData fileUpload(@RequestParam(value = "files" , required = false) MultipartFile files,
+ HttpServletRequest request,
+ HttpServletResponse response
+ ) {
+ try {
+ response.setHeader("Access-Control-Allow-Origin", "*");
+ CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
+ request.getSession().getServletContext());
+ // 判断 request 是否有文件上传,即多部分请求
+ List fileNames = new ArrayList();
+ if (multipartResolver.isMultipart(request)) {
+ // 转换成多部分request
+ MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
+ Iterator iterator = multiRequest.getFileNames();
+
+ while (iterator.hasNext()) {
+ MultipartFile file = multiRequest.getFile(iterator.next());
+ if (file != null) {
+ FileOutputStream out = null;
+ try {
+ String fileType = file.getOriginalFilename()
+ .substring(file.getOriginalFilename().lastIndexOf(".") + 1);
+ String fileName = System.currentTimeMillis() + "." + fileType;
+ String childPath = DateUtil.date2String(new Date(), "yyyyMM");
+ String destDirName = sysConfig.getFileUrl() + File.separator + childPath;
+ File dir = new File(destDirName);
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+
+ out = new FileOutputStream(destDirName + File.separator + fileName);
+ out.write(file.getBytes());
+ out.flush();
+ fileNames.add(childPath + "/" + fileName);
+ // 图片压缩
+ InputStream fis = new FileInputStream(destDirName + File.separator + fileName);
+ if (fis.available() > 300000) {
+ Thumbnails.of(new FileInputStream(destDirName + File.separator + fileName)).scale(0.5).toFile(new File(destDirName + File.separator + fileName));
+ }
+
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+ }
+ }
+ }
+ return ResponseMsgUtil.success(fileNames);
+
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+
+}
diff --git a/bweb/src/main/java/com/bweb/controller/SecMenuController.java b/bweb/src/main/java/com/bweb/controller/SecMenuController.java
new file mode 100644
index 0000000..bd084df
--- /dev/null
+++ b/bweb/src/main/java/com/bweb/controller/SecMenuController.java
@@ -0,0 +1,301 @@
+package com.bweb.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.cg.common.exception.ErrorCode;
+import com.cg.common.exception.ErrorHelp;
+import com.cg.common.exception.SysCode;
+import com.cg.common.utils.HttpUtils;
+import com.cg.common.utils.HttpsUtils;
+import com.cg.common.utils.ResponseMsgUtil;
+import com.cg.entity.SecMenu;
+import com.cg.entity.SecRoleMenuRel;
+import com.cg.model.MenuTreeModel;
+import com.cg.model.ResponseData;
+import com.cg.service.SecMenuService;
+import com.cg.service.SecRoleMenuRelService;
+import com.cg.sysenum.SecMenuTypeEnum;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * @className: SecMenu
+ * @author: HuRui
+ * @date: 2024/3/28
+ **/
+@Controller
+@RequestMapping(value="/secMenu")
+@Api(value="系统菜单管理")
+public class SecMenuController {
+
+ Logger log = LoggerFactory.getLogger(SecUserController.class);
+
+ @Resource
+ private SecMenuService secMenuService;
+ @Resource
+ private SecRoleMenuRelService secRoleMenuRelService;
+
+ @RequestMapping(value="/editMenu",method = RequestMethod.POST)
+ @ResponseBody
+ @ApiOperation(value = "编辑菜单")
+ public ResponseData editMenu(@RequestBody SecMenu body) {
+ try {
+ if (body == null
+ || body.getMenuType() == null
+ || StringUtils.isBlank(body.getMenuName())
+ || StringUtils.isBlank(body.getMenuUrl())
+ || body.getMenuSort() == null) {
+ throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
+ }
+ SecMenu secMenu;
+
+ if (body.getId() != null) {
+ // 查询菜单
+ secMenu = secMenuService.queryDetail(body.getId());
+ if (secMenu == null) {
+ throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
+ }
+ } else {
+ secMenu = new SecMenu();
+ }
+ if (secMenu.getMenuPSid() != null) {
+ // 查询父类菜单
+ SecMenu parentMenu = secMenuService.queryDetail(secMenu.getMenuPSid());
+ if (parentMenu == null) {
+ throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
+ }
+ }
+
+ secMenu.setMenuType(body.getMenuType());
+ secMenu.setMenuName(body.getMenuName());
+ secMenu.setMenuUrl(body.getMenuUrl());
+ secMenu.setMenuUrlImg(body.getMenuUrlImg());
+ secMenu.setMenuPSid(body.getMenuPSid());
+ secMenu.setMenuSort(body.getMenuSort());
+ secMenu.setMenuDesc(body.getMenuDesc());
+ if (secMenu.getId() == null) {
+ secMenuService.create(secMenu);
+ } else {
+ secMenuService.update(secMenu);
+ }
+ return ResponseMsgUtil.success("操作成功");
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+ @RequestMapping(value="/queryDetail",method = RequestMethod.POST)
+ @ResponseBody
+ @ApiOperation(value = "查询详情")
+ public ResponseData queryDetail(@RequestParam(value = "menuId" , required = true) Long menuId) {
+ try {
+
+ return ResponseMsgUtil.success(secMenuService.queryDetail(menuId));
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+ @RequestMapping(value="/delMenu",method = RequestMethod.POST)
+ @ResponseBody
+ @ApiOperation(value = "删除菜单")
+ public ResponseData delMenu(@RequestBody JSONObject body) {
+ try {
+ if (body == null || body.getLong("menuId") == null) {
+ throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
+ }
+ secMenuService.delete(body.getLong("menuId"));
+
+ return ResponseMsgUtil.success("操作成功");
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+ @RequestMapping(value="/assignMenu",method = RequestMethod.POST)
+ @ResponseBody
+ @ApiOperation(value = "分配菜单")
+ public ResponseData assignMenu(@RequestBody JSONObject body) {
+ try {
+ if (body == null
+ || body.getLong("roleId") == null
+ || body.getJSONArray("menuIds").isEmpty()) {
+ throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
+ }
+
+ List list = body.getJSONArray("menuIds")
+ .stream().map(o -> Long.parseLong(o.toString()))
+ .collect(Collectors.toList());
+
+ secMenuService.assignMenu(body.getLong("roleId"),list );
+ return ResponseMsgUtil.success("操作成功");
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+ @RequestMapping(value="/queryMenuList",method = RequestMethod.POST)
+ @ResponseBody
+ @ApiOperation(value = "查询菜单列表")
+ public ResponseData queryMenuList() {
+ try {
+
+ return ResponseMsgUtil.success(secMenuService.getAllList());
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+ @RequestMapping(value="/queryRoleMenuArray",method = RequestMethod.GET)
+ @ResponseBody
+ @ApiOperation(value = "查询分配菜单树")
+ public ResponseData queryRoleMenuArray(@RequestParam(value = "roleId" , required = true) Long roleId) {
+ try {
+
+ // 查询角色菜单权限
+ Map roleMenu = secMenuService.queryRoleMenu(roleId, SecMenuTypeEnum.type1).stream()
+ .collect(Collectors.toMap(SecMenu::getId, Function.identity()));
+
+ // 系统菜单叶节点
+ List menuLeafList = new ArrayList<>();
+
+ // 角色菜单叶节点
+ List roleLeafList = new ArrayList<>();
+
+ // 获取全部菜单
+ List menuList = secMenuService.getAllList();
+
+ // 获取最顶层菜单
+ List topLevelMenuList = menuList.stream()
+ .filter(o -> o.getMenuPSid() == null)
+ .sorted(Comparator.comparing(SecMenu::getMenuSort))
+ .collect(Collectors.toList());
+ // 递归获取系统菜单叶子节点
+ for (SecMenu topLevelMenu : topLevelMenuList) {
+ if (topLevelMenu.getMenuType().equals(SecMenuTypeEnum.type1.getCode())) {
+ recursionMenu(menuList, topLevelMenu.getId(), menuLeafList);
+ }
+ }
+
+ // 筛选角色菜单叶节点
+ for (String leaf : menuLeafList) {
+ SecMenu menu = roleMenu.get(Long.parseLong(leaf));
+ if (menu != null) {
+ roleLeafList.add(""+menu.getId());
+ }
+ }
+
+ return ResponseMsgUtil.success(roleLeafList);
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+ @RequestMapping(value="/queryRoleMenuTree",method = RequestMethod.GET)
+ @ResponseBody
+ @ApiOperation(value = "查询角色菜单树")
+ public ResponseData queryRoleMenuTree(@RequestParam(value = "roleId" , required = false) Long roleId) {
+ try {
+
+ return ResponseMsgUtil.success(secMenuService.queryMenuTree(roleId));
+
+ } catch (Exception e) {
+ log.error("error!",e);
+ return ResponseMsgUtil.exception(e);
+ }
+ }
+
+ @RequestMapping(value="/queryMenuTree",method = RequestMethod.POST)
+ @ResponseBody
+ @ApiOperation(value = "查询角色菜单树")
+ public ResponseData queryMenuTree() {
+ try {
+ List