├── .gitignore ├── README.md ├── doc └── application-dev.yml ├── pom.xml ├── s.sh ├── soulcoder-core ├── pom.xml └── src │ └── main │ └── java │ └── tech │ └── soulcoder │ └── core │ ├── Swagger2Config.java │ ├── WebMVCConfig.java │ └── dbconfig │ ├── DruidConfigSoul.java │ ├── DruidServletConfig.java │ ├── MyBatisConfigSoul.java │ └── MybatisPageHelperConfig.java ├── soulcoder-dao ├── pom.xml └── src │ ├── main │ ├── java │ │ └── tech │ │ │ └── soulcoder │ │ │ └── dao │ │ │ ├── mapper │ │ │ └── generator │ │ │ │ ├── SoulUserDTOMapper.java │ │ │ │ └── SoulUserMapper.java │ │ │ └── pojo │ │ │ └── generator │ │ │ ├── SoulUser.java │ │ │ ├── SoulUserDTO.java │ │ │ └── SoulUserDTOExample.java │ └── resources │ │ ├── mapper │ │ └── generator │ │ │ └── SoulUserMapper.xml │ │ └── tech │ │ └── soulcoder │ │ └── dao │ │ └── mapper │ │ └── generator │ │ └── SoulUserDTOMapper.xml │ └── test │ ├── java │ └── tech │ │ └── soulcoder │ │ └── test │ │ └── GeneratorMain.java │ └── resources │ ├── generator.properties.exmple │ └── generator.xml ├── soulcoder-model └── pom.xml ├── soulcoder-service ├── pom.xml └── src │ ├── main │ └── java │ │ └── tech │ │ └── soulcoder │ │ └── service │ │ ├── TestService.java │ │ └── impl │ │ └── TestServiceImpl.java │ └── test │ └── java │ └── tech │ └── soulcoder │ └── test │ └── MyTest.java ├── soulcoder-utils ├── pom.xml └── src │ └── main │ └── java │ └── tech │ └── soulcoder │ ├── IPUtils.java │ ├── RedisOperation.java │ ├── SqlHelper.java │ ├── StringUtil.java │ ├── entity │ ├── Action.java │ ├── Action2.java │ ├── Action3.java │ ├── Action4.java │ ├── Action5.java │ ├── ActionWithException.java │ ├── ActionWithException2.java │ ├── ActionWithException3.java │ ├── ActionWithException4.java │ ├── ActionWithException5.java │ ├── EqualsFunc.java │ ├── FilterFunc.java │ ├── Func.java │ ├── Func2.java │ ├── Func3.java │ ├── Func4.java │ ├── Func5.java │ ├── FuncWithException.java │ ├── FuncWithException2.java │ ├── FuncWithException3.java │ ├── FuncWithException4.java │ ├── FuncWithException5.java │ ├── Optional.java │ ├── Optional2.java │ ├── Optional3.java │ ├── Optional4.java │ └── Optional5.java │ ├── expection │ ├── CommonException.java │ ├── CommonResponseModel.java │ └── ReturnCodeModel.java │ └── log │ ├── LogAop.java │ └── LogAuto.java └── soulcoder-web ├── .gitignore ├── pom.xml └── src ├── main ├── java │ └── tech │ │ └── soulcoder │ │ ├── StartApplication.java │ │ └── web │ │ └── TestController.java └── resources │ ├── application.yml │ ├── logback-dev.xml │ └── logback-prod.xml └── test └── java └── tech └── soulcoder └── mytest ├── BaseTest.java └── MyTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | .idea 4 | *.iws 5 | *.iml 6 | *.ipr 7 | /logs 8 | /soulcoder-web/src/main/resources/application-dev.yml 9 | /soulcoder-web/src/main/resources/application-prod.yml 10 | .DS_Store 11 | /soulcoder-dao/src/test/resources/generator.properties 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | https://gitee.com/fengyunlucode/soulcoder/ github 提交太卡了,还是用码云吧哈哈 2 | 3 | # 使用 4 | 5 | ``` 6 | # git 拉去最新分支代码 7 | 8 | git pull 9 | git branch zzb 10 | # 拷贝配置文件到指定目录 11 | cp /www/wwwroot/zzb.soulcoder.tech/application.yml /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/src/main/resources/application.yml 12 | cp /www/wwwroot/zzb.soulcoder.tech/application-prod.yml /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/src/main/resources/application-prod.yml 13 | mvn clean 14 | mvn package -Dmaven.test.skip=true 15 | # 启动 16 | cd /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/target/ 17 | nohup java -jar -Xms258m -Xmx258m soulcoder.jar & 18 | 19 | ``` 20 | 21 | # 配置文件 22 | 23 | parent 24 | 25 | ``` 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-maven-plugin 32 | 1.3.0.RELEASE 33 | 34 | tech.soulcoder.StartApplication 35 | ZIP 36 | 37 | 38 | 39 | 40 | repackage 41 | 42 | 43 | 46 | 47 | 48 | 49 | 50 | 51 | ``` 52 | 53 | web 54 | 55 | ``` 56 | 57 | 58 | soulcoder 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-maven-plugin 63 | 1.3.0.RELEASE 64 | 65 | 66 | 67 | ``` 68 | -------------------------------------------------------------------------------- /doc/application-dev.yml: -------------------------------------------------------------------------------- 1 | # 示例配置文件 在正式使用的时候copy到 /soulcoder-web/src/main/resources/ 下面 2 | server: 3 | port: 10002 4 | 5 | #log 6 | logging: 7 | config : classpath:logback-dev.xml 8 | level: 9 | org: 10 | springframework: 11 | web : INFO 12 | 13 | spring: 14 | datasource: 15 | soul: 16 | url : jdbc:mysql://127.0.0.1:3306/soulcoder?autoReconnect=true&useCompression=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true 17 | username : lala 18 | password : lalala 19 | initialSize : 5 20 | maxActive : 20 21 | minIdle : 1 22 | maxWait : 30000 23 | timeBetweenEvictionRunsMillis : 60000 24 | minEvictableIdleTimeMillis : 300000 25 | poolPreparedStatements : true 26 | maxPoolPreparedStatementPerConnectionSize : 20 27 | filters : stat, wall, config 28 | redis: 29 | database : 0 30 | host : 127.0.0.1 31 | port : 6379 32 | password : 123 33 | timeout : 5000 34 | pool : 35 | max-active : 8 36 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 37 | max-wait : -1 38 | # 连接池中的最大空闲连接 39 | max-idle : 8 40 | # 连接池中的最小空闲连接 41 | min-idle : 0 -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | tech.soulcoder 7 | soulcoder 8 | 0.0.1-SNAPSHOT 9 | 10 | soulcoder-web 11 | soulcoder-core 12 | soulcoder-service 13 | soulcoder-utils 14 | soulcoder-model 15 | soulcoder-dao 16 | 17 | pom 18 | 19 | soulcoder 20 | soulcoder project for Spring Boot 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-parent 25 | 2.0.2.RELEASE 26 | 27 | 28 | 29 | 30 | 4.12 31 | 1.0.29 32 | 1.2.3 33 | 1.7.7 34 | 3.1.0 35 | 1.5.7.RELEASE 36 | 1.2.28 37 | 5.0.0 38 | 3.4 39 | 40 | 4.4.1 41 | 4.1 42 | 43 | 4.0.3 44 | UTF-8 45 | UTF-8 46 | 1.8 47 | 48 | 49 | 50 | 51 | 52 | io.netty 53 | netty-all 54 | 4.1.25.Final 55 | 56 | 57 | 58 | org.mybatis.generator 59 | mybatis-generator-core 60 | 1.3.7 61 | 62 | 63 | 64 | org.mybatis.spring.boot 65 | mybatis-spring-boot-starter 66 | 1.3.2 67 | 68 | 69 | mysql 70 | mysql-connector-java 71 | runtime 72 | 73 | 74 | 75 | com.github.pagehelper 76 | pagehelper 77 | 5.1.3 78 | 79 | 80 | 81 | com.alibaba 82 | druid-spring-boot-starter 83 | 1.1.0 84 | 85 | 86 | 87 | 88 | 89 | 90 | org.springframework.boot 91 | spring-boot-starter-thymeleaf 92 | 93 | 94 | org.springframework.boot 95 | spring-boot-starter-web 96 | 97 | 98 | org.springframework.boot 99 | spring-boot-starter-data-redis 100 | 101 | 102 | org.springframework.boot 103 | spring-boot-starter-actuator 104 | 105 | 106 | org.springframework.boot 107 | spring-boot-starter-aop 108 | 109 | 110 | org.springframework.boot 111 | spring-boot-starter-logging 112 | 113 | 114 | org.projectlombok 115 | lombok 116 | true 117 | 118 | 119 | org.springframework.boot 120 | spring-boot-starter-test 121 | test 122 | 123 | 124 | javax.servlet 125 | javax.servlet-api 126 | ${servlet.version} 127 | 128 | 129 | junit 130 | junit 131 | ${junit.version} 132 | 133 | 134 | org.slf4j 135 | slf4j-api 136 | ${slf4j.version} 137 | 138 | 139 | ch.qos.logback 140 | logback-access 141 | ${logback.version} 142 | 143 | 144 | ch.qos.logback 145 | logback-core 146 | ${logback.version} 147 | 148 | 149 | ch.qos.logback 150 | logback-classic 151 | ${logback.version} 152 | 153 | 154 | com.alibaba 155 | fastjson 156 | ${fastjson.version} 157 | 158 | 159 | org.apache.commons 160 | commons-lang3 161 | ${common.version} 162 | 163 | 164 | org.apache.httpcomponents 165 | httpclient 166 | ${httpclient.version} 167 | 168 | 169 | org.apache.httpcomponents 170 | httpmime 171 | ${httpclient.version} 172 | 173 | 174 | org.apache.httpcomponents 175 | httpasyncclient 176 | ${httpasyncclient.version} 177 | 178 | 179 | cn.hutool 180 | hutool-all 181 | ${hutool-all.version} 182 | 183 | 184 | com.google.code.gson 185 | gson 186 | 2.8.4 187 | 188 | 189 | 190 | org.apache.poi 191 | poi 192 | 3.15 193 | 194 | 195 | 196 | org.apache.poi 197 | poi-ooxml 198 | 3.15 199 | 200 | 201 | io.springfox 202 | springfox-swagger2 203 | 2.2.2 204 | 205 | 206 | io.springfox 207 | springfox-swagger-ui 208 | 2.2.2 209 | 210 | 211 | 212 | 213 | 214 | 215 | org.springframework.boot 216 | spring-boot-maven-plugin 217 | 1.3.0.RELEASE 218 | 219 | tech.soulcoder.StartApplication 220 | ZIP 221 | 222 | 223 | 224 | 225 | repackage 226 | 227 | 228 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | -------------------------------------------------------------------------------- /s.sh: -------------------------------------------------------------------------------- 1 | # git 拉去最新分支代码 2 | git pull 3 | git branch zzb 4 | # 拷贝配置文件到指定目录 5 | cp /www/wwwroot/zzb.soulcoder.tech/application.yml /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/src/main/resources/application.yml 6 | cp /www/wwwroot/zzb.soulcoder.tech/application-prod.yml /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/src/main/resources/application-prod.yml 7 | mvn clean 8 | mvn package -Dmaven.test.skip=true 9 | # 启动 10 | cd /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/target/ 11 | nohup java -jar -Xms258m -Xmx258m soulcoder.jar & 12 | 13 | 14 | -------------------------------------------------------------------------------- /soulcoder-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | soulcoder 7 | tech.soulcoder 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | soulcoder-core 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /soulcoder-core/src/main/java/tech/soulcoder/core/Swagger2Config.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.core; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import springfox.documentation.builders.ApiInfoBuilder; 8 | import springfox.documentation.builders.PathSelectors; 9 | import springfox.documentation.builders.RequestHandlerSelectors; 10 | import springfox.documentation.service.ApiInfo; 11 | import springfox.documentation.spi.DocumentationType; 12 | import springfox.documentation.spring.web.plugins.Docket; 13 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 14 | 15 | @Configuration 16 | @EnableWebMvc 17 | @EnableSwagger2 18 | @ComponentScan(basePackages = {"tech.soulcoder.**"}) 19 | public class Swagger2Config { 20 | 21 | @Bean 22 | public Docket createRestApi() { 23 | return new Docket(DocumentationType.SWAGGER_2) 24 | .apiInfo(apiInfo()) 25 | .select() 26 | .apis(RequestHandlerSelectors.basePackage("tech.soulcoder")) 27 | .paths(PathSelectors.any()) 28 | .build(); 29 | } 30 | 31 | private ApiInfo apiInfo() { 32 | return new ApiInfoBuilder() 33 | .title("soulcoder APIs") 34 | .description("官网 www.soulcoder.tech") 35 | .termsOfServiceUrl("www.soulcoder.tech") 36 | .version("1.0") 37 | .build(); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /soulcoder-core/src/main/java/tech/soulcoder/core/WebMVCConfig.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.core; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 7 | 8 | 9 | /** 10 | * @author yunfeng.lu 11 | * @create 2017/11/7. 12 | */ 13 | @Configuration 14 | public class WebMVCConfig implements WebMvcConfigurer { 15 | /** 16 | * 配置swagger 映射路径 17 | * @param registry 18 | */ 19 | @Override 20 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 21 | registry.addResourceHandler("swagger-ui.html") 22 | .addResourceLocations("classpath:/META-INF/resources/"); 23 | registry.addResourceHandler("/webjars/**") 24 | .addResourceLocations("classpath:/META-INF/resources/webjars/"); 25 | 26 | } 27 | 28 | /** 29 | * 跨域处理 30 | * @param registry 31 | */ 32 | @Override 33 | public void addCorsMappings(CorsRegistry registry) { 34 | registry.addMapping("/**"); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /soulcoder-core/src/main/java/tech/soulcoder/core/dbconfig/DruidConfigSoul.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.core.dbconfig; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import com.alibaba.druid.pool.DruidDataSource; 8 | import javax.sql.DataSource; 9 | import java.sql.SQLException; 10 | 11 | /** 12 | * @author yunfeng.lu 13 | * @date 2018年06月11日16:19:32 14 | */ 15 | @Data 16 | @Configuration 17 | @ConfigurationProperties(prefix = "spring.datasource.soul") 18 | public class DruidConfigSoul { 19 | public String onoff; 20 | public String url; 21 | public String username; 22 | public String password; 23 | public int initialSize; 24 | public int maxActive; 25 | public int minIdle; 26 | public long maxWait; 27 | public long timeBetweenEvictionRunsMillis; 28 | public long minEvictableIdleTimeMillis; 29 | public boolean poolPreparedStatements; 30 | public int maxPoolPreparedStatementPerConnectionSize; 31 | public String filters; 32 | public String connectionProperties; 33 | 34 | @Bean(name="druidDataSourceSoul") 35 | public DataSource druidDataSourceSoul() { 36 | DruidDataSource druidDataSource = new DruidDataSource(); 37 | druidDataSource.setUrl(url); 38 | druidDataSource.setUsername(username); 39 | druidDataSource.setPassword(password); 40 | druidDataSource.setInitialSize(initialSize); 41 | druidDataSource.setMaxActive(maxActive); 42 | druidDataSource.setMinIdle(minIdle); 43 | druidDataSource.setMaxWait(maxWait); 44 | druidDataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); 45 | druidDataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); 46 | druidDataSource.setPoolPreparedStatements(poolPreparedStatements); 47 | druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize); 48 | druidDataSource.setConnectionProperties(connectionProperties); 49 | try { 50 | druidDataSource.setFilters("stat,slf4j"); 51 | } catch (SQLException e) { 52 | e.printStackTrace(); 53 | } 54 | try { 55 | druidDataSource.setFilters(filters); 56 | druidDataSource.init(); 57 | } catch (SQLException e) { 58 | e.printStackTrace(); 59 | } 60 | return druidDataSource; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /soulcoder-core/src/main/java/tech/soulcoder/core/dbconfig/DruidServletConfig.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.core.dbconfig; 2 | import com.alibaba.druid.support.http.StatViewServlet; 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.core.annotation.Order; 7 | /** 8 | * @author yunfeng.lu 9 | * @create 2017/12/28. 10 | */ 11 | @Configuration 12 | public class DruidServletConfig { 13 | @Bean 14 | @Order 15 | public ServletRegistrationBean statViewServlet() { 16 | StatViewServlet servlet = new StatViewServlet(); 17 | ServletRegistrationBean bean = new ServletRegistrationBean(servlet, "/druid/*"); 18 | bean.addInitParameter("loginUsername", "lucode"); 19 | bean.addInitParameter("loginPassword", "lucode123"); 20 | return bean; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /soulcoder-core/src/main/java/tech/soulcoder/core/dbconfig/MyBatisConfigSoul.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.core.dbconfig; 2 | import com.github.pagehelper.PageInterceptor; 3 | import org.apache.ibatis.plugin.Interceptor; 4 | import org.apache.ibatis.session.SqlSessionFactory; 5 | import org.mybatis.spring.SqlSessionFactoryBean; 6 | import org.mybatis.spring.SqlSessionTemplate; 7 | import org.mybatis.spring.annotation.MapperScan; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.beans.factory.annotation.Qualifier; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 13 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 14 | 15 | import javax.sql.DataSource; 16 | /** 17 | * @author yunfeng.lu 18 | * @create 2017/12/28. 19 | */ 20 | @MapperScan(basePackages = "tech.soulcoder.dao", 21 | sqlSessionFactoryRef = "sqlSessionFactorySoul", 22 | sqlSessionTemplateRef = "sqlSessionTemplateSoul") 23 | @Configuration 24 | public class MyBatisConfigSoul { 25 | /// 如果不集成 德鲁伊数据库连接池,需要使用普通的数据源,也在这里配置 26 | // @Autowired 27 | // @Qualifier("Soul") 28 | // private DataSource dataSourceSoul; 29 | 30 | /** 31 | * 德鲁伊数据源 32 | */ 33 | private final DataSource druidDataSourceSoul; 34 | 35 | private final PageInterceptor pageHelper; 36 | 37 | @Autowired 38 | public MyBatisConfigSoul(@Qualifier("druidDataSourceSoul") DataSource druidDataSourceSoul, PageInterceptor pageHelper) { 39 | this.druidDataSourceSoul = druidDataSourceSoul; 40 | this.pageHelper = pageHelper; 41 | } 42 | 43 | @Bean("sqlSessionFactorySoul") 44 | public SqlSessionFactory sqlSessionFactorySoul() throws Exception { 45 | 46 | SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); 47 | sqlSessionFactoryBean.setDataSource(druidDataSourceSoul); 48 | sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper}); 49 | PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); 50 | sqlSessionFactoryBean.setMapperLocations( 51 | resolver.getResources("classpath*:mapper/**/*.xml")); 52 | 53 | SqlSessionFactory sqlSessionFactory = null; 54 | try { 55 | sqlSessionFactory = sqlSessionFactoryBean.getObject(); 56 | } catch (Exception e) { 57 | e.printStackTrace(); 58 | System.exit(0); 59 | } 60 | org.apache.ibatis.session.Configuration configuration = sqlSessionFactory.getConfiguration(); 61 | configuration.setMapUnderscoreToCamelCase(true); 62 | return sqlSessionFactoryBean.getObject(); 63 | } 64 | 65 | @Bean("soulTransaction") 66 | public DataSourceTransactionManager transactionManager() throws Exception { 67 | return new DataSourceTransactionManager(druidDataSourceSoul); 68 | } 69 | @Bean 70 | public SqlSessionTemplate sqlSessionTemplateSoul() throws Exception { 71 | return new SqlSessionTemplate(sqlSessionFactorySoul()); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /soulcoder-core/src/main/java/tech/soulcoder/core/dbconfig/MybatisPageHelperConfig.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.core.dbconfig; 2 | 3 | import com.github.pagehelper.PageInterceptor; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import java.util.Properties; 8 | 9 | /** 10 | * 分页 11 | * @author yunfeng.lu 12 | */ 13 | @Configuration 14 | public class MybatisPageHelperConfig { 15 | @Bean 16 | public PageInterceptor pageHelper() { 17 | PageInterceptor pageHelper = new PageInterceptor(); 18 | Properties p = new Properties(); 19 | p.setProperty("offsetAsPageNum", "true"); 20 | p.setProperty("rowBoundsWithCount", "true"); 21 | p.setProperty("reasonable", "true"); 22 | pageHelper.setProperties(p); 23 | return pageHelper; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /soulcoder-dao/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | soulcoder 7 | tech.soulcoder 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | soulcoder-dao 13 | 14 | 15 | -------------------------------------------------------------------------------- /soulcoder-dao/src/main/java/tech/soulcoder/dao/mapper/generator/SoulUserDTOMapper.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.dao.mapper.generator; 2 | 3 | import java.util.List; 4 | import org.apache.ibatis.annotations.Param; 5 | import tech.soulcoder.dao.pojo.generator.SoulUserDTO; 6 | import tech.soulcoder.dao.pojo.generator.SoulUserDTOExample; 7 | 8 | public interface SoulUserDTOMapper { 9 | long countByExample(SoulUserDTOExample example); 10 | 11 | int deleteByExample(SoulUserDTOExample example); 12 | 13 | int deleteByPrimaryKey(String id); 14 | 15 | int insert(SoulUserDTO record); 16 | 17 | int insertSelective(SoulUserDTO record); 18 | 19 | List selectByExample(SoulUserDTOExample example); 20 | 21 | SoulUserDTO selectByPrimaryKey(String id); 22 | 23 | int updateByExampleSelective(@Param("record") SoulUserDTO record, @Param("example") SoulUserDTOExample example); 24 | 25 | int updateByExample(@Param("record") SoulUserDTO record, @Param("example") SoulUserDTOExample example); 26 | 27 | int updateByPrimaryKeySelective(SoulUserDTO record); 28 | 29 | int updateByPrimaryKey(SoulUserDTO record); 30 | } -------------------------------------------------------------------------------- /soulcoder-dao/src/main/java/tech/soulcoder/dao/mapper/generator/SoulUserMapper.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.dao.mapper.generator; 2 | 3 | import tech.soulcoder.dao.pojo.generator.SoulUser; 4 | 5 | public interface SoulUserMapper { 6 | /** 7 | * This method was generated by MyBatis Generator. 8 | * This method corresponds to the database table soul_user 9 | * 10 | * @mbg.generated 11 | */ 12 | int deleteByPrimaryKey(String id); 13 | 14 | /** 15 | * This method was generated by MyBatis Generator. 16 | * This method corresponds to the database table soul_user 17 | * 18 | * @mbg.generated 19 | */ 20 | int insert(SoulUser record); 21 | 22 | /** 23 | * This method was generated by MyBatis Generator. 24 | * This method corresponds to the database table soul_user 25 | * 26 | * @mbg.generated 27 | */ 28 | int insertSelective(SoulUser record); 29 | 30 | /** 31 | * This method was generated by MyBatis Generator. 32 | * This method corresponds to the database table soul_user 33 | * 34 | * @mbg.generated 35 | */ 36 | SoulUser selectByPrimaryKey(String id); 37 | 38 | /** 39 | * This method was generated by MyBatis Generator. 40 | * This method corresponds to the database table soul_user 41 | * 42 | * @mbg.generated 43 | */ 44 | int updateByPrimaryKeySelective(SoulUser record); 45 | 46 | /** 47 | * This method was generated by MyBatis Generator. 48 | * This method corresponds to the database table soul_user 49 | * 50 | * @mbg.generated 51 | */ 52 | int updateByPrimaryKey(SoulUser record); 53 | } -------------------------------------------------------------------------------- /soulcoder-dao/src/main/java/tech/soulcoder/dao/pojo/generator/SoulUser.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.dao.pojo.generator; 2 | 3 | /** 4 | * 5 | * This class was generated by MyBatis Generator. 6 | * This class corresponds to the database table soul_user 7 | * 8 | * @mbg.generated do_not_delete_during_merge 9 | */ 10 | public class SoulUser { 11 | /** 12 | * 13 | * This field was generated by MyBatis Generator. 14 | * This field corresponds to the database column soul_user.id 15 | * 16 | * @mbg.generated 17 | */ 18 | private String id; 19 | 20 | /** 21 | * 22 | * This field was generated by MyBatis Generator. 23 | * This field corresponds to the database column soul_user.pwd 24 | * 25 | * @mbg.generated 26 | */ 27 | private String pwd; 28 | 29 | /** 30 | * This method was generated by MyBatis Generator. 31 | * This method returns the value of the database column soul_user.id 32 | * 33 | * @return the value of soul_user.id 34 | * 35 | * @mbg.generated 36 | */ 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | /** 42 | * This method was generated by MyBatis Generator. 43 | * This method sets the value of the database column soul_user.id 44 | * 45 | * @param id the value for soul_user.id 46 | * 47 | * @mbg.generated 48 | */ 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | /** 54 | * This method was generated by MyBatis Generator. 55 | * This method returns the value of the database column soul_user.pwd 56 | * 57 | * @return the value of soul_user.pwd 58 | * 59 | * @mbg.generated 60 | */ 61 | public String getPwd() { 62 | return pwd; 63 | } 64 | 65 | /** 66 | * This method was generated by MyBatis Generator. 67 | * This method sets the value of the database column soul_user.pwd 68 | * 69 | * @param pwd the value for soul_user.pwd 70 | * 71 | * @mbg.generated 72 | */ 73 | public void setPwd(String pwd) { 74 | this.pwd = pwd; 75 | } 76 | } -------------------------------------------------------------------------------- /soulcoder-dao/src/main/java/tech/soulcoder/dao/pojo/generator/SoulUserDTO.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.dao.pojo.generator; 2 | 3 | import java.io.Serializable; 4 | 5 | public class SoulUserDTO implements Serializable { 6 | private String id; 7 | 8 | private String pwd; 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | public String getId() { 13 | return id; 14 | } 15 | 16 | public void setId(String id) { 17 | this.id = id == null ? null : id.trim(); 18 | } 19 | 20 | public String getPwd() { 21 | return pwd; 22 | } 23 | 24 | public void setPwd(String pwd) { 25 | this.pwd = pwd == null ? null : pwd.trim(); 26 | } 27 | } -------------------------------------------------------------------------------- /soulcoder-dao/src/main/java/tech/soulcoder/dao/pojo/generator/SoulUserDTOExample.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.dao.pojo.generator; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class SoulUserDTOExample { 7 | protected String orderByClause; 8 | 9 | protected boolean distinct; 10 | 11 | protected List oredCriteria; 12 | 13 | public SoulUserDTOExample() { 14 | oredCriteria = new ArrayList(); 15 | } 16 | 17 | public void setOrderByClause(String orderByClause) { 18 | this.orderByClause = orderByClause; 19 | } 20 | 21 | public String getOrderByClause() { 22 | return orderByClause; 23 | } 24 | 25 | public void setDistinct(boolean distinct) { 26 | this.distinct = distinct; 27 | } 28 | 29 | public boolean isDistinct() { 30 | return distinct; 31 | } 32 | 33 | public List getOredCriteria() { 34 | return oredCriteria; 35 | } 36 | 37 | public void or(Criteria criteria) { 38 | oredCriteria.add(criteria); 39 | } 40 | 41 | public Criteria or() { 42 | Criteria criteria = createCriteriaInternal(); 43 | oredCriteria.add(criteria); 44 | return criteria; 45 | } 46 | 47 | public Criteria createCriteria() { 48 | Criteria criteria = createCriteriaInternal(); 49 | if (oredCriteria.size() == 0) { 50 | oredCriteria.add(criteria); 51 | } 52 | return criteria; 53 | } 54 | 55 | protected Criteria createCriteriaInternal() { 56 | Criteria criteria = new Criteria(); 57 | return criteria; 58 | } 59 | 60 | public void clear() { 61 | oredCriteria.clear(); 62 | orderByClause = null; 63 | distinct = false; 64 | } 65 | 66 | protected abstract static class GeneratedCriteria { 67 | protected List criteria; 68 | 69 | protected GeneratedCriteria() { 70 | super(); 71 | criteria = new ArrayList(); 72 | } 73 | 74 | public boolean isValid() { 75 | return criteria.size() > 0; 76 | } 77 | 78 | public List getAllCriteria() { 79 | return criteria; 80 | } 81 | 82 | public List getCriteria() { 83 | return criteria; 84 | } 85 | 86 | protected void addCriterion(String condition) { 87 | if (condition == null) { 88 | throw new RuntimeException("Value for condition cannot be null"); 89 | } 90 | criteria.add(new Criterion(condition)); 91 | } 92 | 93 | protected void addCriterion(String condition, Object value, String property) { 94 | if (value == null) { 95 | throw new RuntimeException("Value for " + property + " cannot be null"); 96 | } 97 | criteria.add(new Criterion(condition, value)); 98 | } 99 | 100 | protected void addCriterion(String condition, Object value1, Object value2, String property) { 101 | if (value1 == null || value2 == null) { 102 | throw new RuntimeException("Between values for " + property + " cannot be null"); 103 | } 104 | criteria.add(new Criterion(condition, value1, value2)); 105 | } 106 | 107 | public Criteria andIdIsNull() { 108 | addCriterion("id is null"); 109 | return (Criteria) this; 110 | } 111 | 112 | public Criteria andIdIsNotNull() { 113 | addCriterion("id is not null"); 114 | return (Criteria) this; 115 | } 116 | 117 | public Criteria andIdEqualTo(String value) { 118 | addCriterion("id =", value, "id"); 119 | return (Criteria) this; 120 | } 121 | 122 | public Criteria andIdNotEqualTo(String value) { 123 | addCriterion("id <>", value, "id"); 124 | return (Criteria) this; 125 | } 126 | 127 | public Criteria andIdGreaterThan(String value) { 128 | addCriterion("id >", value, "id"); 129 | return (Criteria) this; 130 | } 131 | 132 | public Criteria andIdGreaterThanOrEqualTo(String value) { 133 | addCriterion("id >=", value, "id"); 134 | return (Criteria) this; 135 | } 136 | 137 | public Criteria andIdLessThan(String value) { 138 | addCriterion("id <", value, "id"); 139 | return (Criteria) this; 140 | } 141 | 142 | public Criteria andIdLessThanOrEqualTo(String value) { 143 | addCriterion("id <=", value, "id"); 144 | return (Criteria) this; 145 | } 146 | 147 | public Criteria andIdLike(String value) { 148 | addCriterion("id like", value, "id"); 149 | return (Criteria) this; 150 | } 151 | 152 | public Criteria andIdNotLike(String value) { 153 | addCriterion("id not like", value, "id"); 154 | return (Criteria) this; 155 | } 156 | 157 | public Criteria andIdIn(List values) { 158 | addCriterion("id in", values, "id"); 159 | return (Criteria) this; 160 | } 161 | 162 | public Criteria andIdNotIn(List values) { 163 | addCriterion("id not in", values, "id"); 164 | return (Criteria) this; 165 | } 166 | 167 | public Criteria andIdBetween(String value1, String value2) { 168 | addCriterion("id between", value1, value2, "id"); 169 | return (Criteria) this; 170 | } 171 | 172 | public Criteria andIdNotBetween(String value1, String value2) { 173 | addCriterion("id not between", value1, value2, "id"); 174 | return (Criteria) this; 175 | } 176 | 177 | public Criteria andPwdIsNull() { 178 | addCriterion("pwd is null"); 179 | return (Criteria) this; 180 | } 181 | 182 | public Criteria andPwdIsNotNull() { 183 | addCriterion("pwd is not null"); 184 | return (Criteria) this; 185 | } 186 | 187 | public Criteria andPwdEqualTo(String value) { 188 | addCriterion("pwd =", value, "pwd"); 189 | return (Criteria) this; 190 | } 191 | 192 | public Criteria andPwdNotEqualTo(String value) { 193 | addCriterion("pwd <>", value, "pwd"); 194 | return (Criteria) this; 195 | } 196 | 197 | public Criteria andPwdGreaterThan(String value) { 198 | addCriterion("pwd >", value, "pwd"); 199 | return (Criteria) this; 200 | } 201 | 202 | public Criteria andPwdGreaterThanOrEqualTo(String value) { 203 | addCriterion("pwd >=", value, "pwd"); 204 | return (Criteria) this; 205 | } 206 | 207 | public Criteria andPwdLessThan(String value) { 208 | addCriterion("pwd <", value, "pwd"); 209 | return (Criteria) this; 210 | } 211 | 212 | public Criteria andPwdLessThanOrEqualTo(String value) { 213 | addCriterion("pwd <=", value, "pwd"); 214 | return (Criteria) this; 215 | } 216 | 217 | public Criteria andPwdLike(String value) { 218 | addCriterion("pwd like", value, "pwd"); 219 | return (Criteria) this; 220 | } 221 | 222 | public Criteria andPwdNotLike(String value) { 223 | addCriterion("pwd not like", value, "pwd"); 224 | return (Criteria) this; 225 | } 226 | 227 | public Criteria andPwdIn(List values) { 228 | addCriterion("pwd in", values, "pwd"); 229 | return (Criteria) this; 230 | } 231 | 232 | public Criteria andPwdNotIn(List values) { 233 | addCriterion("pwd not in", values, "pwd"); 234 | return (Criteria) this; 235 | } 236 | 237 | public Criteria andPwdBetween(String value1, String value2) { 238 | addCriterion("pwd between", value1, value2, "pwd"); 239 | return (Criteria) this; 240 | } 241 | 242 | public Criteria andPwdNotBetween(String value1, String value2) { 243 | addCriterion("pwd not between", value1, value2, "pwd"); 244 | return (Criteria) this; 245 | } 246 | } 247 | 248 | public static class Criteria extends GeneratedCriteria { 249 | 250 | protected Criteria() { 251 | super(); 252 | } 253 | } 254 | 255 | public static class Criterion { 256 | private String condition; 257 | 258 | private Object value; 259 | 260 | private Object secondValue; 261 | 262 | private boolean noValue; 263 | 264 | private boolean singleValue; 265 | 266 | private boolean betweenValue; 267 | 268 | private boolean listValue; 269 | 270 | private String typeHandler; 271 | 272 | public String getCondition() { 273 | return condition; 274 | } 275 | 276 | public Object getValue() { 277 | return value; 278 | } 279 | 280 | public Object getSecondValue() { 281 | return secondValue; 282 | } 283 | 284 | public boolean isNoValue() { 285 | return noValue; 286 | } 287 | 288 | public boolean isSingleValue() { 289 | return singleValue; 290 | } 291 | 292 | public boolean isBetweenValue() { 293 | return betweenValue; 294 | } 295 | 296 | public boolean isListValue() { 297 | return listValue; 298 | } 299 | 300 | public String getTypeHandler() { 301 | return typeHandler; 302 | } 303 | 304 | protected Criterion(String condition) { 305 | super(); 306 | this.condition = condition; 307 | this.typeHandler = null; 308 | this.noValue = true; 309 | } 310 | 311 | protected Criterion(String condition, Object value, String typeHandler) { 312 | super(); 313 | this.condition = condition; 314 | this.value = value; 315 | this.typeHandler = typeHandler; 316 | if (value instanceof List) { 317 | this.listValue = true; 318 | } else { 319 | this.singleValue = true; 320 | } 321 | } 322 | 323 | protected Criterion(String condition, Object value) { 324 | this(condition, value, null); 325 | } 326 | 327 | protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { 328 | super(); 329 | this.condition = condition; 330 | this.value = value; 331 | this.secondValue = secondValue; 332 | this.typeHandler = typeHandler; 333 | this.betweenValue = true; 334 | } 335 | 336 | protected Criterion(String condition, Object value, Object secondValue) { 337 | this(condition, value, secondValue, null); 338 | } 339 | } 340 | } -------------------------------------------------------------------------------- /soulcoder-dao/src/main/resources/mapper/generator/SoulUserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 11 | 12 | 13 | 17 | id, pwd 18 | 19 | 29 | 30 | 34 | delete from soul_user 35 | where id = #{id,jdbcType=VARCHAR} 36 | 37 | 38 | 42 | insert into soul_user (id, pwd) 43 | values (#{id,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR}) 44 | 45 | 46 | 50 | insert into soul_user 51 | 52 | 53 | id, 54 | 55 | 56 | pwd, 57 | 58 | 59 | 60 | 61 | #{id,jdbcType=VARCHAR}, 62 | 63 | 64 | #{pwd,jdbcType=VARCHAR}, 65 | 66 | 67 | 68 | 69 | 73 | update soul_user 74 | 75 | 76 | pwd = #{pwd,jdbcType=VARCHAR}, 77 | 78 | 79 | where id = #{id,jdbcType=VARCHAR} 80 | 81 | 82 | 86 | update soul_user 87 | set pwd = #{pwd,jdbcType=VARCHAR} 88 | where id = #{id,jdbcType=VARCHAR} 89 | 90 | -------------------------------------------------------------------------------- /soulcoder-dao/src/main/resources/tech/soulcoder/dao/mapper/generator/SoulUserDTOMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | and ${criterion.condition} 17 | 18 | 19 | and ${criterion.condition} #{criterion.value} 20 | 21 | 22 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 23 | 24 | 25 | and ${criterion.condition} 26 | 27 | #{listItem} 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | and ${criterion.condition} 46 | 47 | 48 | and ${criterion.condition} #{criterion.value} 49 | 50 | 51 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} 52 | 53 | 54 | and ${criterion.condition} 55 | 56 | #{listItem} 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | id, pwd 68 | 69 | 83 | 89 | 90 | delete from soul_user 91 | where id = #{id,jdbcType=VARCHAR} 92 | 93 | 94 | delete from soul_user 95 | 96 | 97 | 98 | 99 | 100 | insert into soul_user (id, pwd) 101 | values (#{id,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR}) 102 | 103 | 104 | insert into soul_user 105 | 106 | 107 | id, 108 | 109 | 110 | pwd, 111 | 112 | 113 | 114 | 115 | #{id,jdbcType=VARCHAR}, 116 | 117 | 118 | #{pwd,jdbcType=VARCHAR}, 119 | 120 | 121 | 122 | 128 | 129 | update soul_user 130 | 131 | 132 | id = #{record.id,jdbcType=VARCHAR}, 133 | 134 | 135 | pwd = #{record.pwd,jdbcType=VARCHAR}, 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | update soul_user 144 | set id = #{record.id,jdbcType=VARCHAR}, 145 | pwd = #{record.pwd,jdbcType=VARCHAR} 146 | 147 | 148 | 149 | 150 | 151 | update soul_user 152 | 153 | 154 | pwd = #{pwd,jdbcType=VARCHAR}, 155 | 156 | 157 | where id = #{id,jdbcType=VARCHAR} 158 | 159 | 160 | update soul_user 161 | set pwd = #{pwd,jdbcType=VARCHAR} 162 | where id = #{id,jdbcType=VARCHAR} 163 | 164 | -------------------------------------------------------------------------------- /soulcoder-dao/src/test/java/tech/soulcoder/test/GeneratorMain.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.test; 2 | 3 | import org.mybatis.generator.api.ShellRunner; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | 8 | /** 9 | * GeneratorMain.class 10 | * 11 | * @author yunfeng.lu 12 | * @date 2018/7/9 13 | */ 14 | public class GeneratorMain { 15 | // 本地 mysql jar包的路径 一般在你的 maven仓库里面找 16 | public static String mysqlJarPath = "/Applications/dev/maven_conf/repository/mysql/mysql-connector-java/5.1.29/mysql-connector-java-5.1.29.jar"; 17 | // 这个只要放 相对路径就可以了 18 | public static String mapperXmlPath = "/soulcoder-dao/src/main/resources/tech/soulcoder/dao/mapper/generator"; 19 | public static void main(String[] args) { 20 | args = new String[3]; 21 | args[0] = "-configfile"; 22 | GeneratorMain.class.getResource("/"); 23 | String configRootPath = GeneratorMain.class.getResource("/").getPath(); 24 | args[1] = configRootPath + "generator.xml"; 25 | args[2] = "-overwrite"; 26 | deleteXmlFiles(); 27 | System.getProperties().put("mysql.driver.path",mysqlJarPath); 28 | ShellRunner.main(args); 29 | } 30 | 31 | // 删除原来的 文件 生成最新的 32 | public static void deleteXmlFiles() { 33 | try { 34 | File directory = new File(""); 35 | String str = directory.getCanonicalPath() + mapperXmlPath; 36 | File file = new File(str); 37 | if (file.isDirectory() && null != file.listFiles() && file.listFiles().length > 0) { 38 | for (File f : file.listFiles()) { 39 | f.delete(); 40 | } 41 | } 42 | } catch (IOException e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /soulcoder-dao/src/test/resources/generator.properties.exmple: -------------------------------------------------------------------------------- 1 | classPath=/Applications/dev/maven_conf/repository/mysql/mysql-connector-java/5.1.29/mysql-connector-java-5.1.29.jar 2 | jdbc_driver=com.mysql.jdbc.Driver 3 | jdbc_url=jdbc:mysql://127.0.0.1:3306/soulcoder?autoReconnect=true&useCompression=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true 4 | jdbc_user=root 5 | jdbc_password= -------------------------------------------------------------------------------- /soulcoder-dao/src/test/resources/generator.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 35 | 36 | 37 | 38 | 40 | 41 | 42 | 43 | 51 | 52 | 53 |
54 | 55 |
56 | 57 |
58 | 59 | -------------------------------------------------------------------------------- /soulcoder-model/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | soulcoder 7 | tech.soulcoder 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | soulcoder-model 13 | 14 | 15 | -------------------------------------------------------------------------------- /soulcoder-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | soulcoder 7 | tech.soulcoder 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | soulcoder-service 13 | 14 | 15 | 16 | tech.soulcoder 17 | soulcoder-dao 18 | 0.0.1-SNAPSHOT 19 | 20 | 21 | tech.soulcoder 22 | soulcoder-model 23 | 0.0.1-SNAPSHOT 24 | compile 25 | 26 | 27 | tech.soulcoder 28 | soulcoder-utils 29 | 0.0.1-SNAPSHOT 30 | compile 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /soulcoder-service/src/main/java/tech/soulcoder/service/TestService.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.service; 2 | 3 | 4 | import java.util.Map; 5 | 6 | public interface TestService { 7 | 8 | Map testDB(); 9 | } 10 | -------------------------------------------------------------------------------- /soulcoder-service/src/main/java/tech/soulcoder/service/impl/TestServiceImpl.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.service.impl; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import tech.soulcoder.RedisOperation; 7 | import tech.soulcoder.dao.mapper.generator.SoulUserMapper; 8 | import tech.soulcoder.log.LogAuto; 9 | import tech.soulcoder.service.TestService; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | @Service 15 | public class TestServiceImpl implements TestService { 16 | 17 | private final SoulUserMapper soulUserMapper; 18 | 19 | private final RedisOperation redisOperation; 20 | 21 | @Autowired 22 | public TestServiceImpl(RedisOperation redisOperation, SoulUserMapper soulUserMapper) { 23 | this.redisOperation = redisOperation; 24 | this.soulUserMapper = soulUserMapper; 25 | } 26 | 27 | @Override 28 | @LogAuto 29 | public Map testDB() { 30 | redisOperation.setValue("haha","lalal"); 31 | System.out.println(redisOperation.getValue("haha")); 32 | 33 | Map res=new HashMap<>(); 34 | res.put("res",JSON.toJSONString(soulUserMapper.selectByPrimaryKey("1"))); 35 | return res; 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /soulcoder-service/src/test/java/tech/soulcoder/test/MyTest.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.test; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import tech.soulcoder.service.TestService; 9 | 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class MyTest { 13 | 14 | @Autowired 15 | private TestService testService; 16 | 17 | @Test 18 | public void test(){ 19 | System.out.println(testService.testDB()); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /soulcoder-utils/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | soulcoder 7 | tech.soulcoder 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | soulcoder-utils 13 | 14 | 15 | tech.soulcoder 16 | soulcoder-model 17 | 0.0.1-SNAPSHOT 18 | compile 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/IPUtils.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | public class IPUtils { 6 | public static String getIpAddress(HttpServletRequest request) { 7 | String ip = request.getHeader("x-forwarded-for"); 8 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 9 | ip = request.getHeader("Proxy-Client-IP"); 10 | } 11 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 12 | ip = request.getHeader("WL-Proxy-Client-IP"); 13 | } 14 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 15 | ip = request.getHeader("HTTP_CLIENT_IP"); 16 | } 17 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 18 | ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 19 | } 20 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 21 | ip = request.getRemoteAddr(); 22 | } 23 | return ip; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/RedisOperation.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.dao.DataAccessException; 5 | import org.springframework.data.redis.connection.RedisConnection; 6 | import org.springframework.data.redis.core.RedisCallback; 7 | import org.springframework.data.redis.core.StringRedisTemplate; 8 | import org.springframework.data.redis.core.TimeoutUtils; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | import java.util.Map; 13 | import java.util.Set; 14 | import java.util.concurrent.TimeUnit; 15 | 16 | @Service 17 | public class RedisOperation { 18 | private static final long DEFAULT_REDIS_KEYS_TIMEOUT = 60*60*24*7; 19 | @Autowired 20 | private StringRedisTemplate stringRedisTemplate; 21 | 22 | /** 23 | * 字符串操作 24 | * @param key 25 | * @param value 26 | */ 27 | 28 | public void setValue(String key, String value) { 29 | stringRedisTemplate.opsForValue().set(key, value); 30 | } 31 | 32 | 33 | public void setValue(String key, String value, Long timeout,TimeUnit unit) { 34 | stringRedisTemplate.opsForValue().set(key, value, timeout , unit); 35 | } 36 | 37 | /** 38 | * 字符串 kv 操作 39 | * @param key 40 | * @return 41 | */ 42 | 43 | public String getValue(String key) { 44 | return stringRedisTemplate.opsForValue().get(key); 45 | } 46 | 47 | /** 48 | * Hash 值设置 49 | * @param key 50 | * @param value 51 | */ 52 | 53 | public void setHashAll(String key, Map value) { 54 | stringRedisTemplate.opsForHash().putAll(key,value); 55 | } 56 | 57 | /** 58 | * Hash 值设置,并设置超时时间 59 | * @param key 60 | * @param value 61 | * @param timeout 62 | * @param unit 63 | */ 64 | 65 | public void setHashAll(String key, Map value, Long timeout,TimeUnit unit) { 66 | stringRedisTemplate.opsForHash().putAll(key,value); 67 | stringRedisTemplate.expire(key,timeout,unit); 68 | } 69 | 70 | /** 71 | * 根据 key 获取 Hash 类型的 value 72 | * @param key 73 | * @return 74 | */ 75 | 76 | public Map getHash(String key) { 77 | return stringRedisTemplate.opsForHash().entries(key); 78 | } 79 | 80 | 81 | 82 | /** 83 | * 模糊查询 慎用!!!!! 84 | * @param prex 85 | * @return 86 | */ 87 | 88 | public List getValues(String prex) { 89 | Set keys = stringRedisTemplate.keys(prex + "*"); 90 | return stringRedisTemplate.opsForValue().multiGet(keys); 91 | } 92 | 93 | 94 | 95 | 96 | 97 | public void removeV(String key) { 98 | stringRedisTemplate.delete(key); 99 | } 100 | 101 | 102 | 103 | 104 | public void setSetValue(String key, Long timeout, String... values) { 105 | 106 | if(timeout == null) 107 | { 108 | timeout = DEFAULT_REDIS_KEYS_TIMEOUT; 109 | } 110 | 111 | stringRedisTemplate.opsForSet().add(key,values); 112 | 113 | stringRedisTemplate.expire(key,timeout, TimeUnit.SECONDS); 114 | } 115 | 116 | 117 | public Set getSetValues(String key) { 118 | return stringRedisTemplate.opsForSet().members(key); 119 | } 120 | 121 | 122 | public void setHashValue(String key, String hashKey, String hashValue) { 123 | stringRedisTemplate.opsForHash().put(key,hashKey,hashValue); 124 | } 125 | 126 | 127 | public String getHashValue(String key, String hashKey) { 128 | return String.valueOf(stringRedisTemplate.opsForHash().get(key,hashKey)); 129 | } 130 | 131 | 132 | public List mutiGetHashValue(String key, List hashKeys) { 133 | return stringRedisTemplate.opsForHash().multiGet(key,hashKeys); 134 | } 135 | 136 | 137 | public Set getHashKeys(String key) { 138 | return stringRedisTemplate.opsForHash().keys(key); 139 | } 140 | 141 | 142 | public void removeHashEntry(String key, String... hashKey) { 143 | stringRedisTemplate.opsForHash().delete(key,hashKey); 144 | } 145 | 146 | 147 | public void removeSetEntry(String setkey, String setValue) { 148 | stringRedisTemplate.opsForSet().remove(setkey,setValue); 149 | } 150 | 151 | 152 | public boolean putIfAbsent(String key, String value) 153 | { 154 | return this.stringRedisTemplate.opsForValue().setIfAbsent(key,value); 155 | } 156 | 157 | 158 | public void putRedis(byte[] paramArrayOfByte1,byte[] paramArrayOfByte2) { 159 | final byte[] paramArrayOfByte1Tmp=paramArrayOfByte1; 160 | final byte[] paramArrayOfByte2Tmp=paramArrayOfByte2; 161 | stringRedisTemplate.execute(new RedisCallback() { 162 | 163 | @Override 164 | public Object doInRedis(RedisConnection redisConnection) throws DataAccessException { 165 | redisConnection.set(paramArrayOfByte1Tmp,paramArrayOfByte2Tmp); 166 | return null; 167 | } 168 | },true); 169 | } 170 | 171 | 172 | public void putRedis( byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, long timeout,TimeUnit unit) { 173 | final byte[] paramArrayOfByte1Tmp = paramArrayOfByte1; 174 | final byte[] paramArrayOfByte2Tmp = paramArrayOfByte2; 175 | final long timeOutTmp = timeout; 176 | final TimeUnit unitTmp = unit; 177 | final long rawTimeout = TimeoutUtils.toMillis(timeout, unit); 178 | stringRedisTemplate.execute(new RedisCallback() { 179 | 180 | @Override 181 | public Object doInRedis(RedisConnection redisConnection) throws DataAccessException { 182 | redisConnection.set(paramArrayOfByte1Tmp,paramArrayOfByte2Tmp); 183 | stringRedisTemplate.execute(new RedisCallback() { 184 | 185 | public Boolean doInRedis(RedisConnection connection) { 186 | try { 187 | return connection.pExpire(paramArrayOfByte1Tmp, rawTimeout); 188 | } catch (Exception var3) { 189 | return connection.expire(paramArrayOfByte1Tmp, TimeoutUtils.toSeconds(timeOutTmp, unitTmp)); 190 | } 191 | } 192 | },true); 193 | return null; 194 | } 195 | },true); 196 | } 197 | 198 | 199 | public byte[] getRedis(byte[] paramArrayOfByte1) { 200 | final byte[] paramArrayOfByte1Tmp = paramArrayOfByte1; 201 | return (byte[]) stringRedisTemplate.execute(new RedisCallback() { 202 | 203 | public Object doInRedis(RedisConnection redisConnection) throws DataAccessException { 204 | return redisConnection.get(paramArrayOfByte1Tmp); 205 | } 206 | },true); 207 | } 208 | 209 | 210 | public void removeRedis(byte[] paramArrayOfByte) { 211 | final byte[] tmpKey = paramArrayOfByte; 212 | stringRedisTemplate.execute(new RedisCallback() { 213 | 214 | public Object doInRedis(RedisConnection connection) { 215 | connection.del(new byte[][]{tmpKey}); 216 | return null; 217 | } 218 | }, true); 219 | } 220 | 221 | 222 | public long incr(String paramString){ 223 | final String paramStringTmp = paramString; 224 | return (long)stringRedisTemplate.execute(new RedisCallback() { 225 | 226 | public Object doInRedis(RedisConnection connection) { 227 | byte[] paramBytes = stringRedisTemplate.getStringSerializer().serialize(paramStringTmp); 228 | connection.incr(paramBytes); 229 | return null; 230 | } 231 | }, true); 232 | } 233 | 234 | 235 | public long decr(String paramString){ 236 | final String paramStringTmp = paramString; 237 | return (long)stringRedisTemplate.execute(new RedisCallback() { 238 | 239 | public Object doInRedis(RedisConnection connection) { 240 | byte[] paramBytes = stringRedisTemplate.getStringSerializer().serialize(paramStringTmp); 241 | connection.decr(paramBytes); 242 | return null; 243 | } 244 | }, true); 245 | } 246 | 247 | 248 | public long incrBy(String paramString, long paramLong){ 249 | final String paramStringTmp = paramString; 250 | final long paramLongTmp = paramLong; 251 | return (long)stringRedisTemplate.execute(new RedisCallback() { 252 | 253 | public Object doInRedis(RedisConnection connection) { 254 | byte[] paramBytes = stringRedisTemplate.getStringSerializer().serialize(paramStringTmp); 255 | connection.incrBy(paramBytes,paramLongTmp); 256 | return null; 257 | } 258 | }, true); 259 | } 260 | 261 | 262 | public long decrBy(String paramString, long paramLong){ 263 | final String paramStringTmp = paramString; 264 | final long paramLongTmp = paramLong; 265 | return (long)stringRedisTemplate.execute(new RedisCallback() { 266 | 267 | public Object doInRedis(RedisConnection connection) { 268 | byte[] paramBytes = stringRedisTemplate.getStringSerializer().serialize(paramStringTmp); 269 | connection.decrBy(paramBytes,paramLongTmp); 270 | return null; 271 | } 272 | }, true); 273 | } 274 | 275 | 276 | public long incrEx(String paramString, long timeOut,TimeUnit unit){ 277 | long cnt = incr(paramString); 278 | stringRedisTemplate.expire(paramString,timeOut,unit); 279 | return cnt; 280 | } 281 | 282 | 283 | public long decrEx(String paramString, long timeOut,TimeUnit unit){ 284 | long cnt = decr(paramString); 285 | stringRedisTemplate.expire(paramString,timeOut,unit); 286 | return cnt; 287 | } 288 | 289 | 290 | public long incrByEx(String paramString, long paramLong, long timeOut,TimeUnit unit){ 291 | long cnt = incrBy(paramString,paramLong); 292 | stringRedisTemplate.expire(paramString,timeOut,unit); 293 | return cnt; 294 | } 295 | 296 | 297 | public long decrByEx(String paramString, long paramLong, long timeOut,TimeUnit unit){ 298 | long cnt = decrBy(paramString,paramLong); 299 | stringRedisTemplate.expire(paramString,timeOut,unit); 300 | return cnt; 301 | } 302 | 303 | 304 | public void setTimeout(String key,long timeout){ 305 | stringRedisTemplate.expire(key,timeout,TimeUnit.MILLISECONDS); 306 | } 307 | } 308 | 309 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/SqlHelper.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder; 2 | 3 | import org.apache.ibatis.session.SqlSession; 4 | import org.apache.ibatis.session.SqlSessionFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Qualifier; 7 | import org.springframework.stereotype.Service; 8 | import tech.soulcoder.entity.ActionWithException2; 9 | import tech.soulcoder.entity.FuncWithException2; 10 | import tech.soulcoder.entity.Optional; 11 | 12 | import java.sql.Connection; 13 | import java.sql.PreparedStatement; 14 | import java.sql.ResultSet; 15 | import java.sql.SQLException; 16 | import java.util.Date; 17 | @Service 18 | public class SqlHelper { 19 | 20 | @Autowired 21 | @Qualifier("sqlSessionFactorySoul") 22 | private SqlSessionFactory sqlSessionFactory; 23 | 24 | public SqlHelper() { 25 | } 26 | 27 | public SqlHelper(SqlSessionFactory sqlSessionFactory) { 28 | this.sqlSessionFactory = sqlSessionFactory; 29 | } 30 | 31 | public void exec(String sql, Object[] params, ActionWithException2 rowHandler) { 32 | try { 33 | try (SqlSession session = sqlSessionFactory.openSession()) { 34 | Connection conn = session.getConnection(); 35 | try (PreparedStatement cmd = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, 36 | ResultSet.CONCUR_READ_ONLY)) { 37 | 38 | if (params != null) { 39 | for (int index = 0; index < params.length; ++index) { 40 | cmd.setObject(index + 1, params[index]); 41 | } 42 | } 43 | 44 | if (rowHandler != null) { 45 | cmd.setFetchSize(Integer.MIN_VALUE); 46 | try (ResultSet resultSet = cmd.executeQuery()) { 47 | while (resultSet.next()) { 48 | rowHandler.invoke(resultSet); 49 | } 50 | } 51 | } else { 52 | cmd.execute(); 53 | } 54 | } 55 | } 56 | } catch (Exception ex) { 57 | throw new RuntimeException(ex); 58 | } 59 | } 60 | 61 | public Optional exec(String sql, Object[] params, FuncWithException2 rowHandler) { 62 | Optional result = new Optional(); 63 | exec(sql, params, (row) -> { 64 | result.value = rowHandler.invoke(row); 65 | }); 66 | return result; 67 | } 68 | 69 | public void exec(String sql) { 70 | exec(sql, null, (ActionWithException2)null); 71 | } 72 | 73 | public int execInt(String sql) { 74 | return execInt(sql, null); 75 | } 76 | 77 | public void exec(String sql, Object[] params) { 78 | exec(sql, params, (ActionWithException2)null); 79 | } 80 | 81 | public int execInt(String sql, Object[] params) { 82 | Optional result = exec(sql, params, row -> { 83 | return row.getInt(1); 84 | }); 85 | return result.value != null ? result.value : 0; 86 | } 87 | 88 | public void exec(String sql, ActionWithException2 rowHandler) { 89 | exec(sql, null, rowHandler); 90 | } 91 | 92 | public Optional exec(String sql, FuncWithException2 rowHandler) { 93 | return exec(sql, null, rowHandler); 94 | } 95 | 96 | /** 97 | * 读取日期时间列 98 | */ 99 | public Date readDateTime(ResultSet row, String columnName) { 100 | try { 101 | return new Date(row.getTimestamp(columnName).getTime()); 102 | } catch (SQLException ex) { 103 | throw new RuntimeException(ex); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/StringUtil.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder; 2 | 3 | 4 | import java.math.BigDecimal; 5 | import java.util.*; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | /** 10 | * Created by yunfeng.lu on 2017/10/3 11 | */ 12 | 13 | public class StringUtil { 14 | 15 | public static boolean isEmpty(String str) { 16 | return str == null || str.length() == 0; 17 | } 18 | 19 | public static boolean isNil(Object src) { 20 | return src == null || "".equals(src.toString().trim()); 21 | } 22 | 23 | public static boolean isNil(Collection collection) { 24 | return collection == null || collection.isEmpty(); 25 | } 26 | 27 | public static boolean isNil(Map map) { 28 | return map == null || map.isEmpty(); 29 | } 30 | 31 | public static boolean isNilWithoutTrim(Object src) { 32 | return src == null || "".equals(src.toString()); 33 | } 34 | 35 | public static String nullToString(Object src) { 36 | return src == null ? "" : src.toString().trim(); 37 | } 38 | 39 | public static String nullToStringWithoutTrim(Object src) { 40 | return src == null ? "" : src.toString(); 41 | } 42 | 43 | public static Integer objToInt(Object src) { 44 | return isNil(src) ? null : (Double.valueOf(nullToString(src))).intValue(); 45 | } 46 | 47 | public static Integer objToInt(Object src, int defaultInt) { 48 | return isNil(src) ? defaultInt : (Double.valueOf(nullToString(src))).intValue(); 49 | } 50 | 51 | public static Double objToNum(Object src) { 52 | return isNil(src) ? null : (Double.valueOf(nullToString(src))); 53 | } 54 | 55 | public static Double objToNum(Object src, Double defaultNum) { 56 | return isNil(src) ? defaultNum : (Double.valueOf(nullToString(src))); 57 | } 58 | 59 | public static Double sumDouble(String... d) { 60 | BigDecimal bd = new BigDecimal("0"); 61 | for (int i = 0; i < d.length; i++) { 62 | bd = bd.add((new BigDecimal(d[i]))); 63 | } 64 | return bd.doubleValue(); 65 | } 66 | 67 | /** 68 | * 提供精确的加法运算。 69 | * 70 | * @param v1 被加数 71 | * @param v2 加数 72 | * @return 两个参数的和 73 | */ 74 | 75 | public static double add(double v1, double v2) { 76 | BigDecimal b1 = new BigDecimal(Double.toString(v1)); 77 | BigDecimal b2 = new BigDecimal(Double.toString(v2)); 78 | return b1.add(b2).doubleValue(); 79 | } 80 | 81 | public static String nullToZero(Object amt) { 82 | if (amt == null) 83 | return "0"; 84 | return (String) amt; 85 | } 86 | 87 | public static String strYuanToFen(Object yuan) { 88 | String fen = isNil(yuan) ? "0" : yuan.toString().trim(); 89 | double moneyI = Double.parseDouble(fen); 90 | return String 91 | .valueOf(Integer.parseInt(new java.text.DecimalFormat("0").format(moneyI * 100))); 92 | } 93 | 94 | public static String strFenToYuan(Object fen) { 95 | String yuan = isNil(fen) ? "0" : fen.toString().trim(); 96 | double moneyI = Double.parseDouble(yuan); 97 | return String.valueOf(moneyI / 100); 98 | } 99 | 100 | /** 101 | * @param text 报文信息 填充位置 0在前 1在后 102 | * @param msgLenRange 103 | * @param msgLenSize 报文长度的长度 104 | */ 105 | public static int getLen(String text, int msgLenRange, int msgLenSize) { 106 | if (text != null) { 107 | int len; 108 | try { 109 | len = text.getBytes("utf-8").length; 110 | if (msgLenRange > 0) 111 | len += msgLenSize; 112 | return len; 113 | } catch (Exception e) { 114 | return 0; 115 | } 116 | } 117 | return 0; 118 | } 119 | 120 | /** 121 | * 把16进制字符串转换成字节数组 122 | * 123 | * @return 124 | */ 125 | public static byte[] hex2byte(byte[] b) { 126 | if (b == null) 127 | return null; 128 | if ((b.length % 2) != 0) 129 | throw new IllegalArgumentException("长度不是偶数"); 130 | byte[] b2 = new byte[b.length / 2]; 131 | for (int n = 0; n < b.length; n += 2) { 132 | String item = new String(b, n, 2); 133 | b2[n / 2] = (byte) Integer.parseInt(item, 16); 134 | } 135 | return b2; 136 | } 137 | 138 | public static final String bytesToHexString(byte[] bArray) { 139 | if (bArray == null) 140 | return null; 141 | StringBuffer sb = new StringBuffer(bArray.length); 142 | String sTemp; 143 | for (int i = 0; i < bArray.length; i++) { 144 | sTemp = Integer.toHexString(0xFF & bArray[i]); 145 | if (sTemp.length() < 2) 146 | sb.append(0); 147 | sb.append(sTemp.toUpperCase()); 148 | } 149 | return sb.toString(); 150 | } 151 | 152 | public static byte[] writeInt32(int i) { 153 | byte[] dataBuffer = new byte[4]; 154 | dataBuffer[0] = (byte) (i & 255); 155 | dataBuffer[1] = (byte) (i >>> 8 & 255); 156 | dataBuffer[2] = (byte) (i >>> 16 & 255); 157 | dataBuffer[3] = (byte) (i >>> 24 & 255); 158 | return dataBuffer; 159 | } 160 | 161 | public static int readInt32(byte[] dataBuffer) { 162 | int pos = 0; 163 | return (dataBuffer[pos] & 255) + ((dataBuffer[pos + 1] & 255) << 8) 164 | + ((dataBuffer[pos + 2] & 255) << 16) + ((dataBuffer[pos + 3] & 255) << 24); 165 | } 166 | 167 | /** 168 | * 按长度补足字符数据项 169 | * 170 | * @param needlen 报文长度规定的字符数 171 | * @param pack 填充字符 172 | * @param direction 填充位置 0在前 1在后 173 | * @return 174 | */ 175 | public static String replenishString(Object obj, Integer needlen, char pack, int direction) { 176 | String text = nullToString(obj); 177 | StringBuffer sb = new StringBuffer(text); 178 | if (needlen == null || needlen <= 0) { 179 | return text; 180 | } 181 | if (text.length() > needlen) { 182 | sb.delete(needlen, sb.length()); 183 | } else { 184 | if (direction > 0) { 185 | while (sb.length() < needlen) { 186 | sb.append(pack); 187 | } 188 | } else { 189 | while (sb.length() < needlen) { 190 | sb.insert(0, pack); 191 | } 192 | } 193 | } 194 | return sb.toString(); 195 | } 196 | 197 | public static Object trimItem(Object obj, char pack, int direction) { 198 | if (obj instanceof String || obj instanceof StringBuffer || obj instanceof StringBuilder) { 199 | int index = 0; 200 | String text = nullToString(obj); 201 | char[] charArray = text.toCharArray(); 202 | StringBuffer sbf = new StringBuffer(text); 203 | if (sbf.length() < 1) 204 | return ""; 205 | if (direction > 0) { // 001100 206 | for (int i = charArray.length - 1; i >= 0; i--) { 207 | if (charArray[i] != pack) { 208 | index = i; 209 | break; 210 | } 211 | } 212 | sbf.delete(++index, sbf.length()); 213 | } else { 214 | for (int i = 0; i < charArray.length; i++) { 215 | if (charArray[i] != pack) { 216 | index = i; 217 | break; 218 | } 219 | } 220 | 221 | sbf.delete(0, index); 222 | } 223 | return sbf.toString(); 224 | } else { 225 | return obj; 226 | } 227 | } 228 | 229 | public static String replenishNum(int text, int needlen) { 230 | StringBuffer sb = new StringBuffer(text); 231 | while (sb.length() < needlen) { 232 | sb.insert(0, "0"); 233 | } 234 | return sb.toString(); 235 | } 236 | 237 | public static boolean findStr(String[] subStr, String str) { 238 | for (int i = 0; i < subStr.length; i++) { 239 | if (subStr[i].equals(str)) 240 | return true; 241 | } 242 | return false; 243 | } 244 | 245 | public static int findNumInStr(String source, String regexNew) { 246 | String regex = "[a-zA-Z]+"; 247 | if (regexNew != null && !regexNew.equals("")) { 248 | regex = regexNew; 249 | } 250 | Pattern expression = Pattern.compile(regex); 251 | Matcher matcher = expression.matcher(source); 252 | TreeMap myTreeMap = new TreeMap(); 253 | int n = 0; 254 | Object word = null; 255 | Object num = null; 256 | while (matcher.find()) { 257 | word = matcher.group(); 258 | n++; 259 | if (myTreeMap.containsKey(word)) { 260 | num = myTreeMap.get(word); 261 | Integer count = (Integer) num; 262 | myTreeMap.put(word, new Integer(count.intValue() + 1)); 263 | } else { 264 | myTreeMap.put(word, new Integer(1)); 265 | } 266 | } 267 | return n; 268 | } 269 | 270 | public static String replaceStr(String source, Map param) throws Exception { 271 | // return replaceStr("\\$\\{(.*?)\\}",source,param); 272 | return replaceStr("${mapValue}", source, param); 273 | } 274 | 275 | public static String replaceStr(String regex, String source, 276 | Map param) throws Exception { 277 | for (Map.Entry entry : param.entrySet()) { 278 | String aaa = regex.replace("mapValue", entry.getKey()); 279 | source = source.replace(aaa, nullToString(entry.getValue())); 280 | } 281 | return source; 282 | } 283 | 284 | public static String binaryString2hexString(String bString) { 285 | if (bString == null || bString.equals("") || bString.length() % 8 != 0) 286 | return null; 287 | StringBuffer tmp = new StringBuffer(); 288 | int iTmp = 0; 289 | for (int i = 0; i < bString.length(); i += 4) { 290 | iTmp = 0; 291 | for (int j = 0; j < 4; j++) { 292 | iTmp += Integer.parseInt(bString.substring(i + j, i + j + 1)) << (4 - j - 1); 293 | } 294 | tmp.append(Integer.toHexString(iTmp)); 295 | } 296 | return tmp.toString(); 297 | } 298 | 299 | public static String hexString2binaryString(String hexString) { 300 | if (hexString == null || hexString.length() % 2 != 0) 301 | return null; 302 | String bString = "", tmp; 303 | for (int i = 0; i < hexString.length(); i++) { 304 | tmp = "0000" 305 | + Integer.toBinaryString(Integer.parseInt(hexString.substring(i, i + 1), 16)); 306 | bString += tmp.substring(tmp.length() - 4); 307 | } 308 | return bString; 309 | } 310 | 311 | public static String str2Unicode(String str) { 312 | StringBuffer unicode = new StringBuffer(); 313 | 314 | for (int i = 0; i < str.length(); i++) { 315 | 316 | // 取出每一个字符 317 | char c = str.charAt(i); 318 | 319 | // 转换为unicode 320 | unicode.append("\\u" + Integer.toHexString(c)); 321 | } 322 | 323 | return unicode.toString(); 324 | } 325 | 326 | public static String unicode2str(String s) { 327 | List list = new ArrayList(); 328 | String zz = "\\\\u[0-9,a-z,A-Z]{4}"; 329 | 330 | // 正则表达式用法参考API 331 | Pattern pattern = Pattern.compile(zz); 332 | Matcher m = pattern.matcher(s); 333 | while (m.find()) { 334 | list.add(m.group()); 335 | } 336 | for (int i = 0, j = 2; i < list.size(); i++) { 337 | String st = list.get(i).substring(j, j + 4); 338 | 339 | // 将得到的数值按照16进制解析为十进制整数,再強转为字符 340 | char ch = (char) Integer.parseInt(st, 16); 341 | // 用得到的字符替换编码表达式 342 | s = s.replace(list.get(i), String.valueOf(ch)); 343 | } 344 | return s; 345 | } 346 | 347 | /** 348 | * 转换下划线命名方式为驼峰方式 349 | * 350 | * @param key 351 | * @return 352 | */ 353 | public static String toUnderScore(String key) { 354 | if (isNil(key)) { 355 | return key; 356 | } 357 | if (key.equals(key.toUpperCase())) { 358 | return key.toLowerCase(); 359 | } 360 | StringBuffer sb = new StringBuffer(); 361 | sb.append(key); 362 | for (int i = 1; i < sb.length(); i++) { 363 | char c = sb.charAt(i); 364 | if (c >= 'A' && c <= 'Z') { 365 | c += 32;// 转换成小写 366 | sb.deleteCharAt(i); 367 | sb.insert(i, c); 368 | sb.insert(i, "_"); 369 | i++; 370 | } 371 | } 372 | return sb.toString(); 373 | } 374 | 375 | public static void mapToCamel(Map map) { 376 | List keyList = new ArrayList(); 377 | keyList.addAll(map.keySet()); 378 | for (int i = 0; i < keyList.size(); i++) { 379 | String key = keyList.get(i); 380 | Object value = map.get(key); 381 | if (value == null) { 382 | map.remove(key); 383 | continue;// 移除null值 384 | } 385 | if (value instanceof Map) { 386 | mapToCamel((Map) value); 387 | } else if (value instanceof List) { 388 | List eleList = (List) value; 389 | for (int j = 0; j < eleList.size(); j++) { 390 | if (eleList.get(j) instanceof Map) { 391 | mapToCamel((Map) eleList.get(j)); 392 | } 393 | } 394 | } 395 | String camelKey = toCamel(key); 396 | map.remove(key); 397 | map.put(camelKey, value); 398 | } 399 | } 400 | 401 | public static void mapToUnderscore(Map map) { 402 | List keyList = new ArrayList(); 403 | keyList.addAll(map.keySet()); 404 | for (int i = 0; i < keyList.size(); i++) { 405 | String key = keyList.get(i); 406 | Object value = map.get(key); 407 | if (value == null) { 408 | map.remove(key); 409 | continue;// 移除null值 410 | } 411 | if (value instanceof Map) { 412 | mapToUnderscore((Map) value); 413 | } else if (value instanceof List) { 414 | List eleList = (List) value; 415 | for (int j = 0; j < eleList.size(); j++) { 416 | if (eleList.get(j) instanceof Map) { 417 | mapToUnderscore((Map) eleList.get(j)); 418 | } 419 | } 420 | } 421 | String underscoreKey = toUnderScore(key); 422 | map.remove(key); 423 | map.put(underscoreKey, value); 424 | } 425 | keyList.clear(); 426 | keyList = null; 427 | } 428 | 429 | public static void mapKeyToUpCase(Map map) { 430 | List keyList = new ArrayList(); 431 | keyList.addAll(map.keySet()); 432 | for (int i = 0; i < keyList.size(); i++) { 433 | String key = keyList.get(i); 434 | Object value = map.get(key); 435 | if (value == null) { 436 | map.remove(key); 437 | continue;// 移除null值 438 | } 439 | if (value instanceof Map) { 440 | mapKeyToUpCase((Map) value); 441 | } else if (value instanceof List) { 442 | List eleList = (List) value; 443 | for (int j = 0; j < eleList.size(); j++) { 444 | if (eleList.get(j) instanceof Map) { 445 | mapKeyToUpCase((Map) eleList.get(j)); 446 | } 447 | } 448 | } 449 | map.remove(key); 450 | map.put(key.toUpperCase(), value); 451 | } 452 | } 453 | 454 | /** 455 | * 转换下划线命名方式为驼峰方式 456 | * 457 | * @param key 458 | * @return 459 | */ 460 | public static String toCamel(String key) { 461 | if (isNil(key)) { 462 | return key; 463 | } 464 | StringBuffer sb = new StringBuffer(); 465 | sb.append(key); 466 | for (int i = 1; i < sb.length(); i++) { 467 | char c = sb.charAt(i); 468 | if (c == '_') { 469 | c = sb.charAt(i + 1); 470 | sb.delete(i, i + 2); 471 | if (c >= 'a' && c <= 'z') { 472 | c -= 32;// 转换成大写 473 | } 474 | sb.insert(i, c); 475 | } 476 | } 477 | return sb.toString(); 478 | } 479 | 480 | /** 481 | * @功能: BCD码转为10进制串(阿拉伯数据) 482 | * @参数: BCD码 483 | * @结果: 10进制串 484 | */ 485 | public static String bcd2Str(byte[] bytes) { 486 | StringBuffer temp = new StringBuffer(bytes.length * 2); 487 | for (int i = 0; i < bytes.length; i++) { 488 | temp.append((byte) ((bytes[i] & 0xf0) >>> 4)); 489 | temp.append((byte) (bytes[i] & 0x0f)); 490 | } 491 | return temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp 492 | .toString().substring(1) : temp.toString(); 493 | } 494 | 495 | /** 496 | * 邮箱工具 获取邮箱做对应的服务商 497 | */ 498 | public static String email2Url(String email) { 499 | if (email != null && email.contains("@")) { 500 | if (email.contains("qq.com")) { 501 | return "https://mail.qq.com"; 502 | } else if (email.contains("163.com")) { 503 | return "https://mail.163.com"; 504 | } else if (email.contains("gmail.com")) { 505 | return "https://mail.google.com"; 506 | } else { 507 | return null; 508 | } 509 | 510 | } else { 511 | return null; 512 | } 513 | } 514 | 515 | 516 | public static boolean isAllDigit(String strNum) { 517 | if (strNum != null) { 518 | // 去除收尾空格 519 | strNum=strNum.trim(); 520 | } 521 | Pattern pattern = Pattern.compile("[0-9]{1,}"); 522 | Matcher matcher = pattern.matcher((CharSequence) strNum); 523 | return matcher.matches(); 524 | } 525 | 526 | public static void main(String[] args) { 527 | String str=""; 528 | System.out.println(isAllDigit("45 45 ")); 529 | 530 | 531 | } 532 | 533 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Action.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | 4 | public interface Action { 5 | void invoke(); 6 | } 7 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Action2.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface Action2 { 4 | void invoke(T t); 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Action3.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface Action3 { 4 | void invoke(T t, T2 t2); 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Action4.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface Action4 { 4 | void invoke(T t, T2 t2, T3 t3); 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Action5.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface Action5 { 4 | void invoke(T t, T2 t2, T3 t3, T4 t4); 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/ActionWithException.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface ActionWithException { 4 | void invoke() throws Exception; 5 | } 6 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/ActionWithException2.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface ActionWithException2 { 4 | void invoke(T t) throws Exception; 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/ActionWithException3.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface ActionWithException3 { 4 | void invoke(T t, T2 t2) throws Exception; 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/ActionWithException4.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface ActionWithException4 { 4 | void invoke(T t, T2 t2, T3 t3) throws Exception; 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/ActionWithException5.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface ActionWithException5 { 4 | void invoke(T t, T2 t2, T3 t3, T4 t4) throws Exception; 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/EqualsFunc.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface EqualsFunc { 4 | boolean invoke(T t1, T t2); 5 | } 6 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/FilterFunc.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface FilterFunc { 4 | boolean filter(T t); 5 | } 6 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Func.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface Func { 4 | T invoke(); 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Func2.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface Func2 { 4 | R invoke(T t); 5 | } 6 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Func3.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface Func3 { 4 | R invoke(T1 t1, T2 t2); 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Func4.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface Func4 { 4 | R invoke(T1 t1, T2 t2, T3 t3); 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Func5.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface Func5 { 4 | R invoke(T1 t1, T2 t2, T3 t3, T4 t4); 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/FuncWithException.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface FuncWithException { 4 | T invoke() throws Exception; 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/FuncWithException2.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface FuncWithException2 { 4 | R invoke(T t) throws Exception; 5 | } 6 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/FuncWithException3.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface FuncWithException3 { 4 | R invoke(T1 t1, T2 t2) throws Exception; 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/FuncWithException4.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface FuncWithException4 { 4 | R invoke(T1 t1, T2 t2, T3 t3) throws Exception; 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/FuncWithException5.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public interface FuncWithException5 { 4 | R invoke(T1 t1, T2 t2, T3 t3, T4 t4) throws Exception; 5 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Optional.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public class Optional { 4 | public T value; 5 | public Optional() {} 6 | public Optional(T value) { 7 | this.value = value; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Optional2.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public class Optional2 { 4 | public T value1; 5 | public T2 value2; 6 | public Optional2() {} 7 | public Optional2(T value1, T2 value2) { 8 | this.value1 = value1; 9 | this.value2 = value2; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Optional3.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public class Optional3 { 4 | public T value1; 5 | public T2 value2; 6 | public T3 value3; 7 | public Optional3() {} 8 | public Optional3(T value1, T2 value2, T3 value3) { 9 | this.value1 = value1; 10 | this.value2 = value2; 11 | this.value3 = value3; 12 | } 13 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Optional4.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public class Optional4 { 4 | public T value1; 5 | public T2 value2; 6 | public T3 value3; 7 | public T4 value4; 8 | public Optional4() {} 9 | public Optional4(T value1, T2 value2, T3 value3, T4 value4) { 10 | this.value1 = value1; 11 | this.value2 = value2; 12 | this.value3 = value3; 13 | this.value4 = value4; 14 | } 15 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/entity/Optional5.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.entity; 2 | 3 | public class Optional5 { 4 | public T value1; 5 | public T2 value2; 6 | public T3 value3; 7 | public T4 value4; 8 | public T5 value5; 9 | public Optional5() {} 10 | public Optional5(T value1, T2 value2, T3 value3, T4 value4, T5 value5) { 11 | this.value1 = value1; 12 | this.value2 = value2; 13 | this.value3 = value3; 14 | this.value4 = value4; 15 | this.value5 = value5; 16 | } 17 | } -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/expection/CommonException.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.expection; 2 | 3 | public class CommonException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = 5719639814985692478L; 6 | private ReturnCodeModel exception_type; 7 | 8 | public CommonException(ReturnCodeModel type) { 9 | super(type.getMsg()); 10 | this.exception_type = type; 11 | } 12 | 13 | public String getErrorCode() { 14 | return this.exception_type.getCode(); 15 | } 16 | 17 | public String getErrorDeclare() { 18 | return this.exception_type.getMsg(); 19 | } 20 | 21 | public ReturnCodeModel getException_type() { 22 | return this.exception_type; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/expection/CommonResponseModel.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.expection; 2 | import java.util.HashMap; 3 | import java.util.Map; 4 | 5 | /** 6 | * @author yunfeng.lu 7 | * @create 2017/10/26. 8 | */ 9 | public class CommonResponseModel { 10 | Map data; 11 | 12 | public CommonResponseModel(ReturnCodeModel code, Map data) { 13 | if(data==null){ 14 | data=new HashMap(); 15 | } 16 | data.put("resCode", code.getCode()); 17 | data.put("resMsg", code.getMsg()); 18 | this.data = data; 19 | } 20 | 21 | public CommonResponseModel(String code, String msg,Map data) { 22 | if(data==null){ 23 | data=new HashMap(); 24 | } 25 | data.put("resCode", code); 26 | data.put("resMsg", msg); 27 | this.data = data; 28 | } 29 | 30 | public Map getData() { 31 | return data; 32 | } 33 | 34 | public static Map facade(ReturnCodeModel code, Map data) { 35 | return new CommonResponseModel(code, data).getData(); 36 | } 37 | 38 | public static Map facade(ReturnCodeModel code) { 39 | return new CommonResponseModel(code, null).getData(); 40 | } 41 | 42 | public static Map facade(String code,String msg) { 43 | return new CommonResponseModel(code,msg,null).getData(); 44 | } 45 | 46 | public static Map success(Map data) { 47 | return new CommonResponseModel(ReturnCodeModel.SUCCESS, data).getData(); 48 | } 49 | 50 | public static Map success() { 51 | return new CommonResponseModel(ReturnCodeModel.SUCCESS, null).getData(); 52 | } 53 | 54 | public static Map success(Object o){ 55 | Map map=new HashMap<>(); 56 | map.put("data",o); 57 | return new CommonResponseModel(ReturnCodeModel.SUCCESS, map).getData(); 58 | 59 | } 60 | 61 | 62 | 63 | public static Map fail(Map data) { 64 | return new CommonResponseModel(ReturnCodeModel.FAIL, data).getData(); 65 | } 66 | 67 | public static Map fail() { 68 | return new CommonResponseModel(ReturnCodeModel.FAIL, null).getData(); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return data.toString(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/expection/ReturnCodeModel.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.expection; 2 | /** 3 | * @author yunfeng.lu 4 | * @create 2017/10/26. 5 | */ 6 | public enum ReturnCodeModel { 7 | 8 | SUCCESS("9999", "成功"), 9 | /** 10 | * 该错误一般是异常未处理 ,没有兜住错误 11 | */ 12 | FAIL("0000", "系统异常"), 13 | SYSTEM_IS_BUSY("0001", "系统忙"), 14 | PARAMETER_IS_MISSING("0002", "参数缺失!"), 15 | JSON_XML_PARSE_ERROR("0003", "格式解析错误"), 16 | SERVER_ERROR("0004", "服务错误,请联系我们"), 17 | NO_DATE("0005", "服务端没有数据"), 18 | SCHEDULE_JOB_ERROR("0006","执行定时任务失败"), 19 | 20 | // 登陆 用户相关 21 | UNAUTHORIZED("2001", "无效的认证"), 22 | AUTHTOKEN_INVALID("2002", "AUTH TOKEN失效,登陆过期"), 23 | DEVICE_INVALID("2003", "终端、ip 不一致"), 24 | NOT_GENERATED_PASSWORD("2004", "您上次登陆方式为快捷登录,未设置过密码,先用快捷登录,设置密码,再使用密码登陆"), 25 | PASSWORDERROR("2005","用户名或者密码错误!"), 26 | NOT_REGISTER("2006","该用户未注册"), 27 | REGISTERED("2007","该用户名或者邮箱已被注册,换一个吧"), 28 | EMAILERROR("2008","请输入正确的邮箱地址,暂时只支持qq,163,gmail 邮箱注册"), 29 | SENDEMAILERROR("2009","邮箱发送失败,请稍后再试"), 30 | VERIFICODEERROR("2010","验证码错误"), 31 | 32 | // 文件处理 33 | FILEDIRCREATE("2101","系统文件创建失败"); 34 | 35 | 36 | 37 | 38 | private String code; 39 | private String msg; 40 | 41 | private ReturnCodeModel(String code, String msg) { 42 | this.code=code; 43 | this.msg=msg; 44 | 45 | } 46 | private ReturnCodeModel() {} 47 | 48 | public static ReturnCodeModel getByCode(String code) { 49 | for (ReturnCodeModel param: ReturnCodeModel.values()) { 50 | if (param.getCode().equals(code)) { 51 | return param; 52 | } 53 | } 54 | return null; 55 | } 56 | public String getCode() { 57 | return code; 58 | } 59 | 60 | public String getMsg() { 61 | return msg; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/log/LogAop.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.log; 2 | 3 | 4 | import org.aspectj.lang.ProceedingJoinPoint; 5 | import org.aspectj.lang.annotation.Around; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.context.request.RequestContextHolder; 11 | import org.springframework.web.context.request.ServletRequestAttributes; 12 | import tech.soulcoder.IPUtils; 13 | import tech.soulcoder.expection.CommonException; 14 | 15 | import javax.servlet.http.HttpServletRequest; 16 | import java.net.InetAddress; 17 | import java.net.UnknownHostException; 18 | import java.util.Arrays; 19 | import java.util.Collection; 20 | 21 | /** 22 | * 切面日志 23 | * Created by yunfeng.lu on 2017/9/18. 24 | */ 25 | @Component 26 | @Aspect 27 | public class LogAop { 28 | private final static Logger logger = LoggerFactory.getLogger(LogAop.class); 29 | 30 | private final static Logger monitor_logger = LoggerFactory.getLogger("LogMonitor"); 31 | 32 | private final static String DEF_PROCESS_SUCCESS_RESULT = "T"; 33 | 34 | private final static String DEF_PROCESS_SLOW_RESULT = "S"; 35 | 36 | private final static String DEF_PROCESS_ERROR_RESULT = "E"; 37 | 38 | private final static String DEF_SUCCESS_CODE = "9999"; 39 | 40 | private final static String DEF_ERROR_CODE = "0000"; 41 | 42 | private static String ip_address = null; 43 | 44 | static { 45 | try { 46 | ip_address = InetAddress.getLocalHost().getHostAddress(); 47 | } catch (UnknownHostException e) { 48 | 49 | logger.error("获取本地IP信息异常 请检查.."); 50 | } 51 | } 52 | 53 | @Around("@annotation(logAuto)") 54 | public Object around(ProceedingJoinPoint pjp, LogAuto logAuto) throws Throwable { 55 | String requestIp = null; 56 | try { 57 | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 58 | requestIp = IPUtils.getIpAddress(request); 59 | ///logger.info("请求 ip {}", requestIp); 60 | } catch (Exception ex) { 61 | logger.error("请求 ip 获取失败"); 62 | } 63 | 64 | Object result = null; 65 | LogAuto.ParamPrintOption printOption = logAuto.outParamPrint(); 66 | long current_time = System.currentTimeMillis(); 67 | String inParam = Arrays.toString(pjp.getArgs()); 68 | String className = pjp.getTarget().getClass().getName(); 69 | String methodName = pjp.getSignature().getName(); 70 | String relateId = String.valueOf(new StringBuilder(String.valueOf(current_time)).append(className).append(methodName).toString().hashCode()); 71 | String processResult = DEF_PROCESS_SUCCESS_RESULT; 72 | String errorCode = DEF_SUCCESS_CODE; 73 | try { 74 | 75 | result = pjp.proceed(); 76 | 77 | if (LogAuto.ParamPrintOption.UNCONFIG.equals(printOption)) { 78 | if (result != null && result instanceof Collection) { 79 | printOption = LogAuto.ParamPrintOption.IGNORE; 80 | } else if (result != null && result.getClass().isArray()) { 81 | printOption = LogAuto.ParamPrintOption.IGNORE; 82 | } else { 83 | printOption = LogAuto.ParamPrintOption.PRINT; 84 | } 85 | } 86 | 87 | long lastTime = System.currentTimeMillis() - current_time; 88 | 89 | if (lastTime >= 2000) { 90 | processResult = DEF_PROCESS_SLOW_RESULT; 91 | logger.info( "请求ip:{}——{}.{}:{},该方法执行较慢请检查... 入参: {} \t出参: {} 响应时间:{6}毫秒",requestIp, className, 92 | methodName, relateId, inParam, 93 | printOption.equals(LogAuto.ParamPrintOption.PRINT) ? result : "", lastTime); 94 | } else { 95 | //ip 类名.方法名.请求id 入参 出参 96 | logger.info( "请求ip:{}——{}.{}:{} 入参: {} \t出参: {} 响应时间:{}毫秒", requestIp,className, 97 | methodName, relateId, 98 | inParam, 99 | printOption.equals(LogAuto.ParamPrintOption.PRINT) ? result : "参数太长不打印了", lastTime); 100 | } 101 | 102 | //{请求ip}~{类名}~{方法名}~{关联ID}~{设备ID}~{IP地址}~{错误码}~{错误消息}~{执行结果}~{执行时间} 103 | monitor_logger.info("{}~{}~{}~{}~{}~{}~{}~{}~{}~{}", requestIp,className, methodName, relateId, "uid/设备ID",ip_address, errorCode,"执行成功",processResult,lastTime); 104 | 105 | } catch (CommonException ex) { 106 | processResult = DEF_PROCESS_ERROR_RESULT; 107 | 108 | logger.error("{}.{}:{} 执行报错,入参: {}", pjp.getTarget().getClass().getName(), 109 | pjp.getSignature().getName(), relateId, Arrays.toString(pjp.getArgs()),ex); 110 | 111 | monitor_logger.info("{}~{}~{}~{}~{}~{}~{}~{}~{}~{}", requestIp,className, methodName, relateId, "uid/设备ID",ip_address, ex.getErrorCode(),ex.getMessage(), 112 | processResult,System.currentTimeMillis() - current_time); 113 | throw ex; 114 | 115 | } catch (Throwable throwable) { 116 | errorCode = DEF_ERROR_CODE; 117 | 118 | processResult = DEF_PROCESS_ERROR_RESULT; 119 | 120 | logger.error( "{}.{}:{} 执行报错,入参: {}", pjp.getTarget().getClass().getName(), 121 | pjp.getSignature().getName(), relateId, Arrays.toString(pjp.getArgs()),throwable); 122 | 123 | monitor_logger.info("{}~{}~{}~{}~{}~{}~{}~{}~{}~{}", requestIp,className, methodName, relateId, "uid/设备ID",ip_address,errorCode,throwable.getMessage(), 124 | processResult,System.currentTimeMillis() - current_time); 125 | 126 | throw throwable; 127 | } 128 | 129 | return result; 130 | 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /soulcoder-utils/src/main/java/tech/soulcoder/log/LogAuto.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.log; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by yunfeng.lu on 2017/9/18. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface LogAuto { 14 | public String value() default ""; 15 | public ParamPrintOption outParamPrint() default ParamPrintOption.UNCONFIG; 16 | 17 | 18 | public enum ParamPrintOption{ 19 | 20 | /** 21 | * 未配置 22 | */ 23 | UNCONFIG("UNCONFIG","未配置"), 24 | 25 | /** 26 | * 打印 27 | */ 28 | PRINT("PRINT","打印"), 29 | 30 | /** 31 | * 忽略打印 32 | */ 33 | IGNORE("IGNORE","忽略打印"); 34 | 35 | /** 36 | * 代码 37 | */ 38 | private String code; 39 | 40 | /** 41 | * desc 42 | */ 43 | private String desc; 44 | 45 | /** 46 | * @param code 47 | */ 48 | private ParamPrintOption(String code,String desc) { 49 | this.code = code; 50 | this.desc = desc; 51 | } 52 | 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /soulcoder-web/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### IntelliJ IDEA ### 5 | .idea 6 | *.iws 7 | *.iml 8 | *.ipr 9 | 10 | 11 | 12 | application-dev.yml 13 | application-prod.yml 14 | 15 | -------------------------------------------------------------------------------- /soulcoder-web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | soulcoder 7 | tech.soulcoder 8 | 0.0.1-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | soulcoder-web 14 | 15 | 16 | 17 | tech.soulcoder 18 | soulcoder-core 19 | 0.0.1-SNAPSHOT 20 | 21 | 22 | tech.soulcoder 23 | soulcoder-service 24 | 0.0.1-SNAPSHOT 25 | 26 | 27 | tech.soulcoder 28 | soulcoder-utils 29 | 0.0.1-SNAPSHOT 30 | 31 | 32 | 33 | 34 | soulcoder 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-maven-plugin 39 | 1.3.0.RELEASE 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /soulcoder-web/src/main/java/tech/soulcoder/StartApplication.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 9 | import org.springframework.context.annotation.ComponentScan; 10 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 11 | import org.springframework.scheduling.annotation.EnableScheduling; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | /** 16 | * @author yunfeng.lu 17 | * @date 2018年05月18日17:31:56 18 | */ 19 | @EnableScheduling 20 | @EnableAspectJAutoProxy(exposeProxy=true) 21 | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) 22 | public class StartApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(StartApplication.class, args); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /soulcoder-web/src/main/java/tech/soulcoder/web/TestController.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.web; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import tech.soulcoder.expection.CommonException; 9 | import tech.soulcoder.expection.CommonResponseModel; 10 | import tech.soulcoder.service.TestService; 11 | 12 | import java.util.Map; 13 | 14 | @RestController 15 | public class TestController { 16 | private static final Logger logger = LoggerFactory.getLogger(TestController.class); 17 | 18 | @Autowired 19 | private TestService testService; 20 | 21 | @GetMapping("/test") 22 | public Map test() { 23 | 24 | try { 25 | return CommonResponseModel.success(testService.testDB()); 26 | } catch (CommonException ue) { 27 | logger.error(" 异常,请检查....", ue); 28 | return CommonResponseModel.facade(ue.getException_type()); 29 | } catch (Exception ex) { 30 | logger.error("异常,请检查....", ex); 31 | return CommonResponseModel.fail(); 32 | } 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /soulcoder-web/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev -------------------------------------------------------------------------------- /soulcoder-web/src/main/resources/logback-dev.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | %d{yyyy/MM/dd-HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 9 | 10 | 11 | 12 | ${LOG_HOME}/tiny-%d{yyyy-MM-dd}.%i.log 13 | 14 | 300MB 15 | 30 16 | 200GB 17 | 18 | 19 | 20 | 21 | ${LOG_HOME}/monitor.log 22 | 23 | %d{yyyy/MM/dd-HH:mm:ss}|%msg%n 24 | 25 | 26 | INFO 27 | ACCEPT 28 | DENY 29 | 30 | 31 | 32 | ${LOG_HOME}/monitor.log.%i 33 | 1 34 | 20 35 | 36 | 37 | 38 | 50MB 39 | 40 | 41 | 42 | 43 | 44 | ${LOG_HOME}/error.log 45 | 46 | 47 | %d{yyyy-MM-dd HH:mm:ss} [%class:%line] - %m%n 48 | 49 | 50 | 51 | ERROR 52 | ACCEPT 53 | DENY 54 | 55 | 56 | 57 | ${LOG_HOME}/error.log.%i 58 | 1 59 | 20 60 | 61 | 62 | 63 | 20MB 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | %d{yyyy-MM-dd HH:mm:ss} [%class:%line] - %m%n 73 | 74 | UTF-8 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 97 | 98 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /soulcoder-web/src/main/resources/logback-prod.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | %d{yyyy/MM/dd-HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 9 | 10 | 11 | 12 | ${LOG_HOME}/tiny-%d{yyyy-MM-dd}.%i.log 13 | 14 | 300MB 15 | 30 16 | 200GB 17 | 18 | 19 | 20 | 21 | ${LOG_HOME}/monitor.log 22 | 23 | %d{yyyy/MM/dd-HH:mm:ss}|%msg%n 24 | 25 | 26 | INFO 27 | ACCEPT 28 | DENY 29 | 30 | 31 | 32 | ${LOG_HOME}/monitor.log.%i 33 | 1 34 | 20 35 | 36 | 37 | 38 | 50MB 39 | 40 | 41 | 42 | 43 | 44 | ${LOG_HOME}/error.log 45 | 46 | 47 | %d{yyyy-MM-dd HH:mm:ss} [%class:%line] - %m%n 48 | 49 | 50 | 51 | ERROR 52 | ACCEPT 53 | DENY 54 | 55 | 56 | 57 | ${LOG_HOME}/error.log.%i 58 | 1 59 | 20 60 | 61 | 62 | 63 | 20MB 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | %d{yyyy-MM-dd HH:mm:ss} [%class:%line] - %m%n 73 | 74 | UTF-8 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 97 | 98 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /soulcoder-web/src/test/java/tech/soulcoder/mytest/BaseTest.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.mytest; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import tech.soulcoder.RedisOperation; 9 | import tech.soulcoder.service.TestService; 10 | 11 | @RunWith(SpringRunner.class) 12 | @SpringBootTest 13 | public class BaseTest { 14 | @Autowired 15 | public TestService testService; 16 | 17 | @Autowired 18 | public RedisOperation redisOperation; 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /soulcoder-web/src/test/java/tech/soulcoder/mytest/MyTest.java: -------------------------------------------------------------------------------- 1 | package tech.soulcoder.mytest; 2 | 3 | 4 | import com.alibaba.fastjson.JSON; 5 | import org.apache.ibatis.session.SqlSessionFactory; 6 | import org.junit.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.beans.factory.annotation.Qualifier; 9 | import tech.soulcoder.SqlHelper; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public class MyTest extends BaseTest { 15 | 16 | @Autowired 17 | private SqlHelper sqlHelper; 18 | 19 | @Test 20 | public void test(){ 21 | System.out.println(testService.testDB()); 22 | } 23 | 24 | @Test 25 | public void redisTest(){ 26 | redisOperation.setValue("haha","lala"); 27 | System.out.println(redisOperation.getValue("haha")); 28 | 29 | } 30 | 31 | /** 32 | * sqlHelp 测试 33 | */ 34 | @Test 35 | public void sqlSessionFactoryTest(){ 36 | Map map=new HashMap<>(); 37 | sqlHelper.exec("select id,pwd from soul_user",row ->{ 38 | map.put(row.getString("id"),row.getString("pwd")); 39 | }); 40 | System.out.println(JSON.toJSONString(map)); 41 | } 42 | 43 | } 44 | 45 | --------------------------------------------------------------------------------