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> mapList = new ArrayList<>(); + Map map; + + // 获取全部菜单 + 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())) { + map = new LinkedHashMap<>(); + map.put("key", ""+topLevelMenu.getId()); + map.put("title", topLevelMenu.getMenuName()); + // 获取下级菜单 + map.put("children", recursionMenu(menuList, topLevelMenu.getId(), new ArrayList<>())); + mapList.add(map); + } + } + + return ResponseMsgUtil.success(mapList); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + /** + * 递归获取菜单 + * @param dataSource 数据源 + * @param parentMenuId 父级菜单id + * @return + */ + public List> recursionMenu(List dataSource, Long parentMenuId, List leaf) { + List> mapList = new ArrayList<>(); + Map map; + + List collect = dataSource.stream() + .filter(o -> o.getMenuPSid() != null && o.getMenuPSid().equals(parentMenuId)) + .sorted(Comparator.comparing(SecMenu::getMenuSort)) + .collect(Collectors.toList()); + for (SecMenu menu : collect) { + if (menu.getMenuType().equals(SecMenuTypeEnum.type1.getCode())) { + map = new LinkedHashMap<>(); + map.put("key", ""+menu.getId()); + map.put("title", menu.getMenuName()); + // 获取下级菜单 + List> recursioned = recursionMenu(dataSource, menu.getId(), leaf); + if (recursioned.isEmpty()) { + leaf.add(""+menu.getId()); + map.put("isLeaf", true); + } else { + map.put("children", recursioned); + } + mapList.add(map); + } + } + return mapList; + } + + +} diff --git a/bweb/src/main/java/com/bweb/controller/SecRoleController.java b/bweb/src/main/java/com/bweb/controller/SecRoleController.java new file mode 100644 index 0000000..2795885 --- /dev/null +++ b/bweb/src/main/java/com/bweb/controller/SecRoleController.java @@ -0,0 +1,144 @@ +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.MD5Util; +import com.cg.common.utils.ResponseMsgUtil; +import com.cg.entity.SecRole; +import com.cg.entity.SecUser; +import com.cg.model.ResponseData; +import com.cg.service.SecRoleService; +import com.cg.service.SecUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringEscapeUtils; +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.HashMap; +import java.util.Map; + +/** + * @className: SecRoleController + * @author: HuRui + * @date: 2024/3/27 + **/ +@Controller +@RequestMapping(value="/secRole") +@Api(value="系统用户角色管理") +public class SecRoleController { + + Logger log = LoggerFactory.getLogger(SecUserController.class); + + @Resource + private SecRoleService secRoleService; + + @RequestMapping(value="/editRole",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "编辑角色") + public ResponseData editRole(@RequestBody SecRole body) { + try { + if (body == null || StringUtils.isBlank(body.getRoleName())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + SecRole secRole; + if (body.getId() != null) { + // 查询角色 + secRole = secRoleService.getDetail(body.getId()); + if (secRole == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + } else { + secRole = new SecRole(); + secRole.setStatus(1); + } + secRole.setRoleName(body.getRoleName()); + secRole.setRoleDesc(body.getRoleDesc()); + secRoleService.editData(secRole); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/delRole",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "删除角色") + public ResponseData delRole(@RequestBody SecRole body) { + try { + if (body == null || body.getId() == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + secRoleService.delete(body.getId()); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryDetail",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询详情") + public ResponseData queryDetail(@RequestParam(value = "roleId" , required = true) Long roleId) { + try { + + secRoleService.delete(roleId); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询列表") + public ResponseData queryList(@RequestParam(value = "roleName" , required = false) String roleName, + @RequestParam(value = "pageNum" , required = true) Integer pageNum, + @RequestParam(value = "pageSize" , required = true) Integer pageSize) { + try { + Map param = new HashMap<>(); + param.put("roleName", roleName); + + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(new PageInfo<>(secRoleService.getList(param))); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryAllRole",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询全部角色") + public ResponseData queryAllRole() { + try { + + return ResponseMsgUtil.success(secRoleService.getList(new HashMap<>())); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + +} diff --git a/bweb/src/main/java/com/bweb/controller/SecUserController.java b/bweb/src/main/java/com/bweb/controller/SecUserController.java new file mode 100644 index 0000000..d34804d --- /dev/null +++ b/bweb/src/main/java/com/bweb/controller/SecUserController.java @@ -0,0 +1,310 @@ +package com.bweb.controller; + +import com.alibaba.fastjson.JSONObject; +import com.cg.common.security.UserCenter; +import com.cg.model.SecUserSessionObject; +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.MD5Util; +import com.cg.common.utils.ResponseMsgUtil; +import com.cg.entity.SecUser; +import com.cg.model.ResponseData; +import com.cg.service.SecUserLoginLogService; +import com.cg.service.SecUserService; +import com.cg.sysenum.SecUserObjectTypeEnum; +import com.cg.sysenum.SecUserStatusEnum; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.models.auth.In; +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 javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; + +@Controller +@RequestMapping(value="/secUser") +@Api(value="系统用户管理") +public class SecUserController { + Logger log = LoggerFactory.getLogger(SecUserController.class); + + @Resource + private SecUserService secUserService; + @Resource + private SecUserLoginLogService secUserLoginLogService; + + @Resource + private UserCenter userCenter; + + @RequestMapping(value="/editUser",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "编辑用户") + public ResponseData editUser(@RequestBody JSONObject body) { + try { + if (body == null + || StringUtils.isBlank(body.getString("userName")) + || StringUtils.isBlank(body.getString("loginName")) + || body.getLong("roleId") == null + ) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + SecUser secUser; + if (body.getLong("id") != null) { + // 查询账户 + secUser = secUserService.getDetail(body.getLong("id")); + // 校验重复登录账户 + SecUser user = secUserService.getDetailByLoginName(body.getString("loginName")); + if (user != null && !user.getId().equals(body.getLong("id"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录账户已存在"); + } + } else { + secUser = new SecUser(); + secUser.setPassword(MD5Util.encode("123456".getBytes())); + secUser.setObjectType(SecUserObjectTypeEnum.type1.getCode()); + secUser.setStatus(SecUserStatusEnum.status1.getCode()); + + // 校验重复登录账户 + if (secUserService.getDetailByLoginName(body.getString("loginName")) != null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录账户已存在"); + } + } + + secUser.setUserName(body.getString("userName")); + secUser.setLoginName(body.getString("loginName")); + secUser.setTelephone(body.getString("telephone")); + secUser.setRoleId(body.getLong("roleId")); + secUserService.editUser(secUser); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/delete",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "删除用户") + public ResponseData delete(@RequestBody JSONObject body) { + try { + if (body == null || body.getLong("userId") == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + // 查询用户详情 + SecUser secUser = secUserService.getDetail(body.getLong("userId")); + if (secUser == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + secUser.setStatus(SecUserStatusEnum.status0.getCode()); + secUserService.editUser(secUser); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @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, ""); + } + + // 查询用户详情 + SecUser secUser = secUserService.getDetail(body.getLong("userId")); + if (secUser == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + secUser.setStatus(SecUserStatusEnum.status1.getCode()); + secUserService.editUser(secUser); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/resetPwd",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "账户密码重置") + public ResponseData resetPwd(@RequestBody JSONObject body) { + try { + if (body == null || body.getLong("userId") == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + secUserService.resetPwd(body.getLong("userId")); + + 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, ""); + } + // 查询用户详情 + SecUser secUser = secUserService.getDetail(body.getLong("userId")); + if (secUser == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + secUser.setStatus(SecUserStatusEnum.status2.getCode()); + secUserService.editUser(secUser); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryDetail",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询详情") + public ResponseData queryDetail(@RequestParam(value = "userId" , required = true) Long userId) { + try { + // 查询详情 + SecUser secUser = secUserService.getDetail(userId); + if (secUser != null) { + secUser.setPassword(null); + } + return ResponseMsgUtil.success(secUser); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询列表") + public ResponseData queryList(@RequestParam(value = "userName", required = false) String userName, + @RequestParam(value = "loginName", required = false) String loginName, + @RequestParam(value = "telephone", required = false) String telephone, + @RequestParam(value = "objectType", required = false) Integer objectType, + @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("userName", userName); + param.put("loginName", loginName); + param.put("telephone", telephone); + param.put("objectType", objectType); + param.put("status", status); + + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(new PageInfo<>(secUserService.getList(param))); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + + @RequestMapping(value="/queryLoginLogList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询登录日志列表") + public ResponseData queryLoginLogList(@RequestParam(value = "userId", required = true) String userId, + @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("userId", userId); + param.put("status", status); + + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(secUserLoginLogService.getLogList(param)); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/login",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "登录") + public ResponseData login(@RequestBody JSONObject body) { + try { + if (body == null + || StringUtils.isBlank(body.getString("loginName")) + || StringUtils.isBlank(body.getString("password")) + ) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + return ResponseMsgUtil.success(secUserService.login(body.getString("loginName"), body.getString("password"))); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryUser",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "查询账户") + public ResponseData queryUser() { + try { + + return ResponseMsgUtil.success(userCenter.getSessionModel(SecUserSessionObject.class)); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/loginOut",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "退出登录") + public ResponseData loginOut(HttpServletRequest request) { + try { + try { + SecUserSessionObject session = userCenter.getSessionModel(SecUserSessionObject.class); + if (session != null) { + userCenter.remove(request); + } + } catch (Exception e) {} + return ResponseMsgUtil.success("退出成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/bweb/src/main/java/com/bweb/controller/cms/CmsContentController.java b/bweb/src/main/java/com/bweb/controller/cms/CmsContentController.java new file mode 100644 index 0000000..92b0b53 --- /dev/null +++ b/bweb/src/main/java/com/bweb/controller/cms/CmsContentController.java @@ -0,0 +1,156 @@ +package com.bweb.controller.cms; + +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.CmsContent; +import com.cg.model.ResponseData; +import com.cg.service.cms.CmsContentService; +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 javax.servlet.http.HttpServletRequest; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@Controller +@RequestMapping(value="/cms") +@Api(value="cms") +public class CmsContentController { + + Logger log = LoggerFactory.getLogger(CmsContentController.class); + + @Resource + private CmsContentService cmsContentService; + + @RequestMapping(value="/editCms",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "编辑CMS") + public ResponseData editCms(@RequestBody CmsContent body, HttpServletRequest request) { + try { + + if (body == null + || body.getPlatformCode() == null + || StringUtils.isBlank(body.getName()) + || StringUtils.isBlank(body.getCode())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + CmsContent cmsContent; + + if (body.getId() != null) { + // 查询CMS + cmsContent = cmsContentService.queryDetail(body.getId()); + if (cmsContent == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.CONTENT_NOT_FOUND, ""); + } + } else { + cmsContent = new CmsContent(); + cmsContent.setCreateTime(new Date()); + } + + cmsContent.setUpdateTime(new Date()); + cmsContent.setStatus(1); + cmsContent.setName(body.getName()); + cmsContent.setAppid(body.getAppid()); + cmsContent.setJumpType(body.getJumpType()); + cmsContent.setJumpUrl(body.getJumpUrl()); + cmsContent.setPlatformCode(body.getPlatformCode()); + cmsContent.setImg(body.getImg()); + cmsContent.setCode(body.getCode()); + + if (body.getId() != null) { + cmsContentService.update(cmsContent); + } else { + cmsContentService.create(cmsContent); + } + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + + } + + @RequestMapping(value="/getCms",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询列表") + public ResponseData getCms(@RequestParam(value = "code" , required = false) String code, + @RequestParam(value = "name" , required = false) String name, + @RequestParam(value = "status" , required = false) Integer status, + @RequestParam(value = "platformCode" , required = false) String platformCode, + @RequestParam(value = "pageNum" , required = true) Integer pageNum, + @RequestParam(value = "pageSize" , required = true) Integer pageSize) { + try { + + Map map = new HashMap<>(); + map.put("code", code); + map.put("platformCode", platformCode); + map.put("name", name); + map.put("status", status); + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(new PageInfo<>(cmsContentService.getList(map))); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/delete",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "删除") + public ResponseData delete(@RequestParam(value = "id" , required = false) Long id) { + try { + + cmsContentService.delete(id , false); + + return ResponseMsgUtil.success("删除成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + + @RequestMapping(value="/cmsUpDown",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "商品上下架") + public ResponseData cmsUpDown(@RequestParam(value = "id" , required = false) Long id, HttpServletRequest request) { + try { + + CmsContent cmsContent = cmsContentService.queryDetail(id); + + if (cmsContent.getStatus() == 1) { + cmsContent.setStatus(2); + cmsContent.setUpdateTime(new Date()); + } else if (cmsContent.getStatus() == 2) { + cmsContent.setStatus(1); + cmsContent.setUpdateTime(new Date()); + + } + + cmsContentService.update(cmsContent); + + return ResponseMsgUtil.success("成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/bweb/src/main/resources/dev/application.yml b/bweb/src/main/resources/dev/application.yml new file mode 100644 index 0000000..fca0b11 --- /dev/null +++ b/bweb/src/main/resources/dev/application.yml @@ -0,0 +1,89 @@ +server: + port: 9702 + servlet: + context-path: /brest + +#配置是否为debug模式,debug模式下,不开启权限校验 +debug: false + +#datasource数据源设置 +spring: + datasource: + url: jdbc:mysql://139.9.154.68:3306/cg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + username: root + password: HF123456. + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.jdbc.Driver + filters: stat + maxActive: 10 + initialSize: 5 + maxWait: 60000 + minIdle: 5 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: select 'x' + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + maxOpenPreparedStatements: 20 + redis: + database: 1 + host: 139.9.154.68 + port: 36379 + password: HF123456.Redis + timeout: 1000 + jedis: + pool: + max-active: 20 + max-wait: -1 + max-idle: 10 + min-idle: 0 + #配置日期返回至前台为时间戳 + jackson: + serialization: + write-dates-as-timestamps: true +mybatis: + mapperLocations: + - classpath*:sqlmap*/*.xml + type-aliases-package: + org.springboot.sample.entity + +pagehelper: + helperDialect: mysql + reasonable: true + supportMethodsArguments: true + params: count=countSql + +rocketmq: + name-server: 139.9.154.68:9876 + producer: + access-key: huifukeji + secret-key: HF123456. + #必须指定group + group: default-group + consumer: + access-key: huifukeji + secret-key: HF123456. + +jetcache: + statIntervalMinutes: 15 + areaInCacheName: false + local: + default: + type: linkedhashmap + keyConvertor: fastjson + remote: + default: + type: redis + host: 139.9.154.68 + port: 36379 + password: HF123456.Redis + keyConvertor: fastjson + broadcastChannel: projectA + valueEncoder: java + valueDecoder: java + poolConfig: + minIdle: 5 + maxIdle: 20 + maxTotal: 50 diff --git a/bweb/src/main/resources/dev/config.properties b/bweb/src/main/resources/dev/config.properties new file mode 100644 index 0000000..2bb287c --- /dev/null +++ b/bweb/src/main/resources/dev/config.properties @@ -0,0 +1 @@ +fileUrl=/home/project/phg/filesystem diff --git a/bweb/src/main/resources/dev/logback.xml b/bweb/src/main/resources/dev/logback.xml new file mode 100644 index 0000000..ff7bde9 --- /dev/null +++ b/bweb/src/main/resources/dev/logback.xml @@ -0,0 +1,72 @@ + + + + + %d %p (%file:%line\)- %m%n + UTF-8 + + + + log/base.log + + log/base.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/dao.log + + log/dao.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/error.log + + log/error.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + + + + + + + + + + + + diff --git a/bweb/src/main/resources/pre/application.yml b/bweb/src/main/resources/pre/application.yml new file mode 100644 index 0000000..874093a --- /dev/null +++ b/bweb/src/main/resources/pre/application.yml @@ -0,0 +1,56 @@ +server: + port: 9301 + servlet: + context-path: /crest + +#配置是否为debug模式,debug模式下,不开启权限校验 +debug: false + +#datasource数据源设置 +spring: + datasource: + url: jdbc:mysql://139.9.154.68:3306/hsg_pre?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + username: root + password: HF123456. + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.jdbc.Driver + filters: stat + maxActive: 10 + initialSize: 5 + maxWait: 60000 + minIdle: 5 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: select 'x' + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + maxOpenPreparedStatements: 20 + redis: + database: 1 + host: 139.9.154.68 + port: 36379 + password: HF123456.Redis + timeout: 1000 + jedis: + pool: + max-active: 20 + max-wait: -1 + max-idle: 10 + min-idle: 0 + #配置日期返回至前台为时间戳 + jackson: + serialization: + write-dates-as-timestamps: true +mybatis: + mapperLocations: + - classpath*:sqlmap*/*.xml + type-aliases-package: + org.springboot.sample.entity + +pagehelper: + helperDialect: mysql + reasonable: true + supportMethodsArguments: true + params: count=countSql diff --git a/bweb/src/main/resources/pre/config.properties b/bweb/src/main/resources/pre/config.properties new file mode 100644 index 0000000..44ea8fc --- /dev/null +++ b/bweb/src/main/resources/pre/config.properties @@ -0,0 +1,2 @@ +fileUrl=/home/project/hsg/filesystem +cmsPath=/home/project/hsg/filesystem/cmsPath diff --git a/bweb/src/main/resources/pre/logback.xml b/bweb/src/main/resources/pre/logback.xml new file mode 100644 index 0000000..ff7bde9 --- /dev/null +++ b/bweb/src/main/resources/pre/logback.xml @@ -0,0 +1,72 @@ + + + + + %d %p (%file:%line\)- %m%n + UTF-8 + + + + log/base.log + + log/base.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/dao.log + + log/dao.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/error.log + + log/error.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + + + + + + + + + + + + diff --git a/bweb/src/main/resources/prod/application.yml b/bweb/src/main/resources/prod/application.yml new file mode 100644 index 0000000..1d275ec --- /dev/null +++ b/bweb/src/main/resources/prod/application.yml @@ -0,0 +1,86 @@ +server: + port: 9702 + servlet: + context-path: /brest + +#配置是否为debug模式,debug模式下,不开启权限校验 +debug: false + +#datasource数据源设置 +spring: + datasource: + url: jdbc:mysql://192.168.0.63:21100/phg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 + username: phg + password: HUfukeji123456!@# + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.jdbc.Driver + filters: stat + maxActive: 10 + initialSize: 5 + maxWait: 60000 + minIdle: 5 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: select 'x' + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + maxOpenPreparedStatements: 20 + + redis: + database: 1 + host: 127.0.0.1 + port: 36379 + password: HF123456.Redis + timeout: 1000 + jedis: + pool: + max-active: 20 + max-wait: -1 + max-idle: 10 + min-idle: 0 + #配置日期返回至前台为时间戳 + jackson: + serialization: + write-dates-as-timestamps: true + +rocketmq: + name-server: 1.95.70.9:9876 + producer: + #必须指定group + group: default-group + +mybatis: + mapperLocations: + - classpath*:sqlmap*/*.xml + type-aliases-package: + org.springboot.sample.entity + +jetcache: + statIntervalMinutes: 15 + areaInCacheName: false + local: + default: + type: linkedhashmap + keyConvertor: fastjson + remote: + default: + type: redis + host: 127.0.0.1 + port: 36379 + password: HF123456.Redis + keyConvertor: fastjson + broadcastChannel: projectA + valueEncoder: java + valueDecoder: java + poolConfig: + minIdle: 5 + maxIdle: 20 + maxTotal: 50 + +pagehelper: + helperDialect: mysql + reasonable: true + supportMethodsArguments: true + params: count=countSql diff --git a/bweb/src/main/resources/prod/config.properties b/bweb/src/main/resources/prod/config.properties new file mode 100644 index 0000000..2bb287c --- /dev/null +++ b/bweb/src/main/resources/prod/config.properties @@ -0,0 +1 @@ +fileUrl=/home/project/phg/filesystem diff --git a/bweb/src/main/resources/prod/logback.xml b/bweb/src/main/resources/prod/logback.xml new file mode 100644 index 0000000..3fe336e --- /dev/null +++ b/bweb/src/main/resources/prod/logback.xml @@ -0,0 +1,72 @@ + + + + + %d %p (%file:%line\)- %m%n + UTF-8 + + + + log/base.log + + log/base.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/dao.log + + log/dao.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/error.log + + log/error.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + + + + + + + + + + + + diff --git a/cweb/pom.xml b/cweb/pom.xml new file mode 100644 index 0000000..c825992 --- /dev/null +++ b/cweb/pom.xml @@ -0,0 +1,45 @@ + + + + com.cg + cg-parent + 1.0-SNAPSHOT + + 4.0.0 + + com.cg + cweb + + + + 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/cweb/src/main/java/com/CWebApplication.java b/cweb/src/main/java/com/CWebApplication.java new file mode 100644 index 0000000..bf8779e --- /dev/null +++ b/cweb/src/main/java/com/CWebApplication.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 CWebApplication +{ + public static void main( String[] args ) + { + ApplicationContext app = SpringApplication.run(CWebApplication.class, args); + SpringContextUtil.setApplicationContext(app); + } + +} diff --git a/cweb/src/main/java/com/cweb/config/AuthConfig.java b/cweb/src/main/java/com/cweb/config/AuthConfig.java new file mode 100644 index 0000000..de64701 --- /dev/null +++ b/cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -0,0 +1,130 @@ +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("/goods/*") + .excludePathPatterns("/cms/*") + .excludePathPatterns("/common/*") + .excludePathPatterns("/fileUpload/*") + .excludePathPatterns("/wxMsg/*") + .excludePathPatterns("/cinema/*") + ; + } + + 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/cweb/src/main/java/com/cweb/config/ConfigListener.java b/cweb/src/main/java/com/cweb/config/ConfigListener.java new file mode 100644 index 0000000..cb92b19 --- /dev/null +++ b/cweb/src/main/java/com/cweb/config/ConfigListener.java @@ -0,0 +1,25 @@ +package com.cweb.config; + +import org.springframework.beans.factory.annotation.Autowired; + +import javax.annotation.Resource; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +@WebListener +public class ConfigListener implements ServletContextListener { + + @Resource + private SysConfig sysConfig; + + @Override + public void contextInitialized(ServletContextEvent sce) { + SysConst.setSysConfig(sysConfig); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + } + +} diff --git a/cweb/src/main/java/com/cweb/config/CorsConfig.java b/cweb/src/main/java/com/cweb/config/CorsConfig.java new file mode 100644 index 0000000..14e87c0 --- /dev/null +++ b/cweb/src/main/java/com/cweb/config/CorsConfig.java @@ -0,0 +1,49 @@ +package com.cweb.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/cweb/src/main/java/com/cweb/config/MultipartConfig.java b/cweb/src/main/java/com/cweb/config/MultipartConfig.java new file mode 100644 index 0000000..97794e9 --- /dev/null +++ b/cweb/src/main/java/com/cweb/config/MultipartConfig.java @@ -0,0 +1,26 @@ +package com.cweb.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/cweb/src/main/java/com/cweb/config/RedisConfig.java b/cweb/src/main/java/com/cweb/config/RedisConfig.java new file mode 100644 index 0000000..c6db7fc --- /dev/null +++ b/cweb/src/main/java/com/cweb/config/RedisConfig.java @@ -0,0 +1,110 @@ +package com.cweb.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/cweb/src/main/java/com/cweb/config/SwaggerConfig.java b/cweb/src/main/java/com/cweb/config/SwaggerConfig.java new file mode 100644 index 0000000..95ebf13 --- /dev/null +++ b/cweb/src/main/java/com/cweb/config/SwaggerConfig.java @@ -0,0 +1,47 @@ +package com.cweb.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-CWeb").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/cweb/src/main/java/com/cweb/config/SysConfig.java b/cweb/src/main/java/com/cweb/config/SysConfig.java new file mode 100644 index 0000000..42217d3 --- /dev/null +++ b/cweb/src/main/java/com/cweb/config/SysConfig.java @@ -0,0 +1,17 @@ +package com.cweb.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/cweb/src/main/java/com/cweb/config/SysConst.java b/cweb/src/main/java/com/cweb/config/SysConst.java new file mode 100644 index 0000000..23c919a --- /dev/null +++ b/cweb/src/main/java/com/cweb/config/SysConst.java @@ -0,0 +1,19 @@ +package com.cweb.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/cweb/src/main/java/com/cweb/config/WxMaConfiguration.java b/cweb/src/main/java/com/cweb/config/WxMaConfiguration.java new file mode 100644 index 0000000..b877321 --- /dev/null +++ b/cweb/src/main/java/com/cweb/config/WxMaConfiguration.java @@ -0,0 +1,33 @@ +package com.cweb.config; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; +import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; + +@Configuration +public class WxMaConfiguration { + + private static WxMaService maService; + + public static WxMaService getMaService() { + if (maService == null) { + throw new IllegalArgumentException(String.format("未找到对应的配置,请核实!")); + } + + return maService; + } + + @PostConstruct + public void init() { + /*WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); + config.setAppid(SysConst.getSysConfig().getWxAppId()); + config.setSecret(SysConst.getSysConfig().getWxAppSecret()); + + maService = new WxMaServiceImpl(); + maService.setWxMaConfig(config);*/ + } + +} diff --git a/cweb/src/main/java/com/cweb/controller/CommonController.java b/cweb/src/main/java/com/cweb/controller/CommonController.java new file mode 100644 index 0000000..3c5b543 --- /dev/null +++ b/cweb/src/main/java/com/cweb/controller/CommonController.java @@ -0,0 +1,60 @@ +package com.cweb.controller; + +import com.alibaba.fastjson.JSONObject; +import com.cg.common.utils.RedisUtil; +import com.cg.common.utils.ResponseMsgUtil; +import com.cg.model.ResponseData; +import com.cg.service.CommonService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.*; + +@RestController +@RequestMapping(value="/common") +@Api(value="共用接口") +public class CommonController { + + Logger log = LoggerFactory.getLogger(CommonController.class); + + @Resource + private CommonService commonService; + + @Autowired + private RedisUtil redisUtil; + + + @RequestMapping(value = "/getAllCity", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询所有城市") + public ResponseData getAllCity() { + try { + + Object data = redisUtil.get("regional"); + + if (data == null) { + + List jsonObjects = commonService.getCity("key" , "title" , "children"); + redisUtil.set("regional", jsonObjects); + + return ResponseMsgUtil.success(jsonObjects); + + } else { + return ResponseMsgUtil.success(data); + } + + } catch (Exception e) { + log.error("HighUserCardController --> oilCardRefund() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + + + +} diff --git a/cweb/src/main/java/com/cweb/controller/FileUploadController.java b/cweb/src/main/java/com/cweb/controller/FileUploadController.java new file mode 100644 index 0000000..9683418 --- /dev/null +++ b/cweb/src/main/java/com/cweb/controller/FileUploadController.java @@ -0,0 +1,103 @@ +package com.cweb.controller; + +import com.cweb.config.SysConfig; +import com.cg.common.utils.DateUtil; +import com.cg.common.utils.ResponseMsgUtil; +import com.cg.config.CommonSysConst; +import com.cg.model.ResponseData; +import com.cg.service.FileUploadService; +import com.obs.services.model.PutObjectResult; +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.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +@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 = "上传文件(超过3000KB压缩)") + @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() > 3000000) { + 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/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java b/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java new file mode 100644 index 0000000..805753b --- /dev/null +++ b/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java @@ -0,0 +1,51 @@ +package com.cweb.controller.cms; + +import com.cg.common.utils.ResponseMsgUtil; +import com.cg.model.ResponseData; +import com.cg.service.cms.CmsContentService; +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.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +@Controller +@RequestMapping(value="/cms") +@Api(value="cms") +public class CmsContentController { + + Logger log = LoggerFactory.getLogger(CmsContentController.class); + + @Resource + private CmsContentService cmsContentService; + + @RequestMapping(value="/getCms",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询列表") + public ResponseData getCms(@RequestParam(value = "code" , required = false) String code, + @RequestParam(value = "platformCode" , required = false) String platformCode) { + try { + + Map map = new HashMap<>(); + map.put("code", code); + if (platformCode == null) { + platformCode = "WXAPPLETS"; + } + map.put("platformCode", platformCode); + return ResponseMsgUtil.success(cmsContentService.getList(map)); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/cweb/src/main/resources/dev/application.yml b/cweb/src/main/resources/dev/application.yml new file mode 100644 index 0000000..b012cab --- /dev/null +++ b/cweb/src/main/resources/dev/application.yml @@ -0,0 +1,89 @@ +server: + port: 9701 + servlet: + context-path: /crest + +#配置是否为debug模式,debug模式下,不开启权限校验 +debug: false + +#datasource数据源设置 +spring: + datasource: + url: jdbc:mysql://139.9.154.68:3306/puhui_go?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + username: root + password: HF123456. + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.jdbc.Driver + filters: stat + maxActive: 10 + initialSize: 5 + maxWait: 60000 + minIdle: 5 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: select 'x' + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + maxOpenPreparedStatements: 20 + redis: + database: 1 + host: 139.9.154.68 + port: 36379 + password: HF123456.Redis + timeout: 1000 + jedis: + pool: + max-active: 20 + max-wait: -1 + max-idle: 10 + min-idle: 0 + #配置日期返回至前台为时间戳 + jackson: + serialization: + write-dates-as-timestamps: true +mybatis: + mapperLocations: + - classpath*:sqlmap*/*.xml + type-aliases-package: + org.springboot.sample.entity + +pagehelper: + helperDialect: mysql + reasonable: true + supportMethodsArguments: true + params: count=countSql + +rocketmq: + name-server: 139.9.154.68:9876 + producer: + access-key: huifukeji + secret-key: HF123456. + #必须指定group + group: default-group + consumer: + access-key: huifukeji + secret-key: HF123456. + +jetcache: + statIntervalMinutes: 15 + areaInCacheName: false + local: + default: + type: linkedhashmap + keyConvertor: fastjson + remote: + default: + type: redis + host: 139.9.154.68 + port: 36379 + password: HF123456.Redis + keyConvertor: fastjson + broadcastChannel: projectA + valueEncoder: java + valueDecoder: java + poolConfig: + minIdle: 5 + maxIdle: 20 + maxTotal: 50 diff --git a/cweb/src/main/resources/dev/config.properties b/cweb/src/main/resources/dev/config.properties new file mode 100644 index 0000000..2bb287c --- /dev/null +++ b/cweb/src/main/resources/dev/config.properties @@ -0,0 +1 @@ +fileUrl=/home/project/phg/filesystem diff --git a/cweb/src/main/resources/dev/logback.xml b/cweb/src/main/resources/dev/logback.xml new file mode 100644 index 0000000..ff7bde9 --- /dev/null +++ b/cweb/src/main/resources/dev/logback.xml @@ -0,0 +1,72 @@ + + + + + %d %p (%file:%line\)- %m%n + UTF-8 + + + + log/base.log + + log/base.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/dao.log + + log/dao.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/error.log + + log/error.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + + + + + + + + + + + + diff --git a/cweb/src/main/resources/pre/application.yml b/cweb/src/main/resources/pre/application.yml new file mode 100644 index 0000000..874093a --- /dev/null +++ b/cweb/src/main/resources/pre/application.yml @@ -0,0 +1,56 @@ +server: + port: 9301 + servlet: + context-path: /crest + +#配置是否为debug模式,debug模式下,不开启权限校验 +debug: false + +#datasource数据源设置 +spring: + datasource: + url: jdbc:mysql://139.9.154.68:3306/hsg_pre?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + username: root + password: HF123456. + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.jdbc.Driver + filters: stat + maxActive: 10 + initialSize: 5 + maxWait: 60000 + minIdle: 5 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: select 'x' + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + maxOpenPreparedStatements: 20 + redis: + database: 1 + host: 139.9.154.68 + port: 36379 + password: HF123456.Redis + timeout: 1000 + jedis: + pool: + max-active: 20 + max-wait: -1 + max-idle: 10 + min-idle: 0 + #配置日期返回至前台为时间戳 + jackson: + serialization: + write-dates-as-timestamps: true +mybatis: + mapperLocations: + - classpath*:sqlmap*/*.xml + type-aliases-package: + org.springboot.sample.entity + +pagehelper: + helperDialect: mysql + reasonable: true + supportMethodsArguments: true + params: count=countSql diff --git a/cweb/src/main/resources/pre/config.properties b/cweb/src/main/resources/pre/config.properties new file mode 100644 index 0000000..d26a02e --- /dev/null +++ b/cweb/src/main/resources/pre/config.properties @@ -0,0 +1 @@ +fileUrl=/home/project/hsg/filesystem diff --git a/cweb/src/main/resources/pre/logback.xml b/cweb/src/main/resources/pre/logback.xml new file mode 100644 index 0000000..ff7bde9 --- /dev/null +++ b/cweb/src/main/resources/pre/logback.xml @@ -0,0 +1,72 @@ + + + + + %d %p (%file:%line\)- %m%n + UTF-8 + + + + log/base.log + + log/base.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/dao.log + + log/dao.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/error.log + + log/error.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + + + + + + + + + + + + diff --git a/cweb/src/main/resources/prod/application.yml b/cweb/src/main/resources/prod/application.yml new file mode 100644 index 0000000..34bb930 --- /dev/null +++ b/cweb/src/main/resources/prod/application.yml @@ -0,0 +1,86 @@ +server: + port: 9701 + servlet: + context-path: /crest + +#配置是否为debug模式,debug模式下,不开启权限校验 +debug: false + +#datasource数据源设置 +spring: + datasource: + url: jdbc:mysql://192.168.0.63:21100/phg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 + username: phg + password: HUfukeji123456!@# + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.jdbc.Driver + filters: stat + maxActive: 10 + initialSize: 5 + maxWait: 60000 + minIdle: 5 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: select 'x' + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + maxOpenPreparedStatements: 20 + + redis: + database: 1 + host: 127.0.0.1 + port: 36379 + password: HF123456.Redis + timeout: 1000 + jedis: + pool: + max-active: 20 + max-wait: -1 + max-idle: 10 + min-idle: 0 + #配置日期返回至前台为时间戳 + jackson: + serialization: + write-dates-as-timestamps: true + +rocketmq: + name-server: 1.95.70.9:9876 + producer: + #必须指定group + group: default-group + +mybatis: + mapperLocations: + - classpath*:sqlmap*/*.xml + type-aliases-package: + org.springboot.sample.entity + +jetcache: + statIntervalMinutes: 15 + areaInCacheName: false + local: + default: + type: linkedhashmap + keyConvertor: fastjson + remote: + default: + type: redis + host: 127.0.0.1 + port: 36379 + password: HF123456.Redis + keyConvertor: fastjson + broadcastChannel: projectA + valueEncoder: java + valueDecoder: java + poolConfig: + minIdle: 5 + maxIdle: 20 + maxTotal: 50 + +pagehelper: + helperDialect: mysql + reasonable: true + supportMethodsArguments: true + params: count=countSql diff --git a/cweb/src/main/resources/prod/config.properties b/cweb/src/main/resources/prod/config.properties new file mode 100644 index 0000000..2bb287c --- /dev/null +++ b/cweb/src/main/resources/prod/config.properties @@ -0,0 +1 @@ +fileUrl=/home/project/phg/filesystem diff --git a/cweb/src/main/resources/prod/logback.xml b/cweb/src/main/resources/prod/logback.xml new file mode 100644 index 0000000..5701932 --- /dev/null +++ b/cweb/src/main/resources/prod/logback.xml @@ -0,0 +1,95 @@ + + + + + %d %p (%file:%line\)- %m%n + UTF-8 + + + + log/base.log + + log/base.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/dao.log + + log/dao.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/error.log + + log/error.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + + + + + + + + + + + + + + + + log/QianZhuLog.log + + log/QianZhuLog/QianZhuLog.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..bfdac5d --- /dev/null +++ b/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + com.cg + cg-parent + pom + 1.0-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-parent + 2.0.5.RELEASE + + + + + + + UTF-8 + UTF-8 + 2.6.1 + 2.9.9 + + + + + commons-net + commons-net + 3.6 + + + net.coobird + thumbnailator + 0.4.8 + + + junit + junit + 4.12 + + test + + + org.springframework.boot + spring-boot-starter-test + test + + + com.github.binarywang + weixin-java-mp + 3.8.0 + + + + compile + + + + service + cweb + bweb + + + + diff --git a/service/pom.xml b/service/pom.xml new file mode 100644 index 0000000..9648e50 --- /dev/null +++ b/service/pom.xml @@ -0,0 +1,260 @@ + + + + com.cg + cg-parent + 1.0-SNAPSHOT + + 4.0.0 + + service + PACKT-SNAPSHOT + + + UTF-8 + UTF-8 + 1.8 + 2.6.1 + 2.9.9 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.3.1 + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + com.alicp.jetcache + jetcache-starter-redis + 2.5.0 + + + org.apache.rocketmq + rocketmq-spring-boot-starter + 2.2.2 + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.2.10 + + + org.aspectj + aspectjweaver + 1.8.13 + + + tk.mybatis + mapper + 3.3.0 + + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + + mysql + mysql-connector-java + 5.1.34 + + + + + com.alibaba + druid + 1.0.20 + + + + io.springfox + springfox-swagger2 + ${springfox-version} + + + + io.springfox + springfox-swagger-ui + ${springfox-version} + + + + joda-time + joda-time + ${joda-time-version} + + + + org.slf4j + slf4j-api + 1.7.25 + + + org.slf4j + slf4j-simple + 1.7.25 + provided + + + org.apache.commons + commons-lang3 + 3.7 + + + org.apache.commons + commons-collections4 + 4.2 + + + commons-codec + commons-codec + 1.10 + + + commons-logging + commons-logging + 1.2 + + + + commons-fileupload + commons-fileupload + 1.4 + + + junit + junit + 4.12 + test + + + commons-io + commons-io + 2.6 + + + com.alibaba + fastjson + 1.2.7 + + + org.apache.httpcomponents + httpmime + 4.5.6 + + + com.aliyun + aliyun-java-sdk-core + 4.1.0 + + + + dom4j + dom4j + 1.6.1 + + + org.apache.poi + poi + 4.1.2 + + + org.apache.poi + poi-ooxml + 4.1.2 + + + org.apache.poi + poi-ooxml-schemas + 4.1.2 + + + com.google.zxing + javase + 3.3.0 + + + com.google.code.gson + gson + + + org.slf4j + slf4j-api + 1.7.7 + + + com.thoughtworks.xstream + xstream + 1.4.11.1 + + + com.github.binarywang + weixin-java-miniapp + 3.8.0 + + + com.alibaba + easyexcel + 2.2.6 + + + com.sun.jersey + jersey-client + 1.16 + + + org.projectlombok + lombok + + + com.huaweicloud + esdk-obs-java-bundle + [3.21.8,) + + + com.aliyun + ocr_api20210707 + 1.1.1 + + + + + + src/main/resources/${env} + false + + + + diff --git a/service/src/main/resources/dev/commonConfig.properties b/service/src/main/resources/dev/commonConfig.properties new file mode 100644 index 0000000..dec148e --- /dev/null +++ b/service/src/main/resources/dev/commonConfig.properties @@ -0,0 +1,15 @@ + +domainName=https://phgcs.dctpay.com + +wechatMpAppid=wxa075e8509802f826 +wechatMpSecret=0e606fc1378d35e359fcf3f15570b2c5 + +wechatMaAppid=wx8d49e2f83025229d +wechatMaSecret=d8d6dcaef77d3b659258a01b5ddba5df + +obsBucketName=phg-test +obsEndPoint=https://obs.cn-southwest-2.myhuaweicloud.com +obsUrl=https://phg-test.obs.cn-southwest-2.myhuaweicloud.com + +huiPayPreorderNotifyUrl=https://phgcs.dctpay.com/order/notify/huipay + diff --git a/service/src/main/resources/pre/commonConfig.properties b/service/src/main/resources/pre/commonConfig.properties new file mode 100644 index 0000000..e69de29 diff --git a/service/src/main/resources/prod/commonConfig.properties b/service/src/main/resources/prod/commonConfig.properties new file mode 100644 index 0000000..08e5840 --- /dev/null +++ b/service/src/main/resources/prod/commonConfig.properties @@ -0,0 +1,14 @@ + +domainName=https://phg.dctpay.com + +wechatMpAppid=wxa075e8509802f826 +wechatMpSecret=0e606fc1378d35e359fcf3f15570b2c5 + +wechatMaAppid=wx8d49e2f83025229d +wechatMaSecret=d8d6dcaef77d3b659258a01b5ddba5df + +obsBucketName=phg +obsEndPoint=https://obs.cn-southwest-2.myhuaweicloud.com +obsUrl=https://phg.obs.cn-southwest-2.myhuaweicloud.com + +huiPayPreorderNotifyUrl=https://phg.dctpay.com/order/notify/huipay