commit c8b10b13f296bc921f3d82ad62ee9430b51f5131 Author: zhizhi wu <2377881365@qq.com> Date: Thu Mar 10 18:24:06 2022 +0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..073a042 --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +# Created by .ignore support plugin (hsz.mobi) +### Example user template template +### Example user template +target +target/ +target/* +# IntelliJ project files +.idea +.idea/ +.idea/* +*.iml +.mvn +.mvn/ +.mvn/* +out +gen +### Java template +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +mbg.xml +resources/mbg.xml +resources/application.yml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..6f7d158 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/23778.xml b/.idea/dictionaries/23778.xml new file mode 100644 index 0000000..798db79 --- /dev/null +++ b/.idea/dictionaries/23778.xml @@ -0,0 +1,7 @@ + + + + tencent + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..63e9001 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e1f9d8f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/braintraining.iml b/braintraining.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/braintraining.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e0ec544 --- /dev/null +++ b/pom.xml @@ -0,0 +1,280 @@ + + + 4.0.0 + + com.ccsens + braintraining + 1.0-SNAPSHOT + + + 1.8 + + + org.springframework.boot + spring-boot-starter-parent + 2.1.8.RELEASE + + + + + com.ccsensptos + wechatutil + 1.0-SNAPSHOT + compile + + + org.springframework.boot + spring-boot-starter-amqp + + + com.ccsensptos + cloudutil + + + + + org.aspectj + aspectjweaver + + + + + io.netty + netty-all + 4.1.32.Final + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + org.springframework.boot + spring-boot-starter-cache + + + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-jetty + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + + + com.vaadin.external.google + android-json + + + test + + + org.springframework.boot + spring-boot-starter-actuator + + + + + cn.hutool + hutool-all + 4.1.21 + + + + + org.apache.poi + poi + 3.17 + + + org.apache.poi + poi-ooxml + 3.17 + + + + org.springframework.boot + spring-boot-starter-websocket + + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.1.1 + + + + com.github.pagehelper + pagehelper + 4.1.4 + + + + mysql + mysql-connector-java + + + + com.alibaba + druid + 1.1.10 + + + + io.jsonwebtoken + jjwt + 0.7.0 + + + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.9.0 + + + + + + + org.apache.shiro + shiro-spring + 1.4.0 + + + + org.apache.shiro + shiro-ehcache + 1.4.0 + + + + net.sourceforge.htmlcleaner + htmlcleaner + 2.22 + + + + org.apache.commons + commons-lang3 + 3.8.1 + + + + + + io.springfox + springfox-swagger2 + 2.9.2 + + + + io.springfox + springfox-swagger-ui + 2.9.2 + + + + org.mybatis.generator + mybatis-generator-core + 1.3.7 + + + + + org.beanshell + bsh + 2.0b5 + + + + org.apache.httpcomponents + httpclient + 4.5.1 + + + + org.apache.httpcomponents + httpcore + 4.4.3 + + + + com.github.qcloudsms + qcloudsms + 1.0.5 + + + com.alibaba + fastjson + 1.2.62 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.3.7 + + ${basedir}/src/main/resources/mbg.xml + true + + + + mysql + mysql-connector-java + 5.1.34 + + + + + + \ No newline at end of file diff --git a/src/main/java/com/ccsens/braintraining/BrainTrainingApplication.java b/src/main/java/com/ccsens/braintraining/BrainTrainingApplication.java new file mode 100644 index 0000000..1025534 --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/BrainTrainingApplication.java @@ -0,0 +1,24 @@ +package com.ccsens.braintraining; + +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.cache.annotation.EnableCaching; +import org.springframework.context.annotation.ComponentScan; + +/** + * @description: + * @author: whj + * @time: 2022/3/4 9:34 + */ +@MapperScan(basePackages = {"com.ccsens.braintraining.persist.*"}) +@ServletComponentScan +@EnableCaching +@SpringBootApplication +@ComponentScan(basePackages = {"com.ccsens"}) +public class BrainTrainingApplication { + public static void main(String[] args) { + SpringApplication.run(BrainTrainingApplication.class, args); + } +} diff --git a/src/main/java/com/ccsens/braintraining/api/DebugController.java b/src/main/java/com/ccsens/braintraining/api/DebugController.java new file mode 100644 index 0000000..eb19586 --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/api/DebugController.java @@ -0,0 +1,40 @@ +package com.ccsens.braintraining.api; + +import com.ccsens.util.JsonResponse; +import com.ccsens.wechatutil.bean.dto.wxofficial.WxQrCodeDto; +import com.ccsens.wechatutil.bean.vo.wxofficial.WxQrCodeVo; +import com.ccsens.wechatutil.wxofficial.OfficialQrCodeUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.UUID; + +/** + * @description: + * @author: whj + * @time: 2022/3/8 8:42 + */ +@Api(tags = "DEBUG" , description = "DebugController | ") +@RestController +@RequestMapping("/debug") +@Slf4j +public class DebugController { + + + @ApiOperation(value = "/测试",notes = "") + @ApiImplicitParams({ + }) + @RequestMapping(value="",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) + public JsonResponse debug(HttpServletRequest request) throws Exception { + + + return JsonResponse.newInstance().ok("hello world!"); + } + +} diff --git a/src/main/java/com/ccsens/braintraining/api/WxTencentController.java b/src/main/java/com/ccsens/braintraining/api/WxTencentController.java new file mode 100644 index 0000000..1feabac --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/api/WxTencentController.java @@ -0,0 +1,102 @@ +package com.ccsens.braintraining.api; + +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import com.ccsens.braintraining.service.IWxTencentService; +import com.ccsens.util.JacksonUtil; +import com.ccsens.util.JsonResponse; +import com.ccsens.wechatutil.bean.dto.wxmini.NoticeDto; +import com.ccsens.wechatutil.bean.dto.wxofficial.WxQrCodeDto; +import com.ccsens.wechatutil.bean.vo.wxofficial.WxQrCodeVo; +import com.ccsens.wechatutil.wxofficial.OfficialQrCodeUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.io.BufferedReader; +import java.io.IOException; +import java.security.NoSuchAlgorithmException; +import java.util.UUID; + +/** + * @description: + * @author: whj + * @time: 2022/3/8 9:31 + */ +@Api(tags = "微信公众号相关" ) +@RestController +@RequestMapping("/wxTencent") +@Slf4j +public class WxTencentController { + + private String token = "ccsensChuanKong"; + private String encodingAesKey = "nysgv5sKS5HPMMsHiVcDOE9BBCtX7Ho5DSv3s0qS9b9"; + + @Resource + private IWxTencentService wxTencetnService; + + + + @ApiOperation(value = "/生成公众号临时二维码",notes = "") + @ApiImplicitParams({ + }) + @RequestMapping(value="createQrCode",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) + public JsonResponse createQrCode(Long equipmentId) { + WxQrCodeVo.QrCodeUrl url = OfficialQrCodeUtil.send(new WxQrCodeDto.Create(7*24*60*60L, OfficialQrCodeUtil.QR_STR_SCENE, null, UUID.randomUUID().toString()), + "wxb3be21dcd7912555", "9213776254878a8065f1a29d1f58a02c"); + String qrCodeUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + url.getTicket(); + return JsonResponse.newInstance().ok(qrCodeUrl); + } + + + @ApiOperation(value = "接收公众号消息通知", notes = "") + @RequestMapping(value = "/notice", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"}) + public String noticeGet(@Validated NoticeDto.ValidMsg validMsg) throws NoSuchAlgorithmException { + log.info("接收微信小程序token:{},token:{}",validMsg,token); + boolean check = validMsg.check(token); + log.info("校验结果:{}", check); + return check ? validMsg.getEchostr() : null; + } + + @ApiOperation(value = "接收公众号消息通知", notes = "") + @RequestMapping(value = "/notice", method = RequestMethod.POST) + public String notice(HttpServletRequest request) throws IOException { + log.info("接收公众号消息通知:{}", request.getParameterMap()); + + BufferedReader reader = request.getReader(); + StringBuilder builder = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + builder.append(line); + } + log.info("获取参数:{}", builder.toString()); + NoticeDto.Notice notice = JSONObject.parseObject(JacksonUtil.xmlToJson(builder.toString()), NoticeDto.Notice.class); + + + log.info("接收公众号消息息通知:{}", notice); + if (notice== null || StrUtil.isEmpty(notice.getContent())) { + return "success"; + } + switch (notice.getEvent()) { + case "subscribe": + // 用户未关注时,进行关注后的事件推送 + // 带参数二维码访问,EventKey有值,普通关注没有 + break; + case "SCAN": + // 用户已关注时的事件推送 + break; + case "unsubscribe": + // 取消订阅 + break; + } + return "success"; + } + +} diff --git a/src/main/java/com/ccsens/braintraining/config/BeanConfig.java b/src/main/java/com/ccsens/braintraining/config/BeanConfig.java new file mode 100644 index 0000000..7b181e8 --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/config/BeanConfig.java @@ -0,0 +1,44 @@ +package com.ccsens.braintraining.config; + +import com.ccsens.braintraining.intercept.MybatisInterceptor; +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; + +/** + * @description: + * @author: wuHuiJuan + * @create: 2019/12/03 18:01 + */ +@Configuration +public class BeanConfig { + /** + * 注册拦截器 + */ + @Bean + public MybatisInterceptor mybatisInterceptor() { + MybatisInterceptor interceptor = new MybatisInterceptor(); + return interceptor; + } + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + corsConfiguration.addAllowedOrigin("*"); + corsConfiguration.addAllowedHeader("*"); + corsConfiguration.addAllowedMethod("*"); + // 预检请求的有效期,单位为秒。 + corsConfiguration.setMaxAge(3600L); + // 是否支持安全证书(必需参数) + corsConfiguration.setAllowCredentials(true); + return corsConfiguration; + } + + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + +} diff --git a/src/main/java/com/ccsens/braintraining/config/SpringConfig.java b/src/main/java/com/ccsens/braintraining/config/SpringConfig.java new file mode 100644 index 0000000..3c97929 --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/config/SpringConfig.java @@ -0,0 +1,141 @@ +package com.ccsens.braintraining.config; + + +import cn.hutool.core.lang.Snowflake; +import cn.hutool.core.util.IdUtil; +import com.ccsens.util.PropUtil; +import com.ccsens.util.config.DruidProps; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.StringHttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.servlet.config.annotation.*; + +import javax.annotation.Resource; +import javax.sql.DataSource; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; +import java.util.TimeZone; + +/** + * @author whj + */ +@Configuration +public class SpringConfig implements WebMvcConfigurer { + @Resource + private DruidProps druidPropsUtil; + @Value("${spring.snowflake.workerId}") + private String workerId; + @Value("${spring.snowflake.dataCenterId}") + private String dataCenterId; + + + /** + * 配置Converter + * @return + */ + @Bean + public HttpMessageConverter responseStringConverter() { + return new StringHttpMessageConverter( + Charset.forName("UTF-8")); + } + + @Bean + public HttpMessageConverter responseJsonConverter(){ + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + List mediaTypeList = new ArrayList<>(); + mediaTypeList.add(MediaType.TEXT_HTML); + mediaTypeList.add(MediaType.APPLICATION_JSON_UTF8); + converter.setSupportedMediaTypes(mediaTypeList); + + ObjectMapper objectMapper = new ObjectMapper(); + SimpleModule simpleModule = new SimpleModule(); + simpleModule.addSerializer(Long.class, ToStringSerializer.instance); + simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); + objectMapper.registerModule(simpleModule); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.setTimeZone(TimeZone.getTimeZone("GMT+8")); + converter.setObjectMapper(objectMapper); + + return converter; + } + + @Override + public void configureMessageConverters(List> converters) { + converters.add(responseStringConverter()); + converters.add(responseJsonConverter()); + } + + @Override + public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { + configurer.favorPathExtension(false); + } + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") + // 允许提交请求的方法,*表示全部允许 + .allowedMethods("*") + // #允许向该服务器提交请求的URI,*表示全部允许 + .allowedOrigins("*") + // 允许cookies跨域 + .allowCredentials(true) + // #允许访问的头信息,*表示全部 + .allowedHeaders("*") + // 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了 + .maxAge(18000L); + + } + + + + + /** + * 配置静态资源 + */ + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("swagger-ui.html") + .addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + + registry.addResourceHandler("/uploads/**") +// .addResourceLocations("file:D:/datang_soft/project/uploads/"); + .addResourceLocations("file:" + PropUtil.path); + + registry.addResourceHandler("/static/**") + .addResourceLocations("classpath:/static/"); + } + + /** + * 配置拦截器 + * @param registry 拦截器 + */ + @Override + public void addInterceptors(InterceptorRegistry registry) { + + } + + + /** + * 配置数据源(单数据源) + */ + @Bean + public DataSource dataSource(){ + return druidPropsUtil.createDruidDataSource(); + } + + @Bean + public Snowflake snowflake(){ + return IdUtil.createSnowflake(Long.parseLong(workerId),Long.parseLong(dataCenterId)); + } +} \ No newline at end of file diff --git a/src/main/java/com/ccsens/braintraining/config/SwaggerConfigure.java b/src/main/java/com/ccsens/braintraining/config/SwaggerConfigure.java new file mode 100644 index 0000000..19409e5 --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/config/SwaggerConfigure.java @@ -0,0 +1,58 @@ +package com.ccsens.braintraining.config; + +import com.ccsens.util.WebConstant; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ParameterBuilder; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.schema.ModelRef; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Parameter; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author whj + */ +@Configuration +@EnableSwagger2 +@ConditionalOnExpression("${swagger.enable}") +public class SwaggerConfigure { + @Bean + public Docket customDocket() { + // + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors + .basePackage("com.ccsens.datang.api")) + .build() + .globalOperationParameters(setHeaderToken()); + } + + private ApiInfo apiInfo() { + return new ApiInfo("Swagger Tall-game", + "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.", + "1.0.0", + "http://swagger.io/terms/", + "zhangsan", + "Apache 2.0", + "http://www.apache.org/licenses/LICENSE-2.0.html" + ); + } + + private List setHeaderToken() { + ParameterBuilder tokenPar = new ParameterBuilder(); + List pars = new ArrayList<>(); + tokenPar.name(WebConstant.HEADER_KEY_TOKEN).description("token") + .defaultValue(WebConstant.HEADER_KEY_TOKEN_PREFIX) + .modelRef(new ModelRef("string")).parameterType("header").required(false).build(); + pars.add(tokenPar.build()); + return pars; + } +} diff --git a/src/main/java/com/ccsens/braintraining/intercept/MybatisInterceptor.java b/src/main/java/com/ccsens/braintraining/intercept/MybatisInterceptor.java new file mode 100644 index 0000000..24c3d25 --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/intercept/MybatisInterceptor.java @@ -0,0 +1,159 @@ +package com.ccsens.braintraining.intercept; + +import cn.hutool.core.collection.CollectionUtil; +import com.ccsens.util.WebConstant; +import org.apache.ibatis.executor.Executor; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.ResultMap; +import org.apache.ibatis.mapping.SqlSource; +import org.apache.ibatis.plugin.*; +import org.apache.ibatis.reflection.DefaultReflectorFactory; +import org.apache.ibatis.reflection.MetaObject; +import org.apache.ibatis.reflection.factory.DefaultObjectFactory; +import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory; +import org.apache.ibatis.session.ResultHandler; +import org.apache.ibatis.session.RowBounds; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +/** + * @description: 查询添加rec_status = 0 + * @author: wuHuiJuan + * @create: 2019/12/11 10:58 + */ +@Intercepts({ + @Signature( + type = Executor.class, + method = "query", + args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class} + ) +}) +public class MybatisInterceptor implements Interceptor { + @Override + public Object intercept(Invocation invocation) throws Throwable { + + + String selectByExample = "selectByExample"; + String countByExample = "countByExample"; + String countByExample2 = "selectByExample_COUNT"; + String selectByPrimaryKey = "selectByPrimaryKey"; + + Object[] args = invocation.getArgs(); + MappedStatement statement = (MappedStatement) args[0]; + if (statement.getId().endsWith(selectByExample) + || statement.getId().endsWith(countByExample) + || statement.getId().endsWith(countByExample2)) { + //XXXExample + Object example = args[1]; + + addCondition(statement, example); + + + + + } else if (statement.getId().endsWith(selectByPrimaryKey)) { + BoundSql boundSql = statement.getBoundSql(args[1]); + String sql = boundSql.getSql() + " and rec_status = 0"; + MappedStatement newStatement = newMappedStatement(statement, new BoundSqlSqlSource(boundSql)); + MetaObject msObject = MetaObject.forObject(newStatement, new DefaultObjectFactory(), new DefaultObjectWrapperFactory(),new DefaultReflectorFactory()); + msObject.setValue("sqlSource.boundSql.sql", sql); + args[0] = newStatement; + } + + return invocation.proceed(); + } + + private void addCondition(MappedStatement statement, Object example) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException { + if (example instanceof Map) { + example = ((Map) example).get("_ORIGINAL_PARAMETER_OBJECT"); + } + + + Method method = example.getClass().getMethod("getOredCriteria", null); + //获取到条件数组,第一个是Criteria + List list = (List) method.invoke(example); + if (CollectionUtil.isEmpty(list)) { + Class clazz = ((ResultMap) statement.getResultMaps().get(0)).getType(); + String exampleName = clazz.getName() + "Example"; + Object paramExample = Class.forName(exampleName).newInstance(); + Method createCriteria = paramExample.getClass().getMethod("createCriteria"); + Object criteria = createCriteria.invoke(paramExample); + Method andIsDelEqualTo = criteria.getClass().getMethod("andRecStatusEqualTo", Byte.class); + andIsDelEqualTo.invoke(criteria, WebConstant.REC_STATUS.Normal.value); + list.add(criteria); + } else { + Object criteria = list.get(0); + Method getCriteria = criteria.getClass().getMethod("getCriteria"); + List params = (List) getCriteria.invoke(criteria); + boolean hasDel = false; + for (Object param : params) { + Method getCondition = param.getClass().getMethod("getCondition"); + Object condition = getCondition.invoke(param); + if ("rec_status =".equals(condition)) { + hasDel = true; + } + } + if (!hasDel) { + Method andIsDelEqualTo = criteria.getClass().getMethod("andRecStatusEqualTo", Byte.class); + andIsDelEqualTo.invoke(criteria, WebConstant.REC_STATUS.Normal.value); + } + + } + + } + + @Override + public Object plugin(Object target) { + return Plugin.wrap(target, this); + } + + @Override + public void setProperties(Properties properties) { + + } + + private MappedStatement newMappedStatement(MappedStatement ms, SqlSource newSqlSource) { + MappedStatement.Builder builder = + new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), newSqlSource, ms.getSqlCommandType()); + builder.resource(ms.getResource()); + builder.fetchSize(ms.getFetchSize()); + builder.statementType(ms.getStatementType()); + builder.keyGenerator(ms.getKeyGenerator()); + if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) { + StringBuilder keyProperties = new StringBuilder(); + for (String keyProperty : ms.getKeyProperties()) { + keyProperties.append(keyProperty).append(","); + } + keyProperties.delete(keyProperties.length() - 1, keyProperties.length()); + builder.keyProperty(keyProperties.toString()); + } + builder.timeout(ms.getTimeout()); + builder.parameterMap(ms.getParameterMap()); + builder.resultMaps(ms.getResultMaps()); + builder.resultSetType(ms.getResultSetType()); + builder.cache(ms.getCache()); + builder.flushCacheRequired(ms.isFlushCacheRequired()); + builder.useCache(ms.isUseCache()); + + return builder.build(); + } + + + // 定义一个内部辅助类,作用是包装sq + class BoundSqlSqlSource implements SqlSource { + private BoundSql boundSql; + public BoundSqlSqlSource(BoundSql boundSql) { + this.boundSql = boundSql; + } + @Override + public BoundSql getBoundSql(Object parameterObject) { + return boundSql; + } + } + +} diff --git a/src/main/java/com/ccsens/braintraining/service/IWxTencentService.java b/src/main/java/com/ccsens/braintraining/service/IWxTencentService.java new file mode 100644 index 0000000..eb64923 --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/service/IWxTencentService.java @@ -0,0 +1,8 @@ +package com.ccsens.braintraining.service; + +/** + * @author: whj + * @time: 2022/3/10 15:41 + */ +public interface IWxTencentService { +} diff --git a/src/main/java/com/ccsens/braintraining/service/WxTencentService.java b/src/main/java/com/ccsens/braintraining/service/WxTencentService.java new file mode 100644 index 0000000..3952dea --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/service/WxTencentService.java @@ -0,0 +1,20 @@ +package com.ccsens.braintraining.service; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +/** + * @description: + * @author: whj + * @time: 2022/3/10 15:42 + */ +@Slf4j +@Service +@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) +public class WxTencentService implements IWxTencentService { + + + +} diff --git a/src/main/java/com/ccsens/braintraining/util/BrainTrainingCodeError.java b/src/main/java/com/ccsens/braintraining/util/BrainTrainingCodeError.java new file mode 100644 index 0000000..596a66b --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/util/BrainTrainingCodeError.java @@ -0,0 +1,14 @@ +package com.ccsens.braintraining.util; + +import com.ccsens.util.CodeError; + +/** + * @description: + * @author: whj + * @time: 2022/3/4 9:44 + */ +public class BrainTrainingCodeError extends CodeError { + + + +} diff --git a/src/main/java/com/ccsens/braintraining/util/BrainTrainingConstant.java b/src/main/java/com/ccsens/braintraining/util/BrainTrainingConstant.java new file mode 100644 index 0000000..caf8f8b --- /dev/null +++ b/src/main/java/com/ccsens/braintraining/util/BrainTrainingConstant.java @@ -0,0 +1,11 @@ +package com.ccsens.braintraining.util; + +import com.ccsens.util.WebConstant; + +/** + * @description: + * @author: whj + * @time: 2022/3/4 9:44 + */ +public class BrainTrainingConstant extends WebConstant { +} diff --git a/src/main/resources/application-common.yml b/src/main/resources/application-common.yml new file mode 100644 index 0000000..33d6173 --- /dev/null +++ b/src/main/resources/application-common.yml @@ -0,0 +1,30 @@ +logging: + level: + com: + favorites: DEBUG + org: + hibernate: ERROR + springframework: + web: DEBUG +mybatis: + config-location: classpath:mybatis/mybatis-config.xml + mapper-locations: classpath*:mapper_*/*.xml +# type-aliases-package: com.ccsens.mtpro.bean +#server: +# tomcat: +# uri-encoding: UTF-8 +spring: + http: + encoding: + charset: UTF-8 + enabled: true + force: true + log-request-details: true + servlet: + multipart: + max-file-size: 200MB + max-request-size: 200MB + snowflake: + dataCenterId: 2 + workerId: 2 + diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..7cab1d4 --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,51 @@ +server: + port: 7280 + servlet: + context-path: /v1.0 +spring: + application: + name: ptccsens + datasource: + type: com.alibaba.druid.pool.DruidDataSource +# rabbitmq: +# host: 192.168.0.99 +# password: 111111 +# port: 5672 +# username: admin +# rabbitmq: +# host: dd.tall.wiki +# password: 111111 +# port: 5672 +# username: admin +# redis: +# database: 0 +# host: 127.0.0.1 +# jedis: +# pool: +# max-active: 200 +# max-idle: 10 +# max-wait: -1ms +# min-idle: 0 +# password: '' +# port: 6379 +# timeout: 1000ms +swagger: + enable: true +#mybatisCache: +# database: 1 +# host: 127.0.0.1 +# jedis: +# pool: +# max-active: 200 +# max-idle: 10 +# max-wait: -1 +# min-idle: 0 +# password: '' +# port: 6379 +# timeout: 1000 + +notGatewayUrl: http://101.201.226.163:7320/v1.0 +file: + path: /home/cloud/datang/uploads/ + domain: http://127.0.0.1:7270/v1.0/ + imgDomain: http://127.0.0.1:7270/v1.0/uploads/ diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml new file mode 100644 index 0000000..6659ad9 --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,16 @@ +server: + port: 7280 + servlet: + context-path: /v1.0 +spring: + application: + name: datang + datasource: + type: com.alibaba.druid.pool.DruidDataSource +swagger: + enable: true + +file: + path: /home/cloud/datang/uploads/ + domain: http://10.119.190.12:8000/v1.0/ + imgDomain: http://10.119.190.12:8000/v1.0/uploads/ diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml new file mode 100644 index 0000000..64d0727 --- /dev/null +++ b/src/main/resources/application-test.yml @@ -0,0 +1,16 @@ +server: + port: 7280 + servlet: + context-path: /v1.0 +spring: + application: + name: ptccsens + datasource: + type: com.alibaba.druid.pool.DruidDataSource +swagger: + enable: true + +file: + path: /home/cloud/datang/uploads/ + domain: http://test.tall.wiki/datang/v1.0/ + imgDomain: http://test.tall.wiki/datang/v1.0/uploads/ diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..c3b11fb --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,4 @@ +spring: + profiles: + active: test + include: common, util-test diff --git a/src/main/resources/druid-dev.yml b/src/main/resources/druid-dev.yml new file mode 100644 index 0000000..2b0497b --- /dev/null +++ b/src/main/resources/druid-dev.yml @@ -0,0 +1,35 @@ +spring: + datasource: + druid: + connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 + driverClassName: com.mysql.cj.jdbc.Driver + dynamicUrl: jdbc:mysql://localhost:3306/${schema} + filterExclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' + filterName: druidFilter + filterProfileEnable: true + filterUrlPattern: /* + filters: stat,wall + initialSize: 5 + maxActive: 20 + maxPoolPreparedStatementPerConnectionSize: 20 + maxWait: 60000 + minEvictableIdleTimeMillis: 300000 + minIdle: 5 +# password: 37080c1f223685592316b02dad8816c019290a476e54ebb638f9aa3ba8b6bdb9 + password: 68073a279b399baa1fa12cf39bfbb65bfc1480ffee7b659ccc81cf19be8c4473 + poolPreparedStatements: true + servletLogSlowSql: true + servletLoginPassword: 111111 + servletLoginUsername: druid + servletName: druidServlet + servletResetEnable: true + servletUrlMapping: /druid/* + testOnBorrow: false + testOnReturn: false + testWhileIdle: true + timeBetweenEvictionRunsMillis: 60000 + url: jdbc:mysql://test.tall.wiki:3306/datang?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true + username: root + validationQuery: SELECT 1 FROM DUAL +# env: CCSENS_GAME + env: CCSENS_TALL \ No newline at end of file diff --git a/src/main/resources/druid-prod.yml b/src/main/resources/druid-prod.yml new file mode 100644 index 0000000..169e167 --- /dev/null +++ b/src/main/resources/druid-prod.yml @@ -0,0 +1,33 @@ +spring: + datasource: + druid: + connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 + driverClassName: com.mysql.cj.jdbc.Driver + dynamicUrl: jdbc:mysql://localhost:3306/${schema} + filterExclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' + filterName: druidFilter + filterProfileEnable: true + filterUrlPattern: /* + filters: stat,wall + initialSize: 5 + maxActive: 20 + maxPoolPreparedStatementPerConnectionSize: 20 + maxWait: 60000 + minEvictableIdleTimeMillis: 300000 + minIdle: 5 + password: 68073a279b399baa1fa12cf39bfbb65bfc1480ffee7b659ccc81cf19be8c4473 + poolPreparedStatements: true + servletLogSlowSql: true + servletLoginPassword: 111111 + servletLoginUsername: druid + servletName: druidServlet + servletResetEnable: true + servletUrlMapping: /druid/* + testOnBorrow: false + testOnReturn: false + testWhileIdle: true + timeBetweenEvictionRunsMillis: 60000 + url: jdbc:mysql://127.0.0.1/datang?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true + username: root + validationQuery: SELECT 1 FROM DUAL + env: CCSENS_TALL \ No newline at end of file diff --git a/src/main/resources/druid-test.yml b/src/main/resources/druid-test.yml new file mode 100644 index 0000000..746db26 --- /dev/null +++ b/src/main/resources/druid-test.yml @@ -0,0 +1,33 @@ +spring: + datasource: + druid: + connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 + driverClassName: com.mysql.cj.jdbc.Driver + dynamicUrl: jdbc:mysql://localhost:3306/${schema} + filterExclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' + filterName: druidFilter + filterProfileEnable: true + filterUrlPattern: /* + filters: stat,wall + initialSize: 5 + maxActive: 20 + maxPoolPreparedStatementPerConnectionSize: 20 + maxWait: 60000 + minEvictableIdleTimeMillis: 300000 + minIdle: 5 + password: + poolPreparedStatements: true + servletLogSlowSql: true + servletLoginPassword: 111111 + servletLoginUsername: druid + servletName: druidServlet + servletResetEnable: true + servletUrlMapping: /druid/* + testOnBorrow: false + testOnReturn: false + testWhileIdle: true + timeBetweenEvictionRunsMillis: 60000 + url: jdbc:mysql://127.0.0.1/datang?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true + username: root + validationQuery: SELECT 1 FROM DUAL + env: CCSENS_TALL \ No newline at end of file diff --git a/src/main/resources/encache.xml b/src/main/resources/encache.xml new file mode 100644 index 0000000..0f2eb76 --- /dev/null +++ b/src/main/resources/encache.xml @@ -0,0 +1,37 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..c6324a2 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,196 @@ + + + + + + + + + + logback + + + + + + + + + + + + + + + + + info + + + ${CONSOLE_LOG_PATTERN} + + UTF-8 + + + + + + + + + + ${log.path}/log_debug.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + debug + ACCEPT + DENY + + + + + + + ${log.path}/log_info.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + ${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + info + ACCEPT + DENY + + + + + + + ${log.path}/log_warn.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + warn + ACCEPT + DENY + + + + + + + + ${log.path}/log_error.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + ${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log + + 100MB + + + 15 + + + + ERROR + ACCEPT + DENY + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mbg.xml b/src/main/resources/mbg.xml new file mode 100644 index 0000000..9a7526b --- /dev/null +++ b/src/main/resources/mbg.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mybatis-config.xml b/src/main/resources/mybatis/mybatis-config.xml new file mode 100644 index 0000000..e5a218d --- /dev/null +++ b/src/main/resources/mybatis/mybatis-config.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file