├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── dunwu-dependencies └── pom.xml ├── dunwu-parent └── pom.xml ├── dunwu-tool ├── dunwu-tool-core │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── io │ │ │ └── github │ │ │ └── dunwu │ │ │ └── tool │ │ │ ├── bean │ │ │ ├── BeanUtil.java │ │ │ ├── TypeConvert.java │ │ │ └── support │ │ │ │ └── NamingStrategy.java │ │ │ ├── codec │ │ │ ├── AesEncode.java │ │ │ ├── DesEncode.java │ │ │ ├── DesedeEncode.java │ │ │ ├── Encode.java │ │ │ ├── MessageDigestUtil.java │ │ │ ├── SymmetricEncode.java │ │ │ └── package-info.java │ │ │ ├── core │ │ │ ├── constant │ │ │ │ ├── CodeMsg.java │ │ │ │ ├── DunwuConstant.java │ │ │ │ ├── GetDesc.java │ │ │ │ ├── GetIntCode.java │ │ │ │ ├── GetIntValue.java │ │ │ │ ├── GetStringCode.java │ │ │ │ ├── GetStringValue.java │ │ │ │ └── enums │ │ │ │ │ └── ResultCode.java │ │ │ ├── exception │ │ │ │ ├── AuthException.java │ │ │ │ ├── CodeMsgException.java │ │ │ │ └── DefaultException.java │ │ │ └── function │ │ │ │ └── CallFunction.java │ │ │ ├── io │ │ │ ├── AnsiColorUtil.java │ │ │ ├── FileUtil.java │ │ │ ├── ResourceUtil.java │ │ │ └── ansi │ │ │ │ ├── Ansi8BitColor.java │ │ │ │ ├── AnsiBackground.java │ │ │ │ ├── AnsiColor.java │ │ │ │ ├── AnsiColors.java │ │ │ │ ├── AnsiElement.java │ │ │ │ ├── AnsiOutput.java │ │ │ │ ├── AnsiStyle.java │ │ │ │ └── ColorType.java │ │ │ ├── package-info.java │ │ │ ├── thread │ │ │ └── ThreadPoolUtil.java │ │ │ └── util │ │ │ ├── ClassUtil.java │ │ │ ├── DateUtil.java │ │ │ ├── PropertiesUtil.java │ │ │ ├── RandomUtil.java │ │ │ ├── RegexUtil.java │ │ │ ├── SerializableUtil.java │ │ │ ├── SystemUtil.java │ │ │ ├── ValidatorUtil.java │ │ │ ├── package-info.java │ │ │ └── tree │ │ │ ├── Node.java │ │ │ ├── Tree.java │ │ │ ├── TreeNode.java │ │ │ ├── TreeNodeConfig.java │ │ │ ├── TreeUtil.java │ │ │ └── parser │ │ │ ├── DefaultNodeParser.java │ │ │ └── NodeParser.java │ │ └── test │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── dunwu │ │ │ └── tool │ │ │ ├── codec │ │ │ ├── MessageDigestUtilTest.java │ │ │ └── SymmetricEncryptTest.java │ │ │ ├── io │ │ │ ├── AnsiColorUtilTest.java │ │ │ └── FileUtilTests.java │ │ │ └── util │ │ │ ├── DateUtilTest.java │ │ │ ├── PropertiesUtilTest.java │ │ │ ├── RandomUtilTest.java │ │ │ └── ValidatorUtilTest.java │ │ └── resources │ │ ├── hutool.jpg │ │ ├── test.csv │ │ ├── test.properties │ │ └── test.xml ├── dunwu-tool-data │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── io │ │ │ └── github │ │ │ └── dunwu │ │ │ └── tool │ │ │ └── data │ │ │ ├── annotation │ │ │ ├── ControllerEndpoint.java │ │ │ ├── Dao.java │ │ │ ├── FlowLimit.java │ │ │ ├── JobHandler.java │ │ │ ├── Manager.java │ │ │ ├── QueryField.java │ │ │ └── QueryTable.java │ │ │ ├── aop │ │ │ └── BaseAop.java │ │ │ ├── constant │ │ │ ├── FlowLimitType.java │ │ │ ├── OrderType.java │ │ │ ├── QueryJudgeType.java │ │ │ └── QueryLogicType.java │ │ │ ├── desensitized │ │ │ ├── DesensitizedSerializer.java │ │ │ ├── DesensitizedUtil.java │ │ │ ├── annotation │ │ │ │ ├── Desensitized.java │ │ │ │ └── NeedDesensitized.java │ │ │ └── constant │ │ │ │ └── SensitiveTypeEnum.java │ │ │ ├── elasticsearch │ │ │ ├── ElasticSearchUtil.java │ │ │ └── annotation │ │ │ │ ├── QueryDocument.java │ │ │ │ └── QueryField.java │ │ │ ├── entity │ │ │ ├── TableColumnInfo.java │ │ │ └── TableInfo.java │ │ │ ├── excel │ │ │ ├── ExcelDataStorageListener.java │ │ │ └── ExcelUtil.java │ │ │ ├── exception │ │ │ └── DataException.java │ │ │ ├── hdfs │ │ │ ├── HdfsConfig.java │ │ │ ├── HdfsFactory.java │ │ │ ├── HdfsPool.java │ │ │ └── HdfsUtil.java │ │ │ ├── mybatis │ │ │ ├── BaseExtDaoImpl.java │ │ │ ├── BaseRecordEntity.java │ │ │ ├── DaoImpl.java │ │ │ ├── DaoInfo.java │ │ │ ├── IDao.java │ │ │ ├── IExtDao.java │ │ │ ├── IService.java │ │ │ ├── ServiceImpl.java │ │ │ ├── package-info.java │ │ │ └── util │ │ │ │ └── MybatisPlusUtil.java │ │ │ ├── p6spy │ │ │ ├── P6spySlf4jLogger.java │ │ │ └── P6spySqlFormat.java │ │ │ ├── redis │ │ │ └── RedisHelper.java │ │ │ ├── request │ │ │ ├── PageQuery.java │ │ │ └── PageQueryWrapper.java │ │ │ ├── response │ │ │ ├── DataListResult.java │ │ │ ├── DataResult.java │ │ │ ├── MapResult.java │ │ │ ├── Order.java │ │ │ ├── PageImpl.java │ │ │ ├── PageResult.java │ │ │ └── Result.java │ │ │ ├── util │ │ │ ├── DatabaseUtil.java │ │ │ ├── PageUtil.java │ │ │ ├── ReflectionUtil.java │ │ │ ├── SpringContextHelper.java │ │ │ └── SwaggerUtil.java │ │ │ └── validator │ │ │ ├── IpValidator.java │ │ │ ├── MobileValidator.java │ │ │ ├── RegexValidator.java │ │ │ └── annotation │ │ │ ├── AddCheck.java │ │ │ ├── EditCheck.java │ │ │ ├── IsIp.java │ │ │ ├── IsMobile.java │ │ │ └── RegexValid.java │ │ └── test │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── dunwu │ │ │ └── tool │ │ │ └── data │ │ │ ├── PageImplTests.java │ │ │ ├── PageQueryTests.java │ │ │ ├── ResultTests.java │ │ │ ├── desensitized │ │ │ └── DesensitizedUtilTests.java │ │ │ └── hdfs │ │ │ ├── HdfsConcurrentTest.java │ │ │ └── HdfsUtilTest.java │ │ └── resources │ │ └── source.txt ├── dunwu-tool-dlock │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── io │ │ │ └── github │ │ │ └── dunwu │ │ │ └── tool │ │ │ └── dlock │ │ │ ├── core │ │ │ ├── AbstractDistributedLock.java │ │ │ ├── AbstractStorageAccessor.java │ │ │ ├── DefaultLockManager.java │ │ │ ├── DefaultLockingTaskExecutor.java │ │ │ ├── DistributedLock.java │ │ │ ├── LockAssert.java │ │ │ ├── LockConfiguration.java │ │ │ ├── LockConfigurationExtractor.java │ │ │ ├── LockException.java │ │ │ ├── LockManager.java │ │ │ ├── LockProvider.java │ │ │ ├── LockRecordRegistry.java │ │ │ ├── LockableRunnable.java │ │ │ ├── LockingTaskExecutor.java │ │ │ ├── StorageAccessor.java │ │ │ ├── StorageBasedLockProvider.java │ │ │ └── Utils.java │ │ │ └── provider │ │ │ ├── JdbcTemplateLockProvider.java │ │ │ ├── JdbcTemplateStorageAccessor.java │ │ │ ├── RedisLockProvider.java │ │ │ └── ZookeeperLockProvider.java │ │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── dunwu │ │ └── tool │ │ └── dlock │ │ ├── provider │ │ ├── AbstractRedisLockProviderIntegrationTest.java │ │ ├── H2JdbcTemplateLockProviderIntegrationTest.java │ │ ├── JedisLockProviderIntegrationTest.java │ │ ├── LetucceLockProviderIntegrationTest.java │ │ ├── MySqlJdbcTemplateLockProviderIntegrationTest.java │ │ └── ZookeeperLockProviderIntegrationTest.java │ │ └── test │ │ └── support │ │ ├── AbstractExtensibleLockProviderIntegrationTest.java │ │ ├── AbstractJdbcLockProviderIntegrationTest.java │ │ ├── AbstractLockProviderIntegrationTest.java │ │ ├── AbstractStorageBasedLockProviderIntegrationTest.java │ │ ├── DbConfig.java │ │ ├── FuzzTester.java │ │ ├── JdbcTestUtils.java │ │ └── TransactionalFuzzTester.java ├── dunwu-tool-generator │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── dunwu │ │ │ │ └── tool │ │ │ │ └── generator │ │ │ │ ├── CodeGenerator.java │ │ │ │ ├── CodeGeneratorExt.java │ │ │ │ ├── CodeGeneratorUtil.java │ │ │ │ ├── ICodeGenerator.java │ │ │ │ ├── InjectionConfig.java │ │ │ │ ├── MybatisPlusGenProps.java │ │ │ │ ├── config │ │ │ │ ├── ConstVal.java │ │ │ │ ├── DataSourceConfig.java │ │ │ │ ├── FileOutConfig.java │ │ │ │ ├── GlobalConfig.java │ │ │ │ ├── IDbQuery.java │ │ │ │ ├── IFileCreate.java │ │ │ │ ├── INameConvert.java │ │ │ │ ├── ITypeConvert.java │ │ │ │ ├── PackageConfig.java │ │ │ │ ├── StrategyConfig.java │ │ │ │ ├── TemplateConfig.java │ │ │ │ ├── builder │ │ │ │ │ ├── ConfigBuilder.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── converts │ │ │ │ │ ├── DB2TypeConvert.java │ │ │ │ │ ├── DmTypeConvert.java │ │ │ │ │ ├── GaussTypeConvert.java │ │ │ │ │ ├── KingbaseESTypeConvert.java │ │ │ │ │ ├── MySqlTypeConvert.java │ │ │ │ │ ├── OracleTypeConvert.java │ │ │ │ │ ├── PostgreSqlTypeConvert.java │ │ │ │ │ ├── SqlServerTypeConvert.java │ │ │ │ │ ├── SqliteTypeConvert.java │ │ │ │ │ ├── TypeConvertRegistry.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── package-info.java │ │ │ │ ├── po │ │ │ │ │ ├── DictInfo.java │ │ │ │ │ ├── DictOptionInfo.java │ │ │ │ │ ├── LikeTable.java │ │ │ │ │ ├── TableField.java │ │ │ │ │ ├── TableFill.java │ │ │ │ │ ├── TableInfo.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── querys │ │ │ │ │ ├── AbstractDbQuery.java │ │ │ │ │ ├── DB2Query.java │ │ │ │ │ ├── DMQuery.java │ │ │ │ │ ├── DbQueryRegistry.java │ │ │ │ │ ├── GaussQuery.java │ │ │ │ │ ├── H2Query.java │ │ │ │ │ ├── KingbaseESQuery.java │ │ │ │ │ ├── MariadbQuery.java │ │ │ │ │ ├── MySqlQuery.java │ │ │ │ │ ├── OracleQuery.java │ │ │ │ │ ├── PostgreSqlQuery.java │ │ │ │ │ ├── SqlServerQuery.java │ │ │ │ │ ├── SqliteQuery.java │ │ │ │ │ └── package-info.java │ │ │ │ └── rules │ │ │ │ │ ├── DateType.java │ │ │ │ │ ├── FileType.java │ │ │ │ │ ├── FormType.java │ │ │ │ │ ├── IColumnType.java │ │ │ │ │ ├── JavaColumnType.java │ │ │ │ │ ├── ListType.java │ │ │ │ │ ├── NamingStrategy.java │ │ │ │ │ ├── ValidateType.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── engine │ │ │ │ ├── AbstractTemplateEngine.java │ │ │ │ ├── CodeGenerateContentDto.java │ │ │ │ └── FreemarkerTemplateEngine.java │ │ │ │ └── util │ │ │ │ └── FreemarkerHelper.java │ │ └── resources │ │ │ └── templates │ │ │ ├── backend │ │ │ ├── controller.java.ftl │ │ │ ├── dao.java.ftl │ │ │ ├── daoImpl.java.ftl │ │ │ ├── dict.java.ftl │ │ │ ├── dto.java.ftl │ │ │ ├── entity.java.ftl │ │ │ ├── mapper.java.ftl │ │ │ ├── mapper.xml.ftl │ │ │ ├── query.java.ftl │ │ │ ├── service.java.ftl │ │ │ └── serviceImpl.java.ftl │ │ │ └── frontend │ │ │ ├── api.js.ftl │ │ │ ├── form.vue.ftl │ │ │ └── list.vue.ftl │ │ └── test │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── dunwu │ │ │ └── tool │ │ │ └── generator │ │ │ └── MyCodeGenerator.java │ │ └── resources │ │ └── conf │ │ └── mybatis.properties ├── dunwu-tool-net │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── dunwu │ │ │ │ └── tool │ │ │ │ └── net │ │ │ │ ├── NetUtil.java │ │ │ │ ├── ip │ │ │ │ ├── Header.java │ │ │ │ ├── IpUtil.java │ │ │ │ └── Searcher.java │ │ │ │ └── region │ │ │ │ ├── City.java │ │ │ │ ├── County.java │ │ │ │ ├── Province.java │ │ │ │ └── RegionUtil.java │ │ └── resources │ │ │ └── db │ │ │ ├── cn-area-info.json │ │ │ └── ip2region.xdb │ │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── dunwu │ │ └── tool │ │ └── net │ │ ├── NetUtilTests.java │ │ ├── ip │ │ └── IpUtilsTest.java │ │ └── region │ │ └── RegionUtilTests.java ├── dunwu-tool-special │ ├── dunwu-tool-image │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── dunwu │ │ │ │ └── tool │ │ │ │ └── image │ │ │ │ ├── ImageInfo.java │ │ │ │ ├── ImageProperties.java │ │ │ │ ├── ImageType.java │ │ │ │ ├── ImageUtil.java │ │ │ │ ├── ImageWaterMark.java │ │ │ │ └── KaptchaUtils.java │ │ │ └── test │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── dunwu │ │ │ │ └── tool │ │ │ │ └── image │ │ │ │ ├── ImageUtilTest.java │ │ │ │ └── KaptchaUtilsTest.java │ │ │ └── resources │ │ │ └── images │ │ │ ├── logo.png │ │ │ └── logo2.png │ ├── dunwu-tool-parser │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── dunwu │ │ │ │ └── tool │ │ │ │ └── parser │ │ │ │ ├── git │ │ │ │ └── GitUtil.java │ │ │ │ ├── md │ │ │ │ └── MarkdownUtil.java │ │ │ │ └── yaml │ │ │ │ └── YamlUtil.java │ │ │ └── test │ │ │ └── java │ │ │ └── io │ │ │ └── github │ │ │ └── dunwu │ │ │ └── tool │ │ │ └── parser │ │ │ └── md │ │ │ └── MarkdownUtilTest.java │ └── dunwu-tool-pdf │ │ ├── pom.xml │ │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── dunwu │ │ │ │ └── tool │ │ │ │ └── pdf │ │ │ │ ├── FreemarkerUtil.java │ │ │ │ └── PdfUtil.java │ │ └── resources │ │ │ ├── fonts │ │ │ └── msyh.ttf │ │ │ └── templates │ │ │ └── template.ftl │ │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── dunwu │ │ └── tool │ │ └── pdf │ │ ├── FreemarkerUtilTest.java │ │ └── OrderInfo.java ├── dunwu-tool-web │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── dunwu │ │ └── tool │ │ └── web │ │ ├── CookieUtil.java │ │ ├── ServletUtil.java │ │ ├── SpringUtil.java │ │ ├── aop │ │ ├── CorsInceptor.java │ │ ├── HttpDebugInterceptor.java │ │ ├── SecurityInterceptor.java │ │ ├── entity │ │ │ └── MethodInfo.java │ │ └── util │ │ │ └── AopUtil.java │ │ ├── constant │ │ ├── HttpHeaders.java │ │ └── WebConstant.java │ │ ├── converter │ │ ├── DateConverter.java │ │ ├── DateTimeConverter.java │ │ ├── LocalDateConverter.java │ │ └── LocalDateTimeConverter.java │ │ ├── filter │ │ ├── XssFilter.java │ │ └── wrapper │ │ │ └── XssHttpServletRequestWrapper.java │ │ ├── jsp │ │ ├── BlockTag.java │ │ └── OverrideTag.java │ │ ├── log │ │ ├── annotation │ │ │ ├── DataLockLog.java │ │ │ └── OperationLog.java │ │ ├── aop │ │ │ ├── DataLockLogAop.java │ │ │ └── OperationLogAop.java │ │ ├── constant │ │ │ └── OperationType.java │ │ ├── entity │ │ │ ├── DataLockLogInfo.java │ │ │ ├── DataLockLogRecord.java │ │ │ ├── ExecuteResult.java │ │ │ ├── OperationLogInfo.java │ │ │ └── OperationLogRecord.java │ │ ├── service │ │ │ ├── DataLockLogService.java │ │ │ ├── FunctionService.java │ │ │ ├── OperationLogService.java │ │ │ ├── ParseFunction.java │ │ │ ├── TableColumnConfigService.java │ │ │ └── impl │ │ │ │ ├── DefaultDataLockLogServiceImpl.java │ │ │ │ ├── DefaultFunctionServiceImpl.java │ │ │ │ ├── DefaultOperationLogServiceImpl.java │ │ │ │ ├── DefaultParseFunction.java │ │ │ │ └── DefaultTableColumnConfigServiceImpl.java │ │ └── support │ │ │ ├── DataLockLogParser.java │ │ │ ├── LogRecordContext.java │ │ │ ├── LogRecordEvaluationContext.java │ │ │ ├── LogRecordExpressionEvaluator.java │ │ │ ├── OperationLogParser.java │ │ │ ├── ParseFunctionFactory.java │ │ │ └── SpElValueParser.java │ │ └── security │ │ └── SecurityService.java ├── pom.xml └── scripts │ └── deploy.bat └── pom.xml /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig 用于在 IDE 中检查代码的基本 Code Style 2 | # @see: https://editorconfig.org/ 3 | 4 | # 配置说明: 5 | # 所有文件换行使用 Unix 风格(LF),*.bat 文件使用 Windows 风格(CRLF) 6 | # java / sh 文件缩进 4 个空格,其他所有文件缩进 2 个空格 7 | 8 | root = true 9 | 10 | [*] 11 | end_of_line = lf 12 | indent_size = 2 13 | indent_style = space 14 | max_line_length = 120 15 | charset = utf-8 16 | trim_trailing_whitespace = true 17 | insert_final_newline = true 18 | 19 | [*.{bat, cmd}] 20 | end_of_line = crlf 21 | 22 | [*.{java, gradle, groovy, kt, sh, xml}] 23 | indent_size = 4 24 | 25 | [*.md] 26 | max_line_length = 0 27 | trim_trailing_whitespace = false 28 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | # plan text 4 | *.txt text 5 | *.java text 6 | *.scala text 7 | *.groovy text 8 | *.gradle text 9 | *.xml text 10 | *.xsd text 11 | *.tld text 12 | *.yaml text 13 | *.yml text 14 | *.wsdd text 15 | *.wsdl text 16 | *.jsp text 17 | *.jspf text 18 | *.js text 19 | *.jsx text 20 | *.json text 21 | *.css text 22 | *.less text 23 | *.sql text 24 | *.properties text 25 | 26 | # unix style 27 | *.sh text eol=lf 28 | 29 | # win style 30 | *.bat text eol=crlf 31 | 32 | # don't handle 33 | *.der -text 34 | *.jks -text 35 | *.pfx -text 36 | *.map -text 37 | *.patch -text 38 | *.dat -text 39 | *.data -text 40 | *.db -text 41 | 42 | # binary 43 | *.jar binary 44 | *.war binary 45 | *.zip binary 46 | *.tar binary 47 | *.tar.gz binary 48 | *.gz binary 49 | *.apk binary 50 | *.bin binary 51 | *.exe binary 52 | 53 | # images 54 | *.png binary 55 | *.jpg binary 56 | *.ico binary 57 | *.gif binary 58 | 59 | # medias 60 | *.mp3 binary 61 | *.swf binary 62 | 63 | # fonts 64 | *.eot binary 65 | *.svg binary 66 | *.ttf binary 67 | *.woff binary 68 | 69 | # others 70 | *.pdf binary 71 | *.doc binary 72 | *.docx binary 73 | *.ppt binary 74 | *.pptx binary 75 | *.xls binary 76 | *.xlsx binary 77 | *.xmind binary 78 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # --------------------------------------------------------------------- 2 | # more gitignore templates see https://github.com/github/gitignore 3 | # --------------------------------------------------------------------- 4 | 5 | # ------------------------------- java ------------------------------- 6 | # compiled folders 7 | classes 8 | target 9 | logs 10 | .mtj.tmp/ 11 | 12 | # compiled files 13 | *.class 14 | 15 | # bluej files 16 | *.ctxt 17 | 18 | # package files # 19 | *.jar 20 | *.war 21 | *.nar 22 | *.ear 23 | *.zip 24 | *.tar.gz 25 | *.rar 26 | 27 | # virtual machine crash logs 28 | hs_err_pid* 29 | 30 | # maven plugin temp files 31 | .flattened-pom.xml 32 | dependency-reduced-pom.xml 33 | 34 | 35 | # ------------------------------- javascript ------------------------------- 36 | # dependencies 37 | node_modules 38 | 39 | # temp folders 40 | build 41 | dist 42 | _book 43 | _jsdoc 44 | 45 | # temp files 46 | *.log 47 | npm-debug.log* 48 | yarn-debug.log* 49 | yarn-error.log* 50 | bundle*.js 51 | book.pdf 52 | 53 | 54 | # ------------------------------- intellij ------------------------------- 55 | .idea 56 | *.iml 57 | 58 | 59 | # ------------------------------- eclipse ------------------------------- 60 | .classpath 61 | .project 62 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk8 4 | 5 | script: 6 | - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V 7 | 8 | branches: 9 | only: 10 | - master 11 | 12 | notifications: 13 | email: 14 | recipients: 15 | - forbreak@163.com 16 | on_success: change # default: change 17 | on_failure: always # default: always 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dunwu-framework 2 | 3 | > dunwu-framework 项目是一个 Java 脚手架项目。 4 | 5 | [![License](https://img.shields.io/badge/license-Apache%202-blue)](https://www.apache.org/licenses/LICENSE-2.0.html) [![Maven](https://img.shields.io/badge/maven--central-v3.5.4-blue)](https://maven.apache.org/ref/3.5.4/) [![Build Status](https://travis-ci.com/dunwu/dunwu-framework.svg?branch=master)](https://travis-ci.com/dunwu/dunwu-framework) 6 | 7 | ## 项目结构 8 | 9 | - `dunwu-dependencies`:管理项目中所有常见 jar 包的版本。 10 | - `dunwu-parent`:所有模块的父 pom,管理各种插件及构建。 11 | - `dunwu-tool`:dunwu 工具包模块,对常见工具集进行二次封装,并提供一些通用工具类,旨在提高开发效能。 12 | - `dunwu-boot`:在 Spring Boot 的基础上进行扩展,针对一些未覆盖的场景,提供 starter 包,以支持即开即用。 13 | 14 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | io.github.dunwu.tool 8 | dunwu-tool 9 | 1.1.2 10 | ../pom.xml 11 | 12 | 13 | dunwu-tool-core 14 | jar 15 | dunwu 基础工具包 16 | https://github.com/dunwu/dunwu-framework/dunwu-tool/dunwu-tool-core 17 | 18 | 19 | 20 | cn.hutool 21 | hutool-all 22 | 23 | 24 | org.projectlombok 25 | lombok 26 | 27 | 28 | ch.qos.logback 29 | logback-classic 30 | true 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | org.junit.vintage 40 | junit-vintage-engine 41 | 42 | 43 | 44 | 45 | org.junit.platform 46 | junit-platform-launcher 47 | test 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/bean/BeanUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.bean; 2 | 3 | import cn.hutool.core.collection.CollectionUtil; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Zhang Peng 11 | * @since 2020-04-08 12 | */ 13 | public class BeanUtil extends cn.hutool.core.bean.BeanUtil { 14 | 15 | public static Collection toBeanCollection(Collection collection, Class clazz) { 16 | final Collection targetList = new ArrayList<>(); 17 | if (CollectionUtil.isEmpty(collection)) { 18 | return targetList; 19 | } 20 | 21 | for (S o : collection) { 22 | T item = toBean(o, clazz); 23 | targetList.add(item); 24 | } 25 | return targetList; 26 | } 27 | 28 | public static List toBeanList(Collection collection, Class clazz) { 29 | return new ArrayList<>(toBeanCollection(collection, clazz)); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/bean/TypeConvert.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.bean; 2 | 3 | /** 4 | * Bean 类型转换接口 5 | * 6 | * @author Zhang Peng 7 | * @since 2020-04-25 8 | */ 9 | public interface TypeConvert { 10 | 11 | /** 12 | * 将类型 S 转换为 T 13 | * 14 | * @param origin 要转换的对象 15 | * @return / 16 | */ 17 | T transform(S origin); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/bean/support/NamingStrategy.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.bean.support; 2 | 3 | /** 4 | * 关键字命名策略枚举 5 | * 6 | * @author Zhang Peng 7 | * @since 2019-12-18 8 | */ 9 | public enum NamingStrategy { 10 | /** 11 | * 默认命名。即不对命名做任何要求 12 | */ 13 | DEFAULT, 14 | /** 15 | * 驼峰命名。例:namingStrategy 16 | */ 17 | CAMEL, 18 | /** 19 | * 全小写字母用下划线拼接。例:naming_strategy 20 | */ 21 | LOWER_UNDERLINE, 22 | /** 23 | * 全大写字母用下划线拼接。例:NAMING_STRATEGY 24 | */ 25 | UPPER_UNDERLINE, 26 | /** 27 | * 全小写字母用分割线拼接。例:naming-strategy 28 | */ 29 | LOWER_DASHED, 30 | /** 31 | * 全小写字母用分割线拼接。例:NAMING-STRATEGY 32 | */ 33 | UPPER_DASHED 34 | } 35 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/codec/MessageDigestUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.codec; 2 | 3 | import cn.hutool.core.codec.Base64; 4 | 5 | import java.security.MessageDigest; 6 | import java.security.NoSuchAlgorithmException; 7 | 8 | /** 9 | * @author Zhang Peng 10 | * @since 2020-03-11 11 | */ 12 | public class MessageDigestUtil { 13 | 14 | private MessageDigestUtil() { } 15 | 16 | public static String encodeWithBase64(String type, byte[] input, byte[] salt) throws NoSuchAlgorithmException { 17 | return Base64.encodeUrlSafe(encode(type, input, salt)); 18 | } 19 | 20 | public static byte[] encode(String type, byte[] input, byte[] salt) throws NoSuchAlgorithmException { 21 | // 根据类型,初始化消息摘要对象 22 | MessageDigest digest = MessageDigest.getInstance(type); 23 | 24 | // 更新要计算的内容 25 | if (salt != null) { 26 | digest.reset(); 27 | digest.update(salt); 28 | } 29 | 30 | // 完成哈希计算,返回摘要 31 | return digest.digest(input); 32 | } 33 | 34 | public static String encodeWithBase64(Type type, byte[] input, byte[] salt) throws NoSuchAlgorithmException { 35 | return Base64.encodeUrlSafe(encode(type, input, salt)); 36 | } 37 | 38 | public static byte[] encode(Type type, byte[] input, byte[] salt) throws NoSuchAlgorithmException { 39 | return encode(type.name, input, salt); 40 | } 41 | 42 | enum Type { 43 | 44 | MD2("MD2"), 45 | MD5("MD5"), 46 | SHA1("SHA1"), 47 | SHA256("SHA-256"), 48 | SHA384("SHA-384"), 49 | SHA512("SHA-512"); 50 | 51 | private String name; 52 | 53 | Type(String name) { 54 | this.name = name; 55 | } 56 | 57 | public String getName() { 58 | return this.name; 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/codec/SymmetricEncode.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.codec; 2 | 3 | import java.security.GeneralSecurityException; 4 | import java.util.Base64; 5 | 6 | /** 7 | * 对称加密接口 8 | * 9 | * @author Zhang Peng 10 | * @since 2020-03-14 11 | */ 12 | public interface SymmetricEncode extends Encode { 13 | 14 | /** 15 | * 对二进制密文解密,返回二进制 16 | * 17 | * @param ciphertext 密文 18 | * @return byte[] 明文 19 | * @throws GeneralSecurityException 20 | */ 21 | byte[] decode(byte[] ciphertext) throws GeneralSecurityException; 22 | 23 | /** 24 | * 对二进制密文解密,返回字符串 25 | * 26 | * @param ciphertext 密文 27 | * @return String 明文 28 | * @throws GeneralSecurityException 29 | */ 30 | default String decodeStr(byte[] ciphertext) throws GeneralSecurityException { 31 | return new String(decode(ciphertext)); 32 | } 33 | 34 | /** 35 | * 对 Base64 二次编码后的密文进行解密 36 | * 37 | * @param ciphertext 密文 38 | * @return 明文 39 | * @throws GeneralSecurityException 40 | */ 41 | default byte[] decodeFromBase64(String ciphertext) throws GeneralSecurityException { 42 | return decode(Base64.getUrlDecoder().decode(ciphertext)); 43 | } 44 | 45 | /** 46 | * 对 Base64 二次编码后的密文进行解密 47 | * 48 | * @param ciphertext 密文 49 | * @return 明文 50 | * @throws GeneralSecurityException 51 | */ 52 | default String decodeStrFromBase64(String ciphertext) throws GeneralSecurityException { 53 | return new String(decodeFromBase64(ciphertext)); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/codec/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BaseN以及BCD编码封装 3 | * 4 | * @author looly 5 | */ 6 | package io.github.dunwu.tool.codec; 7 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/CodeMsg.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.core.constant; 2 | 3 | /** 4 | * 请求 / 应答状态接口 5 | * 6 | * @author Zhang Peng 7 | * @since 2019-06-06 8 | */ 9 | public interface CodeMsg { 10 | 11 | int getCode(); 12 | 13 | String getMsg(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/DunwuConstant.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.core.constant; 2 | 3 | /** 4 | * 常量 5 | * 6 | * @author Zhang Peng 7 | * @since 2020-03-14 8 | */ 9 | public class DunwuConstant { 10 | 11 | /** 12 | * 注册用户角色ID 13 | */ 14 | public static final Long REGISTER_ROLE_ID = 2L; 15 | 16 | /** 17 | * 排序规则:降序 18 | */ 19 | public static final String ORDER_DESC = "desc"; 20 | 21 | /** 22 | * 排序规则:升序 23 | */ 24 | public static final String ORDER_ASC = "asc"; 25 | 26 | /** 27 | * 前端页面路径前缀 28 | */ 29 | public static final String VIEW_PREFIX = "febs/views/"; 30 | 31 | /** 32 | * 验证码 Session Key 33 | */ 34 | public static final String CODE_PREFIX = "dunwu_captcha_"; 35 | 36 | /** 37 | * 允许下载的文件类型,根据需求自己添加(小写) 38 | */ 39 | public static final String[] VALID_FILE_TYPE = { "xlsx", "zip" }; 40 | 41 | /** 42 | * 异步线程池名称 43 | */ 44 | public static final String ASYNC_POOL = "dunwuAsyncThreadPool"; 45 | 46 | /** 47 | * 开发环境 48 | */ 49 | public static final String DEVELOP = "dev"; 50 | 51 | /** 52 | * Windows 操作系统 53 | */ 54 | public static final String SYSTEM_WINDOWS = "windows"; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/GetDesc.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.core.constant; 2 | 3 | /** 4 | * @author peng.zhang 5 | * @date 2021-09-26 6 | */ 7 | public interface GetDesc { 8 | 9 | String getDesc(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/GetIntCode.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.core.constant; 2 | 3 | /** 4 | * @author Zhang Peng 5 | * @since 2019-07-24 6 | */ 7 | public interface GetIntCode { 8 | 9 | int getCode(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/GetIntValue.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.core.constant; 2 | 3 | /** 4 | * @author Zhang Peng 5 | * @since 2019-08-14 6 | */ 7 | public interface GetIntValue { 8 | 9 | int getValue(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/GetStringCode.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.core.constant; 2 | 3 | /** 4 | * @author Zhang Peng 5 | * @since 2021-09-25 6 | */ 7 | public interface GetStringCode { 8 | 9 | String getCode(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/GetStringValue.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.core.constant; 2 | 3 | /** 4 | * @author Zhang Peng 5 | * @since 2019-08-14 6 | */ 7 | public interface GetStringValue { 8 | 9 | String getValue(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/exception/AuthException.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.core.exception; 2 | 3 | import io.github.dunwu.tool.core.constant.CodeMsg; 4 | import io.github.dunwu.tool.core.constant.enums.ResultCode; 5 | 6 | /** 7 | * 认证异常 8 | * @author Zhang Peng 9 | * @since 2019-04-11 10 | */ 11 | public class AuthException extends CodeMsgException { 12 | 13 | private static final long serialVersionUID = -7027578114976830416L; 14 | 15 | public AuthException() { 16 | this(ResultCode.AUTH_ERROR); 17 | } 18 | 19 | public AuthException(CodeMsg codeMsg) { 20 | this(codeMsg.getCode(), codeMsg.getMsg()); 21 | } 22 | 23 | public AuthException(CodeMsg codeMsg, String msg) { 24 | this(codeMsg.getCode(), msg, null); 25 | } 26 | 27 | public AuthException(CodeMsg codeMsg, String msg, String toast) { 28 | this(codeMsg.getCode(), msg, toast); 29 | } 30 | 31 | public AuthException(String msg) { 32 | this(ResultCode.AUTH_ERROR, msg); 33 | } 34 | 35 | public AuthException(int code, String msg) { 36 | this(code, msg, msg); 37 | } 38 | 39 | public AuthException(int code, String msg, String toast) { 40 | super(code, msg, toast); 41 | } 42 | 43 | public AuthException(Throwable cause) { 44 | this(cause, ResultCode.AUTH_ERROR); 45 | } 46 | 47 | public AuthException(Throwable cause, String msg) { 48 | this(cause, ResultCode.AUTH_ERROR, msg); 49 | } 50 | 51 | public AuthException(Throwable cause, CodeMsg codeMsg) { 52 | this(cause, codeMsg.getCode(), codeMsg.getMsg()); 53 | } 54 | 55 | public AuthException(Throwable cause, CodeMsg codeMsg, String msg) { 56 | this(cause, codeMsg.getCode(), msg, null); 57 | } 58 | 59 | public AuthException(Throwable cause, CodeMsg codeMsg, String msg, String toast) { 60 | this(cause, codeMsg.getCode(), msg, toast); 61 | } 62 | 63 | public AuthException(Throwable cause, int code, String msg) { 64 | this(cause, code, msg, null); 65 | } 66 | 67 | public AuthException(Throwable cause, int code, String msg, String toast) { 68 | super(cause, code, msg, toast); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/function/CallFunction.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.core.function; 2 | 3 | import java.io.Serializable; 4 | 5 | @FunctionalInterface 6 | public interface CallFunction extends Serializable { 7 | 8 | R call(P var1) throws Exception; 9 | 10 | default R callWithRuntimeException(P parameter) { 11 | try { 12 | return this.call(parameter); 13 | } catch (Exception var3) { 14 | throw new RuntimeException(var3); 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/io/ansi/AnsiBackground.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.io.ansi; 2 | 3 | /** 4 | * ANSI 背景显示颜色枚举 5 | * 6 | * @author Zhang Peng 7 | * @see ANSI Colors 8 | * @since 2019/10/30 9 | */ 10 | public enum AnsiBackground implements AnsiElement { 11 | 12 | DEFAULT("49"), 13 | 14 | BLACK("40"), 15 | 16 | RED("41"), 17 | 18 | GREEN("42"), 19 | 20 | YELLOW("43"), 21 | 22 | BLUE("44"), 23 | 24 | MAGENTA("45"), 25 | 26 | CYAN("46"), 27 | 28 | WHITE("47"), 29 | 30 | BRIGHT_BLACK("100"), 31 | 32 | BRIGHT_RED("101"), 33 | 34 | BRIGHT_GREEN("102"), 35 | 36 | BRIGHT_YELLOW("103"), 37 | 38 | BRIGHT_BLUE("104"), 39 | 40 | BRIGHT_MAGENTA("105"), 41 | 42 | BRIGHT_CYAN("106"), 43 | 44 | BRIGHT_WHITE("107"); 45 | 46 | private final String code; 47 | 48 | AnsiBackground(String code) { 49 | this.code = code; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return code; 55 | } 56 | 57 | public String getCode() { 58 | return code; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/io/ansi/AnsiColor.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.io.ansi; 2 | 3 | /** 4 | * ANSI 字体显示颜色枚举 5 | * 6 | * @author Zhang Peng 7 | * @see ANSI Colors 8 | * @since 2019/10/30 9 | */ 10 | public enum AnsiColor implements AnsiElement { 11 | 12 | DEFAULT("39"), 13 | BLACK("30"), 14 | RED("31"), 15 | GREEN("32"), 16 | YELLOW("33"), 17 | BLUE("34"), 18 | MAGENTA("35"), 19 | CYAN("36"), 20 | WHITE("37"), 21 | BRIGHT_BLACK("90"), 22 | BRIGHT_RED("91"), 23 | BRIGHT_GREEN("92"), 24 | BRIGHT_YELLOW("99"), 25 | BRIGHT_BLUE("94"), 26 | BRIGHT_MAGENTA("95"), 27 | BRIGHT_CYAN("96"), 28 | BRIGHT_WHITE("97"); 29 | 30 | private final String code; 31 | 32 | AnsiColor(String code) { 33 | this.code = code; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return code; 39 | } 40 | 41 | public String getCode() { 42 | return code; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/io/ansi/AnsiElement.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.io.ansi; 2 | 3 | public interface AnsiElement { 4 | 5 | /** 6 | * @return the ANSI escape code 7 | */ 8 | @Override 9 | String toString(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/io/ansi/AnsiStyle.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.io.ansi; 2 | 3 | /** 4 | * Ansi SGR (Select Graphic Rendition) 设置显示属性。 5 | *

6 | * 可以按相同的顺序设置多个属性,并用分号隔开。 7 | *

8 | * 每个显示属性一直有效,直到随后发生SGR重置它为止。 9 | *

10 | * 如果未给出代码,则将 CSI m 视为 CSI 0m(重置/正常)。 11 | * 12 | * @author Zhang Peng 13 | * @see SGR 14 | * @since 2019/10/30 15 | */ 16 | public enum AnsiStyle implements AnsiElement { 17 | 18 | NORMAL("0"), 19 | BOLD("1"), 20 | FAINT("2"), 21 | ITALIC("3"), 22 | UNDERLINE("4"), 23 | SLOW_BLINK("5"), 24 | RAPID_BLINK("6"), 25 | REVERSE_VIDEO("7"), 26 | CONCEAL("8"); 27 | 28 | private final String code; 29 | 30 | AnsiStyle(String code) { 31 | this.code = code; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return code; 37 | } 38 | 39 | public String getCode() { 40 | return code; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/io/ansi/ColorType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.io.ansi; 2 | 3 | /** 4 | * 完全对应 {@link AnsiColor} 和 {@link AnsiBackground} 所有元素 5 | * 6 | * @author Zhang Peng 7 | * @since 2019/10/30 8 | */ 9 | public enum ColorType { 10 | 11 | DEFAULT("默认"), 12 | BLACK("黑色"), 13 | RED("红色"), 14 | GREEN("绿色"), 15 | YELLOW("黄色"), 16 | BLUE("蓝色"), 17 | MAGENTA("紫色"), 18 | CYAN("青色"), 19 | WHITE("白色"), 20 | BRIGHT_BLACK("亮黑色"), 21 | BRIGHT_RED("亮红色"), 22 | BRIGHT_GREEN("亮绿色"), 23 | BRIGHT_YELLOW("亮黄色"), 24 | BRIGHT_BLUE("亮蓝色"), 25 | BRIGHT_MAGENTA("亮紫色"), 26 | BRIGHT_CYAN("亮青色"), 27 | BRIGHT_WHITE("亮白色"); 28 | 29 | private String desc; 30 | 31 | ColorType(String desc) { 32 | this.desc = desc; 33 | } 34 | 35 | public String getDesc() { 36 | return desc; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Hutool核心方法及数据结构包 3 | * 4 | * @author looly 5 | */ 6 | package io.github.dunwu.tool; 7 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/util/ClassUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.util; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.Collections; 5 | import java.util.LinkedHashSet; 6 | import java.util.Set; 7 | 8 | /** 9 | * @author Zhang Peng 10 | * @since 2020-05-20 11 | */ 12 | public class ClassUtil extends cn.hutool.core.util.ClassUtil { 13 | 14 | /** 15 | * @param clazz 指定类 16 | * @return 对象及其父类的所有字段 17 | */ 18 | public static Field[] getAllFields(Class clazz) { 19 | Set fieldSet = new LinkedHashSet<>(); 20 | // 为了避免出现死循环,所以设定最大嵌套层数为 10 (正常情况,嵌套层数不会太深) 21 | int i = 0; 22 | while (clazz != null && i < 10) { 23 | i++; 24 | Collections.addAll(fieldSet, clazz.getDeclaredFields()); 25 | clazz = clazz.getSuperclass(); 26 | } 27 | Field[] fields = new Field[fieldSet.size()]; 28 | fieldSet.toArray(fields); 29 | return fields; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/util/SerializableUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.util; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author Zhang Peng 7 | * @since 2021-10-05 8 | */ 9 | public class SerializableUtil { 10 | 11 | public static Long getLong(Serializable value) { 12 | if (value instanceof Long) { 13 | return (Long) value; 14 | } else if (value instanceof Integer) { 15 | Integer intValue = (Integer) value; 16 | return intValue.longValue(); 17 | } else { 18 | return null; 19 | } 20 | } 21 | 22 | public static Integer getInteger(Serializable value) { 23 | if (value instanceof Long) { 24 | Long longValue = (Long) value; 25 | return longValue.intValue(); 26 | } else if (value instanceof Integer) { 27 | return (Integer) value; 28 | } else { 29 | return null; 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 提供各种工具方法,按照归类入口为XXXUtil,如字符串工具StrUtil等 3 | * 4 | * @author looly 5 | */ 6 | package io.github.dunwu.tool.util; 7 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/util/tree/parser/DefaultNodeParser.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.util.tree.parser; 2 | 3 | import cn.hutool.core.collection.CollUtil; 4 | import cn.hutool.core.map.MapUtil; 5 | import io.github.dunwu.tool.util.tree.Tree; 6 | import io.github.dunwu.tool.util.tree.TreeNode; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Map; 10 | 11 | /** 12 | * 默认的简单转换器 13 | * 14 | * @author liangbaikai 15 | * @author Zhang Peng 16 | */ 17 | public class DefaultNodeParser implements NodeParser { 18 | 19 | @Override 20 | public void parse(TreeNode treeNode, Tree tree) { 21 | if (MapUtil.isNotEmpty(treeNode.getFull())) { 22 | treeNode.getFull().forEach(tree::putExtra); 23 | if (CollUtil.isEmpty(tree.getChildren())) { 24 | tree.setChildren(new ArrayList<>()); 25 | } 26 | return; 27 | } 28 | 29 | tree.setId(treeNode.getId()); 30 | tree.setPid(treeNode.getPid()); 31 | tree.setWeight(treeNode.getWeight()); 32 | tree.setName(treeNode.getName()); 33 | tree.setChildren(new ArrayList<>()); 34 | 35 | //扩展字段 36 | final Map extra = treeNode.getExtra(); 37 | if (MapUtil.isNotEmpty(extra)) { 38 | extra.forEach(tree::putExtra); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/util/tree/parser/NodeParser.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.util.tree.parser; 2 | 3 | import io.github.dunwu.tool.util.tree.Node; 4 | 5 | /** 6 | * 树节点解析器 可以参考{@link DefaultNodeParser} 7 | * 8 | * @param 转换的实体 为数据源里的对象类型 9 | * @author liangbaikai 10 | */ 11 | @FunctionalInterface 12 | public interface NodeParser, T extends Node> { 13 | 14 | /** 15 | * @param object 源数据实体 16 | * @param treeNode 树节点实体 17 | */ 18 | void parse(S object, T treeNode); 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/test/java/io/github/dunwu/tool/codec/MessageDigestUtilTest.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.codec; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.RepeatedTest; 5 | 6 | import java.security.NoSuchAlgorithmException; 7 | 8 | /** 9 | * @author Zhang Peng 10 | * @since 2020-03-14 11 | */ 12 | public class MessageDigestUtilTest { 13 | 14 | @RepeatedTest(2) 15 | public void testSHA384() throws NoSuchAlgorithmException { 16 | String username = "root"; 17 | String password = "root"; 18 | String target = MessageDigestUtil.encodeWithBase64(MessageDigestUtil.Type.SHA384, username.getBytes(), 19 | password.getBytes()); 20 | String result = String.format("%s摘要:%s", MessageDigestUtil.Type.SHA384.getName(), target); 21 | Assertions.assertEquals("ZApimbcDO6rAvpQyi9yFpOFxvIgvi5dXu6VKQPgUduIC22MwT3Wlli62MNn9m9d_", target); 22 | System.out.println(result); 23 | } 24 | 25 | @RepeatedTest(2) 26 | public void testMD5() throws NoSuchAlgorithmException { 27 | String username = "root"; 28 | String password = "root"; 29 | String target = MessageDigestUtil.encodeWithBase64(MessageDigestUtil.Type.MD5, username.getBytes(), 30 | password.getBytes()); 31 | String result = String.format("%s摘要:%s", MessageDigestUtil.Type.MD5.getName(), target); 32 | Assertions.assertEquals("tLja9LjqnTlWhxnh4yAHbw", target); 33 | System.out.println(result); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/test/java/io/github/dunwu/tool/io/AnsiColorUtilTest.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.io; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | /** 6 | * @author Zhang Peng 7 | * @since 2020-03-14 8 | */ 9 | public class AnsiColorUtilTest { 10 | 11 | @Test 12 | public void test() { 13 | AnsiColorUtil.setEnabled(false); 14 | AnsiColorUtil.BOLD_RED.println("abc"); 15 | System.out.println("abc"); 16 | 17 | AnsiColorUtil.setEnabled(true); 18 | AnsiColorUtil.RED.print("A"); 19 | AnsiColorUtil.GREEN.print("B"); 20 | AnsiColorUtil.BLUE.print("C"); 21 | System.out.println("D"); 22 | 23 | AnsiColorUtil.RED.printf("HELLO \n%s", "World"); 24 | AnsiColorUtil.BOLD_BLUE.printf("HELLO\n"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/test/java/io/github/dunwu/tool/io/FileUtilTests.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.io; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Zhang Peng 11 | * @since 2023-05-01 12 | */ 13 | public class FileUtilTests { 14 | 15 | String rootDir = "E:\\照片\\"; 16 | 17 | @Test 18 | public void test() { 19 | File dir = new File(rootDir); 20 | File[] files = dir.listFiles(); 21 | for (File file : files) { 22 | if (file.isDirectory()) { 23 | continue; 24 | } 25 | 26 | String fullFileName = FileUtil.getName(file); 27 | String filename = StrUtil.subBefore(fullFileName, ".jpg", true); 28 | if (!StrUtil.startWith(filename, "IMG_")) { 29 | continue; 30 | } 31 | 32 | List groups = StrUtil.split(filename, "_"); 33 | 34 | String month = groups.get(1).substring(0, 6); 35 | String newFileName = rootDir + month + "\\" + fullFileName; 36 | FileUtil.move(file, new File(newFileName), false); 37 | // System.out.println(newFileName); 38 | } 39 | } 40 | 41 | @Test 42 | public void test2() { 43 | // for (int i = 1; i <= 4; i++) { 44 | // FileUtil.textToBinary(StrUtil.format("D:\\Temp\\temp{}.txt", i), 45 | // StrUtil.format("D:\\Temp\\backup.part0{}.rar", i)); 46 | // } 47 | // FileUtil.binaryToText("D:\\Workspace\\知识图谱.xmind", "D:\\Workspace\\知识图谱.txt"); 48 | FileUtil.textToBinary("D:\\Temp\\Output.txt", "D:\\Temp\\Output.rar"); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/test/java/io/github/dunwu/tool/util/DateUtilTest.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.time.Duration; 6 | 7 | /** 8 | * @author Zhang Peng 9 | * @since 2020-04-13 10 | */ 11 | public class DateUtilTest { 12 | 13 | @Test 14 | public void test() { 15 | Duration duration = 16 | Duration.ofDays(7).plusMinutes(32).plusSeconds(21).plusMillis(500).plusNanos(1000); 17 | String formatTime = DateUtil.formatDurationChineseString(duration); 18 | System.out.println("formatTime: " + formatTime); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/test/resources/hutool.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dunwu/dunwu-framework/HEAD/dunwu-tool/dunwu-tool-core/src/test/resources/hutool.jpg -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/test/resources/test.csv: -------------------------------------------------------------------------------- 1 | 姓名,"性别",关注"对象",年龄 -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/test/resources/test.properties: -------------------------------------------------------------------------------- 1 | #-------------------------------------------- 2 | # 配置文件测试 3 | #-------------------------------------------- 4 | a = 1 5 | b = 2 6 | dunwu.timezone = GMT+8 7 | dunwu.encoding = utf-8 8 | dunwu.min = 1 9 | dunwu.max = 10 10 | dunwu.enabled = true 11 | dunwu.nodes[0] = 1 12 | dunwu.nodes[1] = 2 13 | dunwu.nodes[2] = 3 14 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-core/src/test/resources/test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Success(成功) 4 | ok 5 | 1490 6 | 885 7 | 1 8 | 9 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/ControllerEndpoint.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.annotation; 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 | * @author MrBird 10 | */ 11 | @Target(ElementType.METHOD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface ControllerEndpoint { 14 | 15 | String operation() default ""; 16 | 17 | String exceptionMessage() default "系统内部异常"; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/Dao.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.annotation; 2 | 3 | import org.springframework.core.annotation.AliasFor; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.lang.annotation.*; 7 | 8 | /** 9 | * Dao 标记注解 10 | * 11 | * @author Zhang Peng 12 | * @since 2019-07-23 13 | */ 14 | @Component 15 | @Documented 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target({ ElementType.TYPE }) 18 | public @interface Dao { 19 | 20 | @AliasFor(annotation = Component.class) 21 | String value() default ""; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/FlowLimit.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.annotation; 2 | 3 | import io.github.dunwu.tool.data.constant.FlowLimitType; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * 流控注解 12 | * 13 | * @author Zhang Peng 14 | * @since 2020-03-15 15 | */ 16 | @Target(ElementType.METHOD) 17 | @Retention(RetentionPolicy.RUNTIME) 18 | public @interface FlowLimit { 19 | 20 | /** 21 | * 资源名称,用于描述接口功能 22 | */ 23 | String name() default ""; 24 | 25 | /** 26 | * 资源 key 27 | */ 28 | String key() default ""; 29 | 30 | /** 31 | * key prefix 32 | */ 33 | String prefix() default ""; 34 | 35 | /** 36 | * 时间范围,单位秒 37 | */ 38 | int period(); 39 | 40 | /** 41 | * 限制访问次数 42 | */ 43 | int count(); 44 | 45 | /** 46 | * 限制类型 47 | */ 48 | FlowLimitType limitType() default FlowLimitType.CUSTOMER; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/JobHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.annotation; 2 | 3 | import org.springframework.core.annotation.AliasFor; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.lang.annotation.*; 7 | 8 | @Target({ ElementType.TYPE }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Documented 11 | @Component 12 | @Inherited 13 | public @interface JobHandler { 14 | 15 | @AliasFor("beanName") 16 | String value() default ""; 17 | 18 | @AliasFor("value") 19 | String beanName() default ""; 20 | 21 | String executeMethod() default "execute"; 22 | 23 | Class[] paramTypes() default {}; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/Manager.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.annotation; 2 | 3 | import org.springframework.core.annotation.AliasFor; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.lang.annotation.*; 7 | 8 | /** 9 | * Manager 标记注解 10 | *

11 | * 用于指示被修饰的类型是一个管理类。管理类通常由多个 Service 类组成,用于处理一些跨职能的服务。 12 | * 13 | * @author Zhang Peng 14 | * @since 2019-07-23 15 | */ 16 | @Target({ ElementType.TYPE }) 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Documented 19 | @Component 20 | public @interface Manager { 21 | 22 | @AliasFor(annotation = Component.class) 23 | String value() default ""; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/QueryField.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.annotation; 2 | 3 | import io.github.dunwu.tool.bean.support.NamingStrategy; 4 | import org.springframework.core.annotation.AliasFor; 5 | 6 | import java.lang.annotation.*; 7 | 8 | /** 9 | * 查询注解 10 | * 11 | * @author Zhang Peng 12 | * @since 2019-07-23 13 | */ 14 | @Documented 15 | @Target(ElementType.FIELD) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | public @interface QueryField { 18 | 19 | @AliasFor("name") 20 | String value() default ""; 21 | 22 | @AliasFor("value") 23 | String name() default ""; 24 | 25 | String[] blurry() default {}; 26 | 27 | QueryType type() default QueryType.EQUALS; 28 | 29 | String joinName() default ""; 30 | 31 | boolean nullable() default false; 32 | 33 | NamingStrategy namingStrategy() default NamingStrategy.LOWER_UNDERLINE; 34 | 35 | enum QueryType { 36 | EQUALS, 37 | LIKE, 38 | NOT_LIKE, 39 | LIKE_LEFT, 40 | LIKE_RIGHT, 41 | LT, 42 | LE, 43 | GT, 44 | GE, 45 | NE, 46 | IN, 47 | NOT_IN, 48 | BETWEEN, 49 | NOT_NULL 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/QueryTable.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.annotation; 2 | 3 | import org.springframework.core.annotation.AliasFor; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * @author Zhang Peng 9 | * @since 2020-04-07 10 | */ 11 | @Documented 12 | @Target(ElementType.TYPE) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface QueryTable { 15 | 16 | @AliasFor("entity") 17 | Class value() default Object.class; 18 | 19 | @AliasFor("value") 20 | Class entity() default Object.class; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/aop/BaseAop.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.aop; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | import org.aspectj.lang.reflect.MethodSignature; 5 | 6 | import java.lang.reflect.Method; 7 | 8 | /** 9 | * @author Zhang Peng 10 | * @since 2020-03-15 11 | */ 12 | public abstract class BaseAop { 13 | 14 | protected Method resolveMethod(ProceedingJoinPoint point) { 15 | MethodSignature signature = (MethodSignature) point.getSignature(); 16 | Class targetClass = point.getTarget().getClass(); 17 | Method method = getDeclaredMethod(targetClass, signature.getName(), 18 | signature.getMethod().getParameterTypes()); 19 | if (method == null) { 20 | throw new IllegalStateException("无法解析目标方法: " + signature.getMethod().getName()); 21 | } 22 | return method; 23 | } 24 | 25 | private Method getDeclaredMethod(Class clazz, String name, Class... parameterTypes) { 26 | try { 27 | return clazz.getDeclaredMethod(name, parameterTypes); 28 | } catch (NoSuchMethodException e) { 29 | Class superClass = clazz.getSuperclass(); 30 | if (superClass != null) { 31 | return getDeclaredMethod(superClass, name, parameterTypes); 32 | } 33 | } 34 | return null; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/constant/FlowLimitType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.constant; 2 | 3 | /** 4 | * 流控类型枚举 5 | * 6 | * @author Zhang Peng 7 | * @since 2021-09-25 8 | */ 9 | public enum FlowLimitType { 10 | /** 11 | * 传统类型 12 | */ 13 | CUSTOMER, 14 | /** 15 | * 根据 IP地址限制 16 | */ 17 | IP 18 | } 19 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/constant/OrderType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.constant; 2 | 3 | import java.util.Locale; 4 | import java.util.Optional; 5 | 6 | /** 7 | * 排序类型枚举 8 | * 9 | * @author Zhang Peng 10 | * @since 2019-12-17 11 | */ 12 | public enum OrderType { 13 | 14 | /** 升序 */ 15 | ASC, 16 | /** 降序 */ 17 | DESC; 18 | 19 | /** 20 | * Returns the {@link OrderType} enum for the given {@link String} or null if it cannot be parsed into an enum 21 | * value. 22 | * 23 | * @param value 字符串 24 | * @return 可选类型 25 | */ 26 | public static Optional fromOptionalString(String value) { 27 | 28 | try { 29 | return Optional.of(fromString(value)); 30 | } catch (IllegalArgumentException e) { 31 | return Optional.empty(); 32 | } 33 | } 34 | 35 | /** 36 | * Returns the {@link OrderType} enum for the given {@link String} value. 37 | * 38 | * @param value 字符串 39 | * @return OrderType 40 | * @throws IllegalArgumentException in case the given value cannot be parsed into an enum value. 41 | */ 42 | public static OrderType fromString(String value) { 43 | 44 | try { 45 | return OrderType.valueOf(value.toUpperCase(Locale.US)); 46 | } catch (Exception e) { 47 | throw new IllegalArgumentException(String.format( 48 | "Invalid value '%s' for orders given! Has to be either 'desc' or 'asc' (case insensitive).", value), e); 49 | } 50 | } 51 | 52 | /** 53 | * Returns whether the direction is ascending. 54 | * 55 | * @return true/false 56 | * @since 1.13 57 | */ 58 | public boolean isAscending() { 59 | return this.equals(ASC); 60 | } 61 | 62 | /** 63 | * Returns whether the direction is descending. 64 | * 65 | * @return true/false 66 | * @since 1.13 67 | */ 68 | public boolean isDescending() { 69 | return this.equals(DESC); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/constant/QueryJudgeType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.constant; 2 | 3 | /** 4 | * 查询条件判断类型 5 | * 6 | * @author Zhang Peng 7 | * @since 2019-12-17 8 | */ 9 | public enum QueryJudgeType { 10 | Equals, 11 | NotEquals, 12 | Like, 13 | NotLike, 14 | In, 15 | NotIn, 16 | IsNull, 17 | IsNotNull, 18 | } 19 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/constant/QueryLogicType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.constant; 2 | 3 | /** 4 | * 查询条件逻辑类型 5 | * 6 | * @author Zhang Peng 7 | * @since 2019-12-17 8 | */ 9 | public enum QueryLogicType { 10 | AND, 11 | OR 12 | } 13 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/desensitized/annotation/Desensitized.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.desensitized.annotation; 2 | 3 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import io.github.dunwu.tool.data.desensitized.DesensitizedSerializer; 6 | import io.github.dunwu.tool.data.desensitized.constant.SensitiveTypeEnum; 7 | 8 | import java.lang.annotation.ElementType; 9 | import java.lang.annotation.Inherited; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | /** 15 | * 数据脱敏注解 16 | *

17 | * 注:需要配合 {@link NeedDesensitized} 使用,只有被标记 {@link NeedDesensitized} 的类,脱敏工具 {@link DesensitizedSerializer} 18 | * 才会去扫描是否存在被标记为 {@link Desensitized} 的字段 19 | * 20 | * @author Zhang Peng 21 | * @date 2022-11-04 22 | */ 23 | @Inherited 24 | @Target(ElementType.FIELD) 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @JacksonAnnotationsInside // 表示自定义自己的注解PrivacyEncrypt 27 | @JsonSerialize(using = DesensitizedSerializer.class) // 该注解使用序列化的方式 28 | public @interface Desensitized { 29 | 30 | /** 31 | * 脱敏类型(规则) 32 | */ 33 | SensitiveTypeEnum type() default SensitiveTypeEnum.NONE; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/desensitized/annotation/NeedDesensitized.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.desensitized.annotation; 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 | * 脱敏标记注解 10 | * 11 | * @author Zhang Peng 12 | * @date 2022-11-04 13 | */ 14 | @Target({ ElementType.TYPE, ElementType.METHOD }) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface NeedDesensitized { 17 | } 18 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/desensitized/constant/SensitiveTypeEnum.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.desensitized.constant; 2 | 3 | /** 4 | * 敏感数据脱敏类型 5 | * 6 | * @author Zhang Peng 7 | * @date 2022-11-04 8 | */ 9 | public enum SensitiveTypeEnum { 10 | /** 11 | * 所有字符都脱敏 12 | */ 13 | ALL, 14 | /** 15 | * 直接展示为 null 16 | */ 17 | NONE, 18 | /** 19 | * 中文名 20 | */ 21 | CHINESE_NAME, 22 | /** 23 | * 身份证号 24 | */ 25 | ID_CARD, 26 | /** 27 | * 座机号 28 | */ 29 | FIXED_PHONE, 30 | /** 31 | * 手机号 32 | */ 33 | MOBILE_PHONE, 34 | /** 35 | * 地址 36 | */ 37 | ADDRESS, 38 | /** 39 | * 电子邮件 40 | */ 41 | EMAIL, 42 | /** 43 | * 密码 44 | */ 45 | PASSWORD, 46 | /** 47 | * 车牌号 48 | */ 49 | CAR_LICENSE, 50 | /** 51 | * 银行卡 52 | */ 53 | BANK_CARD; 54 | } 55 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/elasticsearch/annotation/QueryDocument.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.elasticsearch.annotation; 2 | 3 | import io.github.dunwu.tool.bean.support.NamingStrategy; 4 | import io.github.dunwu.tool.data.constant.OrderType; 5 | import org.springframework.data.annotation.Persistent; 6 | 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Inherited; 9 | import java.lang.annotation.Retention; 10 | import java.lang.annotation.RetentionPolicy; 11 | import java.lang.annotation.Target; 12 | 13 | /** 14 | * ElasticSearch 查询注解 15 | * 16 | * @author Zhang Peng 17 | * @since 2019-12-17 18 | */ 19 | @Persistent 20 | @Inherited 21 | @Retention(RetentionPolicy.RUNTIME) 22 | @Target({ ElementType.TYPE }) 23 | public @interface QueryDocument { 24 | 25 | NamingStrategy namingStrategy() default NamingStrategy.LOWER_UNDERLINE; 26 | 27 | String[] orderItem() default {}; 28 | 29 | OrderType orderType() default OrderType.ASC; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/elasticsearch/annotation/QueryField.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.elasticsearch.annotation; 2 | 3 | import io.github.dunwu.tool.data.constant.QueryJudgeType; 4 | 5 | import java.lang.annotation.Documented; 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Inherited; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | /** 13 | * @author Zhang Peng 14 | * @since 2019-12-17 15 | */ 16 | @Documented 17 | @Inherited 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Target(ElementType.FIELD) 20 | public @interface QueryField { 21 | 22 | String value() default ""; 23 | 24 | QueryJudgeType judgeType() default QueryJudgeType.Equals; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/entity/TableColumnInfo.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | /** 10 | * @author Zhang Peng 11 | * @date 2022-11-29 12 | */ 13 | @Data 14 | @Builder 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class TableColumnInfo { 18 | 19 | /** Schema 名称 */ 20 | @JsonProperty("schemaName") 21 | private String tableSchema; 22 | 23 | /** 表名称 */ 24 | private String tableName; 25 | 26 | /** 字段名称 */ 27 | private String columnName; 28 | 29 | /** 字段备注 */ 30 | private String columnComment; 31 | 32 | /** 字段数据类型 */ 33 | private String dataType; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/entity/TableInfo.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.time.LocalDateTime; 11 | 12 | /** 13 | * 表的数据信息 14 | * 15 | * @author Zhang Peng 16 | * @since 2021-03-07 17 | */ 18 | @Data 19 | @Builder 20 | @NoArgsConstructor 21 | @AllArgsConstructor 22 | public class TableInfo { 23 | 24 | /** Schema 名称 */ 25 | @JsonProperty("schemaName") 26 | private String tableSchema; 27 | 28 | /** 表名称 */ 29 | private String tableName; 30 | 31 | /** 数据库引擎 */ 32 | private String engine; 33 | 34 | /** 编码集 */ 35 | @JsonProperty("coding") 36 | private String tableCollation; 37 | 38 | /** 注释 */ 39 | @JsonProperty("comment") 40 | private String tableComment; 41 | 42 | /** 创建日期 */ 43 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 44 | private LocalDateTime createTime; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/hdfs/HdfsConfig.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.hdfs; 2 | 3 | import lombok.Data; 4 | import lombok.ToString; 5 | import lombok.experimental.Accessors; 6 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; 7 | import org.apache.hadoop.fs.FileSystem; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * Hdfs 配置选项 13 | * 14 | * @author Zhang Peng 15 | * @since 2020-03-21 16 | */ 17 | @Data 18 | @ToString 19 | @Accessors(chain = true) 20 | public class HdfsConfig implements Serializable { 21 | 22 | public static final String HDFS_DEFAULT_URL_KEY = "fs.defaultFS"; 23 | 24 | public static final String HDFS_DEFAULT_URL = "hdfs://localhost:9000"; 25 | 26 | public static final String HDFS_DEFAULT_USER_NAME = "hdfs"; 27 | 28 | private static final long serialVersionUID = -5434086838792181903L; 29 | 30 | protected final Pool pool = new Pool(); 31 | 32 | protected String url = HDFS_DEFAULT_URL; 33 | 34 | protected String user = HDFS_DEFAULT_USER_NAME; 35 | 36 | public static class Pool extends GenericObjectPoolConfig { } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/hdfs/HdfsPool.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.hdfs; 2 | 3 | import org.apache.commons.pool2.impl.AbandonedConfig; 4 | import org.apache.commons.pool2.impl.GenericObjectPool; 5 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; 6 | import org.apache.hadoop.fs.FileSystem; 7 | 8 | /** 9 | * Hdfs 连接池工具,基于 common-pool2 的 {@link GenericObjectPool} 实现,需要配合 {@link HdfsFactory} 使用 10 | * 11 | * @author Zhang Peng 12 | * @since 2020-03-21 13 | */ 14 | public class HdfsPool extends GenericObjectPool { 15 | 16 | public HdfsPool(final HdfsFactory factory) { 17 | super(factory); 18 | } 19 | 20 | public HdfsPool(final HdfsFactory factory, final GenericObjectPoolConfig config) { 21 | super(factory, config); 22 | } 23 | 24 | public HdfsPool(final HdfsFactory factory, final GenericObjectPoolConfig config, 25 | final AbandonedConfig abandonedConfig) { 26 | super(factory, config, abandonedConfig); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/BaseExtDaoImpl.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.mybatis; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.Wrapper; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import io.github.dunwu.tool.data.mybatis.util.MybatisPlusUtil; 7 | import org.springframework.data.domain.Pageable; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * {@link IExtDao} 基本实现类 13 | * 14 | * @author Zhang Peng 15 | * @since 2020-04-07 16 | */ 17 | public abstract class BaseExtDaoImpl, E> extends DaoImpl 18 | implements IExtDao { 19 | 20 | @Override 21 | public Integer countByQuery(Object query) { 22 | return baseMapper.selectCount(MybatisPlusUtil.buildQueryWrapper(query)); 23 | } 24 | 25 | @Override 26 | public E getByQuery(Object query) { 27 | return baseMapper.selectOne(MybatisPlusUtil.buildQueryWrapper(query)); 28 | } 29 | 30 | @Override 31 | public List listByQuery(Object query) { 32 | return baseMapper.selectList(MybatisPlusUtil.buildQueryWrapper(query)); 33 | } 34 | 35 | @Override 36 | public org.springframework.data.domain.Page springPage(Pageable pageable, Wrapper wrapper) { 37 | Page queryPage = MybatisPlusUtil.toMybatisPlusPage(pageable); 38 | Page page = page(queryPage, wrapper); 39 | return MybatisPlusUtil.toSpringPage(page); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/BaseRecordEntity.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.mybatis; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | import lombok.experimental.Accessors; 9 | 10 | import java.io.Serializable; 11 | import java.time.LocalDateTime; 12 | 13 | /** 14 | * 基础记录数据库实体类 15 | * 16 | * @author Zhang Peng 17 | * @since 2019-04-27 18 | */ 19 | @Data 20 | @Accessors(chain = true) 21 | public abstract class BaseRecordEntity implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @ApiModelProperty(value = "ID") 26 | @TableId(value = "id", type = IdType.AUTO) 27 | protected Long id; 28 | 29 | @ApiModelProperty(value = "是否禁用,1表示禁用,0表示启用") 30 | protected Boolean isDisabled; 31 | 32 | @ApiModelProperty(value = "备注") 33 | protected String note; 34 | 35 | @ApiModelProperty(value = "创建者") 36 | protected Long createBy; 37 | 38 | @ApiModelProperty(value = "更新者") 39 | protected Long updateBy; 40 | 41 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 42 | @ApiModelProperty(value = "创建时间") 43 | protected LocalDateTime createTime; 44 | 45 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 46 | @ApiModelProperty(value = "更新时间") 47 | protected LocalDateTime updateTime; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/DaoInfo.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.mybatis; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * Dao 信息实体 7 | * 8 | * @author Zhang Peng 9 | * @date 2022-12-14 10 | */ 11 | @Data 12 | public class DaoInfo { 13 | 14 | private String schemaName; 15 | 16 | private String tableName; 17 | 18 | private String description; 19 | 20 | private Class entityClass; 21 | 22 | private String entityClassName; 23 | 24 | private Class daoClass; 25 | 26 | private String daoClassName; 27 | 28 | private Class mapperClass; 29 | 30 | private String mapperClassName; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/IService.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.mybatis; 2 | 3 | import io.github.dunwu.tool.data.request.PageQuery; 4 | import org.springframework.data.domain.PageRequest; 5 | 6 | public interface IService { 7 | 8 | PageRequest toPageRequest(PageQuery query); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/ServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.mybatis; 2 | 3 | import cn.hutool.core.collection.CollectionUtil; 4 | import io.github.dunwu.tool.data.request.PageQuery; 5 | import io.github.dunwu.tool.data.util.PageUtil; 6 | import org.springframework.data.domain.PageRequest; 7 | import org.springframework.data.domain.Sort; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * {@link IService} 实现类( 泛型:M 是 mapper 对象,T 是实体 ) 14 | * 15 | * @author Zhang Peng 16 | * @since 2020-04-26 17 | */ 18 | public class ServiceImpl implements IService { 19 | 20 | @Override 21 | public PageRequest toPageRequest(PageQuery query) { 22 | 23 | if (query == null) { 24 | return null; 25 | } 26 | 27 | int page = 0; 28 | if (query.getPage() > 1) { 29 | page = query.getPage() - 1; 30 | } 31 | 32 | Sort sort = null; 33 | if (CollectionUtil.isNotEmpty(query.getSort())) { 34 | List list = query.getSort(); 35 | if (list.get(0).contains(",")) { 36 | sort = PageUtil.getSort(list); 37 | } else { 38 | sort = getOrdersForOneSort(query.getSort()); 39 | } 40 | } 41 | 42 | if (sort == null) { 43 | return PageRequest.of(page, query.getSize()); 44 | } 45 | return PageRequest.of(page, query.getSize(), sort); 46 | } 47 | 48 | private Sort getOrdersForOneSort(List list) { 49 | if (CollectionUtil.isEmpty(list)) { 50 | return null; 51 | } 52 | 53 | int i = 0; 54 | List orders = new ArrayList<>(); 55 | while (i + 1 < list.size()) { 56 | Sort.Direction direction = Sort.Direction.fromString(list.get(i + 1)); 57 | Sort.Order order = new Sort.Order(direction, list.get(i)); 58 | orders.add(order); 59 | i = i + 2; 60 | } 61 | return Sort.by(orders); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Mybatis 扩展工具 3 | *

4 | * 使用此 package 工具类,需要引入 mybatis-plus、等 jar 5 | * 6 | * @author Zhang Peng 7 | * @since 2019-12-18 8 | */ 9 | package io.github.dunwu.tool.data.mybatis; 10 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/p6spy/P6spySlf4jLogger.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.p6spy; 2 | 3 | import com.p6spy.engine.logging.Category; 4 | import com.p6spy.engine.spy.appender.FormattedLogger; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | /** 9 | * 自定义 p6spy 日志输出器 10 | * 11 | * @author Zhang Peng 12 | * @since 2020-03-16 13 | */ 14 | public class P6spySlf4jLogger extends FormattedLogger { 15 | 16 | private Logger log = LoggerFactory.getLogger("p6spy"); 17 | 18 | public P6spySlf4jLogger() { } 19 | 20 | @Override 21 | public void logException(Exception e) { 22 | log.error("", e); 23 | } 24 | 25 | @Override 26 | public void logText(String text) { 27 | log.info(text); 28 | } 29 | 30 | @Override 31 | public boolean isCategoryEnabled(Category category) { 32 | return true; 33 | } 34 | 35 | @Override 36 | public void logSQL(int connectionId, String now, long elapsed, Category category, String prepared, String sql, 37 | String url) { 38 | String msg = this.strategy.formatMessage(connectionId, now, elapsed, category.toString(), prepared, sql, url); 39 | if (log.isDebugEnabled()) { 40 | log.debug(msg); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/p6spy/P6spySqlFormat.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.p6spy; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import com.p6spy.engine.spy.appender.MessageFormattingStrategy; 5 | 6 | /** 7 | * 自定义 p6spy sql 输出格式 8 | * 9 | * @author Zhang Peng 10 | * @since 2020-03-16 11 | */ 12 | public class P6spySqlFormat implements MessageFormattingStrategy { 13 | 14 | @Override 15 | public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, 16 | String sql, String url) { 17 | if (StrUtil.isNotBlank(sql)) { 18 | StringBuilder sb = new StringBuilder(); 19 | sb.append(String.format("耗时:%s ms ", elapsed)) 20 | .append(String.format("执行 SQL:\n%s\n", sql.replaceAll("[\\s]+", StrUtil.SPACE))); 21 | return sb.toString(); 22 | } else { 23 | return StrUtil.EMPTY; 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/util/ReflectionUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.util; 2 | 3 | import cn.hutool.core.util.ReflectUtil; 4 | import org.reflections.Reflections; 5 | 6 | import java.util.Set; 7 | 8 | /** 9 | * @author Zhang Peng 10 | * @date 2022-12-14 11 | */ 12 | public class ReflectionUtil extends ReflectUtil { 13 | 14 | private static final Reflections reflections = new Reflections(); 15 | 16 | public static Set> getSubTypesOf(Class type) { 17 | return reflections.getSubTypesOf(type); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/util/SpringContextHelper.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.util; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * @author Zhang Peng 10 | * @since 2020-03-14 11 | */ 12 | @Component 13 | public class SpringContextHelper implements ApplicationContextAware { 14 | 15 | private static ApplicationContext applicationContext; 16 | 17 | public static boolean containsBean(String name) { 18 | return applicationContext.containsBean(name); 19 | } 20 | 21 | public static T getBean(Class clazz) { 22 | return applicationContext.getBean(clazz); 23 | } 24 | 25 | public static T getBean(String name, Class requiredType) { 26 | return applicationContext.getBean(name, requiredType); 27 | } 28 | 29 | public static Object getBean(String name) { 30 | return applicationContext.getBean(name); 31 | } 32 | 33 | public static Class getType(String name) { 34 | return applicationContext.getType(name); 35 | } 36 | 37 | public static boolean isSingleton(String name) { 38 | return applicationContext.isSingleton(name); 39 | } 40 | 41 | @Override 42 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 43 | SpringContextHelper.applicationContext = applicationContext; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/util/SwaggerUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.util; 2 | 3 | import cn.hutool.core.collection.CollectionUtil; 4 | import cn.hutool.core.util.ReflectUtil; 5 | import io.swagger.annotations.ApiModelProperty; 6 | 7 | import java.lang.reflect.Field; 8 | import java.util.ArrayList; 9 | import java.util.Collection; 10 | import java.util.LinkedHashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * Swagger 工具类 16 | * 17 | * @author Zhang Peng 18 | * @date 2022-11-04 19 | */ 20 | public class SwaggerUtil { 21 | 22 | public static List> getFieldsMapList(Collection list, Class clazz) { 23 | if (CollectionUtil.isNotEmpty(list)) { 24 | return new ArrayList<>(); 25 | } 26 | 27 | if (clazz == null) { 28 | return new ArrayList<>(); 29 | } 30 | 31 | List> mapList = new ArrayList<>(); 32 | for (T item : list) { 33 | Map map = new LinkedHashMap<>(); 34 | Field[] fields = ReflectUtil.getFields(clazz); 35 | for (Field field : fields) { 36 | ApiModelProperty property = field.getAnnotation(ApiModelProperty.class); 37 | if (property != null) { 38 | Object value = ReflectUtil.getFieldValue(item, field); 39 | map.put(property.value(), value); 40 | } 41 | } 42 | mapList.add(map); 43 | } 44 | return mapList; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/validator/IpValidator.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.validator; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import io.github.dunwu.tool.data.validator.annotation.IsIp; 5 | import io.github.dunwu.tool.util.ValidatorUtil; 6 | 7 | import javax.validation.ConstraintValidator; 8 | import javax.validation.ConstraintValidatorContext; 9 | 10 | /** 11 | * @author Zhang Peng 12 | * @since 2020-03-15 13 | */ 14 | public class IpValidator implements ConstraintValidator { 15 | 16 | private IsIp.Type type; 17 | 18 | @Override 19 | public void initialize(IsIp constraintAnnotation) { 20 | type = constraintAnnotation.type(); 21 | } 22 | 23 | @Override 24 | public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) { 25 | if (StrUtil.isBlank(s)) { 26 | return false; 27 | } else { 28 | switch (type) { 29 | case IPv4: 30 | return ValidatorUtil.isIpv4(s); 31 | case IPv6: 32 | return ValidatorUtil.isIpv6(s); 33 | case Any: 34 | return ValidatorUtil.isIpv4(s) || ValidatorUtil.isIpv6(s); 35 | default: 36 | throw new IllegalArgumentException("type must not be null"); 37 | } 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/validator/MobileValidator.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.validator; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import io.github.dunwu.tool.data.validator.annotation.IsMobile; 5 | import io.github.dunwu.tool.util.ValidatorUtil; 6 | 7 | import javax.validation.ConstraintValidator; 8 | import javax.validation.ConstraintValidatorContext; 9 | 10 | /** 11 | * @author Zhang Peng 12 | * @since 2020-03-15 13 | */ 14 | public class MobileValidator implements ConstraintValidator { 15 | 16 | @Override 17 | public void initialize(IsMobile constraintAnnotation) { } 18 | 19 | @Override 20 | public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) { 21 | if (StrUtil.isBlank(s)) { 22 | return false; 23 | } else { 24 | return ValidatorUtil.isMobile(s); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/validator/RegexValidator.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.validator; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import io.github.dunwu.tool.data.validator.annotation.RegexValid; 5 | import io.github.dunwu.tool.util.RegexUtil; 6 | 7 | import javax.validation.ConstraintValidator; 8 | import javax.validation.ConstraintValidatorContext; 9 | 10 | /** 11 | * 正则校验器,配合 {@link RegexValid} 使用 12 | * 13 | * @author Zhang Peng 14 | * @since 2020-03-17 15 | */ 16 | public class RegexValidator implements ConstraintValidator { 17 | 18 | private String regexp; 19 | 20 | @Override 21 | public void initialize(RegexValid constraintAnnotation) { 22 | regexp = constraintAnnotation.regexp(); 23 | } 24 | 25 | @Override 26 | public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) { 27 | 28 | if (StrUtil.isBlank(s)) { 29 | return false; 30 | } 31 | if (StrUtil.isBlank(regexp)) { 32 | throw new IllegalArgumentException("regexp in @RegexValid must not be blank"); 33 | } 34 | 35 | return RegexUtil.matches(s, regexp); 36 | } 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/validator/annotation/AddCheck.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.validator.annotation; 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 | @Target({ ElementType.FIELD, ElementType.PARAMETER }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface AddCheck { } 11 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/validator/annotation/EditCheck.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.validator.annotation; 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 | @Target({ ElementType.FIELD, ElementType.PARAMETER }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface EditCheck { } 11 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/validator/annotation/IsIp.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.validator.annotation; 2 | 3 | import io.github.dunwu.tool.data.validator.MobileValidator; 4 | 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.Target; 7 | import javax.validation.Constraint; 8 | import javax.validation.Payload; 9 | 10 | import static java.lang.annotation.ElementType.*; 11 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 12 | 13 | /** 14 | * 验证被修饰字段、参数字符串是否为 Ip 地址 15 | * 16 | * @author Zhang Peng 17 | * @since 2020-03-17 18 | */ 19 | @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE }) 20 | @Retention(RUNTIME) 21 | @Constraint(validatedBy = MobileValidator.class) 22 | public @interface IsIp { 23 | 24 | String message() default "不是合法 IP 地址"; 25 | 26 | Type type() default Type.Any; 27 | 28 | Class[] groups() default {}; 29 | 30 | Class[] payload() default {}; 31 | 32 | enum Type { 33 | IPv4, 34 | IPv6, 35 | Any 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/validator/annotation/IsMobile.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.validator.annotation; 2 | 3 | import io.github.dunwu.tool.data.validator.MobileValidator; 4 | 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.Target; 7 | import javax.validation.Constraint; 8 | import javax.validation.Payload; 9 | 10 | import static java.lang.annotation.ElementType.*; 11 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 12 | 13 | /** 14 | * 验证被修饰字段、参数字符串是否为手机号 15 | * 16 | * @author Zhang Peng 17 | * @since 2020-03-15 18 | */ 19 | @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE }) 20 | @Retention(RUNTIME) 21 | @Constraint(validatedBy = MobileValidator.class) 22 | public @interface IsMobile { 23 | 24 | String message(); 25 | 26 | Class[] groups() default {}; 27 | 28 | Class[] payload() default {}; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/validator/annotation/RegexValid.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.data.validator.annotation; 2 | 3 | import io.github.dunwu.tool.data.validator.RegexValidator; 4 | 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | import javax.validation.Constraint; 9 | import javax.validation.Payload; 10 | 11 | import static java.lang.annotation.ElementType.*; 12 | 13 | /** 14 | * 正则校验注解 15 | * 16 | * @author Zhang Peng 17 | * @since 2020-03-17 18 | */ 19 | @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE }) 20 | @Retention(RetentionPolicy.RUNTIME) 21 | @Constraint(validatedBy = RegexValidator.class) 22 | public @interface RegexValid { 23 | 24 | String regexp(); 25 | 26 | String message() default "未通过正则校验"; 27 | 28 | Class[] groups() default {}; 29 | 30 | Class[] payload() default {}; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-data/src/test/resources/source.txt: -------------------------------------------------------------------------------- 1 | 这是用于HDFS测试的文件,不要删除 2 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/AbstractDistributedLock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.core; 14 | 15 | import java.time.Instant; 16 | import java.util.Optional; 17 | import javax.validation.constraints.NotNull; 18 | 19 | public abstract class AbstractDistributedLock implements DistributedLock { 20 | 21 | protected final LockConfiguration lockConfiguration; 22 | 23 | private boolean valid = true; 24 | 25 | protected AbstractDistributedLock(LockConfiguration lockConfiguration) { 26 | this.lockConfiguration = lockConfiguration; 27 | } 28 | 29 | @Override 30 | public final void unlock() { 31 | checkValidity(); 32 | doUnlock(); 33 | valid = false; 34 | } 35 | 36 | protected abstract void doUnlock(); 37 | 38 | @Override 39 | public final Optional extend(@NotNull Instant lockMaxTime, @NotNull Instant lockMinTime) { 40 | checkValidity(); 41 | Optional result = 42 | doExtend(new LockConfiguration(lockConfiguration.getName(), lockMaxTime, lockMinTime)); 43 | valid = false; 44 | return result; 45 | } 46 | 47 | protected Optional doExtend(LockConfiguration newConfiguration) { 48 | throw new UnsupportedOperationException(); 49 | } 50 | 51 | private void checkValidity() { 52 | if (!valid) { 53 | throw new IllegalStateException("Lock is not valid, it has already been unlocked or extended"); 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/AbstractStorageAccessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.core; 14 | 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | public abstract class AbstractStorageAccessor implements StorageAccessor { 19 | 20 | protected final Logger logger = LoggerFactory.getLogger(getClass()); 21 | 22 | protected String getHostname() { 23 | return Utils.getHostname(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/DistributedLock.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.dlock.core; 2 | 3 | import java.time.Instant; 4 | import java.util.Optional; 5 | import javax.validation.constraints.NotNull; 6 | 7 | public interface DistributedLock { 8 | 9 | /** 10 | * Unlocks the lock. Once you unlock it, you should not use for any other operation. 11 | * 12 | * @throws IllegalStateException if the lock has already been unlocked or extended 13 | */ 14 | void unlock(); 15 | 16 | /** 17 | * Extends the lock. If the lock can be extended a new lock is returned. After calling extend, no other operation 18 | * can be called on current lock. 19 | *

20 | * This method is NOT supported by all lock providers. 21 | * 22 | * @return a new lock or empty optional if the lock can not be extended 23 | * @throws IllegalStateException if the lock has already been unlocked or extended 24 | * @throws UnsupportedOperationException if the lock extension is not supported by LockProvider. 25 | */ 26 | @NotNull 27 | default Optional extend(@NotNull Instant lockMaxTime, @NotNull Instant lockMinTime) { 28 | throw new UnsupportedOperationException(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/LockAssert.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.core; 14 | 15 | import javax.validation.constraints.NotNull; 16 | 17 | /** 18 | * Asserts lock presence. The Spring ecosystem is so complicated, so one can not be sure that the lock is applied. This 19 | * class makes sure that the task is indeed locked. 20 | *

21 | * If you use AOP with Kotlin, it does not have to work due to final methods, if you use TaskExecutor wrapper, it can be 22 | * broken by Sleuth,. 23 | */ 24 | public class LockAssert { 25 | 26 | private static final ThreadLocal CURRENT_LOCK_NAME = ThreadLocal.withInitial(() -> null); 27 | 28 | /** 29 | * Throws an exception if the lock is not present. 30 | */ 31 | public static void assertLocked() { 32 | if (CURRENT_LOCK_NAME.get() == null) { 33 | throw new IllegalStateException("The task is not locked."); 34 | } 35 | } 36 | 37 | static void startLock(String name) { 38 | CURRENT_LOCK_NAME.set(name); 39 | } 40 | 41 | static boolean alreadyLockedBy(@NotNull String name) { 42 | return name.equals(CURRENT_LOCK_NAME.get()); 43 | } 44 | 45 | static void endLock() { 46 | CURRENT_LOCK_NAME.remove(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/LockConfigurationExtractor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.core; 14 | 15 | import java.util.Optional; 16 | import javax.validation.constraints.NotNull; 17 | 18 | /** 19 | * Extracts lock parameters from the task. 20 | */ 21 | public interface LockConfigurationExtractor { 22 | 23 | @NotNull 24 | Optional getLockConfiguration(@NotNull Runnable task); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/LockException.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.dlock.core; 2 | 3 | public class LockException extends RuntimeException { 4 | 5 | public LockException(String message) { 6 | super(message); 7 | } 8 | 9 | public LockException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/LockManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.core; 14 | 15 | import javax.validation.constraints.NotNull; 16 | 17 | /** 18 | * Executes task if not locked. 19 | */ 20 | public interface LockManager { 21 | 22 | void executeWithLock(@NotNull Runnable task); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/LockProvider.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.dlock.core; 2 | 3 | import java.time.Instant; 4 | import java.time.temporal.ChronoUnit; 5 | import java.util.Optional; 6 | import javax.validation.constraints.NotBlank; 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * 分布式锁接口 11 | */ 12 | public interface LockProvider { 13 | 14 | /** 15 | * @param name 锁名称 16 | * @param lockMaxTime 锁定最长时间 17 | * @return 如果获取成功,返回持有的锁;失败则返回空。其中,{@link DistributedLock} 包含了释放锁的方法 18 | */ 19 | default Optional lock(@NotBlank String name, Instant lockMaxTime) { 20 | LockConfiguration lockConfiguration = new LockConfiguration(name, lockMaxTime, Instant.now()); 21 | return lock(lockConfiguration); 22 | } 23 | 24 | /** 25 | * @param lockConfiguration 锁的配置信息,{@link LockConfiguration} 26 | * @return 如果获取成功,返回持有的锁;失败则返回空。其中,{@link DistributedLock} 包含了释放锁的方法 27 | */ 28 | @NotNull 29 | Optional lock(@NotNull LockConfiguration lockConfiguration); 30 | 31 | /** 32 | * @param name 锁名称 33 | * @param lockMaxTime 锁定最长时间 34 | * @param unit 时间单位 35 | * @return 如果获取成功,返回持有的锁;失败则返回空。其中,{@link DistributedLock} 包含了释放锁的方法 36 | */ 37 | default Optional lock(@NotBlank String name, long lockMaxTime, ChronoUnit unit) { 38 | Instant maxTime = Instant.now().plus(lockMaxTime, unit); 39 | LockConfiguration lockConfiguration = new LockConfiguration(name, maxTime, Instant.now()); 40 | return lock(lockConfiguration); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/LockRecordRegistry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.core; 14 | 15 | import java.util.Collections; 16 | import java.util.Set; 17 | import java.util.WeakHashMap; 18 | 19 | /** 20 | * Some LockProviders have to decide if a new record has to be created or an old one updated. This class helps them keep 21 | * track of existing lock records, so they know if a lock record exists. 22 | */ 23 | class LockRecordRegistry { 24 | 25 | private final Set lockRecords = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>())); 26 | 27 | public void addLockRecord(String lockName) { 28 | lockRecords.add(lockName); 29 | } 30 | 31 | public boolean lockRecordRecentlyCreated(String lockName) { 32 | return lockRecords.contains(lockName); 33 | } 34 | 35 | public void clear() { 36 | lockRecords.clear(); 37 | } 38 | 39 | int getSize() { 40 | return lockRecords.size(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/LockableRunnable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.core; 14 | 15 | import javax.validation.constraints.NotNull; 16 | 17 | import static java.util.Objects.requireNonNull; 18 | 19 | /** 20 | * Executes wrapped runnable using {@link LockManager#executeWithLock(Runnable)} 21 | */ 22 | public class LockableRunnable implements Runnable { 23 | 24 | private final Runnable task; 25 | 26 | private final LockManager lockManager; 27 | 28 | public LockableRunnable(@NotNull Runnable task, @NotNull LockManager lockManager) { 29 | this.task = requireNonNull(task); 30 | this.lockManager = requireNonNull(lockManager); 31 | } 32 | 33 | @Override 34 | public void run() { 35 | lockManager.executeWithLock(task); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/main/java/io/github/dunwu/tool/dlock/core/StorageAccessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.core; 14 | 15 | import javax.validation.constraints.NotNull; 16 | 17 | public interface StorageAccessor { 18 | 19 | /** 20 | * Inserts a record, if it does not already exists. If it exists, returns false. 21 | * 22 | * @param lockConfiguration LockConfiguration 23 | * @return true if inserted 24 | */ 25 | boolean insertRecord(@NotNull LockConfiguration lockConfiguration); 26 | 27 | /** 28 | * Tries to update the lock record. If there is already a valid lock record (the lock is held by someone else) 29 | * update should not do anything and this method returns false. 30 | * 31 | * @param lockConfiguration LockConfiguration 32 | * @return true if updated 33 | */ 34 | boolean updateRecord(@NotNull LockConfiguration lockConfiguration); 35 | 36 | void unlock(@NotNull LockConfiguration lockConfiguration); 37 | 38 | default boolean extend(@NotNull LockConfiguration lockConfiguration) { 39 | throw new UnsupportedOperationException(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/test/java/io/github/dunwu/tool/dlock/provider/H2JdbcTemplateLockProviderIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.provider; 14 | 15 | import io.github.dunwu.tool.dlock.core.StorageBasedLockProvider; 16 | import io.github.dunwu.tool.dlock.test.support.AbstractJdbcLockProviderIntegrationTest; 17 | import io.github.dunwu.tool.dlock.test.support.DbConfig; 18 | import org.springframework.jdbc.core.JdbcTemplate; 19 | 20 | public class H2JdbcTemplateLockProviderIntegrationTest extends AbstractJdbcLockProviderIntegrationTest { 21 | 22 | private static final H2Config dbConfig = new H2Config(); 23 | 24 | @Override 25 | protected DbConfig getDbConfig() { 26 | return dbConfig; 27 | } 28 | 29 | @Override 30 | protected StorageBasedLockProvider getLockProvider() { 31 | return new JdbcTemplateLockProvider(JdbcTemplateLockProvider.Configuration.builder() 32 | .withJdbcTemplate(new JdbcTemplate(getDatasource())) 33 | .build() 34 | ); 35 | } 36 | 37 | static class H2Config implements DbConfig { 38 | 39 | public void startDb() { 40 | } 41 | 42 | public void shutdownDb() { 43 | } 44 | 45 | public String getJdbcUrl() { 46 | return "jdbc:h2:mem:test"; 47 | } 48 | 49 | @Override 50 | public String getUsername() { 51 | return "SA"; 52 | } 53 | 54 | @Override 55 | public String getPassword() { 56 | return ""; 57 | } 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/test/java/io/github/dunwu/tool/dlock/provider/JedisLockProviderIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.dlock.provider; 2 | 3 | import org.springframework.data.redis.connection.RedisConnectionFactory; 4 | import org.springframework.data.redis.connection.RedisStandaloneConfiguration; 5 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; 6 | 7 | public class JedisLockProviderIntegrationTest extends AbstractRedisLockProviderIntegrationTest { 8 | 9 | public JedisLockProviderIntegrationTest() { 10 | super(createJedisConnectionFactory()); 11 | } 12 | 13 | private static RedisConnectionFactory createJedisConnectionFactory() { 14 | RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(HOST, PORT); 15 | return new JedisConnectionFactory(redisStandaloneConfiguration); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/test/java/io/github/dunwu/tool/dlock/provider/LetucceLockProviderIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.dlock.provider; 2 | 3 | import org.springframework.data.redis.connection.RedisConnectionFactory; 4 | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; 5 | 6 | public class LetucceLockProviderIntegrationTest extends AbstractRedisLockProviderIntegrationTest { 7 | 8 | public LetucceLockProviderIntegrationTest() { 9 | super(createLettuceConnectionFactory()); 10 | } 11 | 12 | private static RedisConnectionFactory createLettuceConnectionFactory() { 13 | LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(HOST, PORT); 14 | lettuceConnectionFactory.afterPropertiesSet(); 15 | return lettuceConnectionFactory; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/test/java/io/github/dunwu/tool/dlock/test/support/AbstractStorageBasedLockProviderIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.test.support; 14 | 15 | import io.github.dunwu.tool.dlock.core.DistributedLock; 16 | import io.github.dunwu.tool.dlock.core.LockConfiguration; 17 | import io.github.dunwu.tool.dlock.core.StorageBasedLockProvider; 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.util.Optional; 21 | 22 | import static org.assertj.core.api.Assertions.assertThat; 23 | 24 | public abstract class AbstractStorageBasedLockProviderIntegrationTest 25 | extends AbstractExtensibleLockProviderIntegrationTest { 26 | 27 | @Test 28 | public void lockShouldSurviveCacheClearingInTheMiddle() { 29 | StorageBasedLockProvider provider = getLockProvider(); 30 | 31 | LockConfiguration configuration = lockConfig(LOCK_NAME1); 32 | Optional lock = provider.lock(configuration); 33 | assertThat(lock).isPresent(); 34 | 35 | provider.clearCache(); 36 | 37 | // lock is still locked 38 | assertThat(provider.lock(lockConfig(LOCK_NAME1))).isEmpty(); 39 | 40 | lock.get().unlock(); 41 | } 42 | 43 | @Override 44 | protected abstract StorageBasedLockProvider getLockProvider(); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/test/java/io/github/dunwu/tool/dlock/test/support/DbConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.test.support; 14 | 15 | import java.io.IOException; 16 | 17 | public interface DbConfig { 18 | 19 | void startDb() throws IOException; 20 | 21 | void shutdownDb(); 22 | 23 | String getJdbcUrl(); 24 | 25 | String getUsername(); 26 | 27 | String getPassword(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/test/java/io/github/dunwu/tool/dlock/test/support/JdbcTestUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.test.support; 14 | 15 | import com.zaxxer.hikari.HikariDataSource; 16 | import org.springframework.jdbc.core.JdbcTemplate; 17 | 18 | import javax.sql.DataSource; 19 | 20 | public class JdbcTestUtils { 21 | 22 | private final HikariDataSource datasource; 23 | 24 | private final JdbcTemplate jdbcTemplate; 25 | 26 | JdbcTestUtils(DbConfig dbConfig) { 27 | datasource = new HikariDataSource(); 28 | datasource.setJdbcUrl(dbConfig.getJdbcUrl()); 29 | datasource.setUsername(dbConfig.getUsername()); 30 | datasource.setPassword(dbConfig.getPassword()); 31 | 32 | jdbcTemplate = new JdbcTemplate(datasource); 33 | String sql = "CREATE TABLE IF NOT EXISTS `dunwulock` (\n" 34 | + " `name` VARCHAR(64),\n" 35 | + " `lock_until` TIMESTAMP(3) NULL,\n" 36 | + " `locked_at` TIMESTAMP(3) NULL,\n" 37 | + " `locked_by` VARCHAR(255),\n" 38 | + " PRIMARY KEY (`name`)\n" 39 | + ");\n"; 40 | jdbcTemplate.execute(sql); 41 | } 42 | 43 | public JdbcTemplate getJdbcTemplate() { 44 | return jdbcTemplate; 45 | } 46 | 47 | public DataSource getDatasource() { 48 | return datasource; 49 | } 50 | 51 | void clean() { 52 | jdbcTemplate.execute("DROP TABLE dunwulock"); 53 | datasource.close(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-dlock/src/test/java/io/github/dunwu/tool/dlock/test/support/TransactionalFuzzTester.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2009-2019 the original author or authors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | *

7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | *

9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | package io.github.dunwu.tool.dlock.test.support; 14 | 15 | import io.github.dunwu.tool.dlock.core.LockProvider; 16 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 17 | import org.springframework.transaction.support.TransactionTemplate; 18 | 19 | import java.util.concurrent.ExecutionException; 20 | import javax.sql.DataSource; 21 | 22 | public class TransactionalFuzzTester { 23 | 24 | public static void fuzzTestShouldWorkWithTransaction(LockProvider lockProvider, DataSource dataSource) 25 | throws ExecutionException, InterruptedException { 26 | new FuzzTester(lockProvider) { 27 | @Override 28 | protected Void task(int iterations) { 29 | TransactionTemplate transactionTemplate = 30 | new TransactionTemplate(new DataSourceTransactionManager(dataSource)); 31 | return transactionTemplate.execute(status -> super.task(iterations)); 32 | } 33 | 34 | @Override 35 | protected boolean shouldLog() { 36 | return true; 37 | } 38 | }.doFuzzTest(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/ICodeGenerator.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.generator; 2 | 3 | import io.github.dunwu.tool.generator.config.*; 4 | import io.github.dunwu.tool.generator.config.po.TableInfo; 5 | import io.github.dunwu.tool.generator.engine.CodeGenerateContentDto; 6 | 7 | import java.util.Collection; 8 | import java.util.List; 9 | import java.util.Properties; 10 | 11 | /** 12 | * 代码生成器模板方法类 13 | * 14 | * @author Zhang Peng 15 | * @since 2019-07-19 16 | */ 17 | public interface ICodeGenerator { 18 | 19 | /** 20 | * 模板方法 21 | */ 22 | void generate(); 23 | 24 | void generate(Collection tables); 25 | 26 | List getPreviewList(); 27 | 28 | /** 29 | * 全局配置 30 | * 31 | * @param properties Properties 32 | * @return {@link GlobalConfig} 33 | */ 34 | GlobalConfig getGlobalConfig(Properties properties); 35 | 36 | /** 37 | * 数据源配置 38 | * 39 | * @param properties Properties 40 | * @return {@link DataSourceConfig} 41 | */ 42 | DataSourceConfig getDataSourceConfig(Properties properties); 43 | 44 | /** 45 | * 包名配置 46 | * 47 | * @param properties Properties 48 | * @return {@link PackageConfig} 49 | */ 50 | PackageConfig getPackageConfig(Properties properties); 51 | 52 | /** 53 | * 策略配置 54 | * 55 | * @param properties Properties 56 | * @param pc PackageConfig 57 | * @return {@link StrategyConfig} 58 | */ 59 | StrategyConfig getStrategyConfig(Properties properties, PackageConfig pc); 60 | 61 | /** 62 | * 自定义配置 63 | * 64 | * @param properties Properties 65 | * @param pc PackageConfig 66 | * @return {@link InjectionConfig} 67 | */ 68 | InjectionConfig getInjectionConfig(Properties properties, PackageConfig pc); 69 | 70 | /** 71 | * 模板配置 72 | * 73 | * @return {@link TemplateConfig} 74 | */ 75 | TemplateConfig getTemplateConfig(); 76 | 77 | } 78 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/FileOutConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config; 17 | 18 | import io.github.dunwu.tool.generator.config.po.TableInfo; 19 | import lombok.Data; 20 | import lombok.experimental.Accessors; 21 | 22 | /** 23 | * 输出文件配置 24 | * 25 | * @author hubin 26 | * @since 2017-01-18 27 | */ 28 | @Data 29 | @Accessors(chain = true) 30 | public abstract class FileOutConfig { 31 | 32 | /** 33 | * 模板 34 | */ 35 | private String templatePath; 36 | 37 | public FileOutConfig() { 38 | // to do nothing 39 | } 40 | 41 | public FileOutConfig(String templatePath) { 42 | this.templatePath = templatePath; 43 | } 44 | 45 | /** 46 | * 输出文件 47 | */ 48 | public abstract String outputFile(TableInfo tableInfo); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/IFileCreate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config; 17 | 18 | import io.github.dunwu.tool.generator.config.builder.ConfigBuilder; 19 | import io.github.dunwu.tool.generator.config.rules.FileType; 20 | 21 | import java.io.File; 22 | 23 | /** 24 | * 文件覆盖接口 25 | * 26 | * @author hubin 27 | * @since 2018-08-07 28 | */ 29 | public interface IFileCreate { 30 | 31 | /** 32 | * 自定义判断是否创建文件 33 | * 34 | * @param configBuilder 配置构建器 35 | * @param fileType 文件类型 36 | * @param filePath 文件路径 37 | * @return ignore 38 | */ 39 | boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath); 40 | 41 | /** 42 | * 检查文件目录,不存在自动递归创建 43 | * 44 | * @param filePath 文件路径 45 | */ 46 | default void checkDir(String filePath) { 47 | File file = new File(filePath); 48 | boolean exist = file.exists(); 49 | if (!exist) { 50 | file.getParentFile().mkdir(); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/INameConvert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config; 17 | 18 | import io.github.dunwu.tool.generator.config.po.TableField; 19 | import io.github.dunwu.tool.generator.config.po.TableInfo; 20 | 21 | /** 22 | * 名称转换接口类 23 | * 24 | * @author hubin 25 | * @since 2017-01-20 26 | */ 27 | public interface INameConvert { 28 | 29 | /** 30 | * 执行实体名称转换 31 | * 32 | * @param tableInfo 表信息对象 33 | * @return 34 | */ 35 | String entityNameConvert(TableInfo tableInfo); 36 | 37 | /** 38 | * 执行属性名称转换 39 | * 40 | * @param field 表字段对象,如果属性表字段命名不一致注意 convert 属性的设置 41 | * @return 42 | */ 43 | String propertyNameConvert(TableField field); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/ITypeConvert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config; 17 | 18 | import io.github.dunwu.tool.generator.config.po.TableField; 19 | import io.github.dunwu.tool.generator.config.rules.IColumnType; 20 | 21 | /** 22 | * 数据库字段类型转换 23 | * 24 | * @author hubin 25 | * @since 2017-01-20 26 | */ 27 | public interface ITypeConvert { 28 | 29 | /** 30 | * 执行类型转换 31 | * 32 | * @param globalConfig 全局配置 33 | * @param tableField 字段列信息 34 | * @return ignore 35 | */ 36 | default IColumnType processTypeConvert(GlobalConfig globalConfig, TableField tableField) { 37 | // 该方法提供重写 38 | return processTypeConvert(globalConfig, tableField.getType()); 39 | } 40 | 41 | /** 42 | * 执行类型转换 43 | * 44 | * @param globalConfig 全局配置 45 | * @param fieldType 字段类型 46 | * @return ignore 47 | */ 48 | IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/builder/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | /** 17 | * 代码生成器,构建类 18 | */ 19 | package io.github.dunwu.tool.generator.config.builder; 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/converts/TypeConvertRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.converts; 17 | 18 | import com.baomidou.mybatisplus.annotation.DbType; 19 | import io.github.dunwu.tool.generator.config.ITypeConvert; 20 | 21 | import java.util.EnumMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * @author nieqiuqiu 26 | * @date 2020-01-09 27 | * @since 3.3.1 28 | */ 29 | public class TypeConvertRegistry { 30 | 31 | private final Map type_convert_enum_map = new EnumMap<>(DbType.class); 32 | 33 | public TypeConvertRegistry() { 34 | type_convert_enum_map.put(DbType.ORACLE, new OracleTypeConvert()); 35 | type_convert_enum_map.put(DbType.SQL_SERVER, new SqlServerTypeConvert()); 36 | type_convert_enum_map.put(DbType.POSTGRE_SQL, new PostgreSqlTypeConvert()); 37 | type_convert_enum_map.put(DbType.DB2, new DB2TypeConvert()); 38 | type_convert_enum_map.put(DbType.SQLITE, new SqliteTypeConvert()); 39 | type_convert_enum_map.put(DbType.DM, new DmTypeConvert()); 40 | type_convert_enum_map.put(DbType.MARIADB, 41 | new MySqlTypeConvert()); 42 | type_convert_enum_map.put(DbType.KINGBASE_ES, new KingbaseESTypeConvert()); 43 | type_convert_enum_map.put(DbType.MYSQL, new MySqlTypeConvert()); 44 | } 45 | 46 | public ITypeConvert getTypeConvert(DbType dbType) { 47 | return type_convert_enum_map.get(dbType); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/converts/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | /** 17 | * 代码生成器,类型转换相关类 18 | */ 19 | package io.github.dunwu.tool.generator.config.converts; 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | /** 17 | * 代码生成器,配置相关类 18 | */ 19 | package io.github.dunwu.tool.generator.config; 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/po/DictInfo.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.generator.config.po; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 字典信息 9 | * 10 | * @author Zhang Peng 11 | * @since 2022-02-13 12 | */ 13 | public class DictInfo { 14 | 15 | /** 字典编码 */ 16 | private String code; 17 | /** 字典名称 */ 18 | private String name; 19 | /** 字典备注 */ 20 | private String note; 21 | /** 格式化字典编码 */ 22 | private String formatCode; 23 | /** 属于字典的字典选项 */ 24 | private List options; 25 | 26 | public DictInfo() { } 27 | 28 | public DictInfo(String code, String name, String note) { 29 | this.code = code; 30 | this.name = name; 31 | this.note = note; 32 | this.formatCode = getFormatCode(code); 33 | } 34 | 35 | public String getCode() { 36 | return code; 37 | } 38 | 39 | public DictInfo setCode(String code) { 40 | this.code = code; 41 | this.formatCode = getFormatCode(code); 42 | return this; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public DictInfo setName(String name) { 50 | this.name = name; 51 | return this; 52 | } 53 | 54 | public String getNote() { 55 | return note; 56 | } 57 | 58 | public DictInfo setNote(String note) { 59 | this.note = note; 60 | return this; 61 | } 62 | 63 | public String getFormatCode() { 64 | return formatCode; 65 | } 66 | 67 | public List getOptions() { 68 | return options; 69 | } 70 | 71 | public DictInfo setOptions(List options) { 72 | this.options = options; 73 | return this; 74 | } 75 | 76 | public static String getFormatCode(String code) { 77 | if (StrUtil.isBlank(code)) { 78 | return null; 79 | } 80 | // 字典名称驼峰命名,首字母大写 81 | String formatCode = StrUtil.toCamelCase(code); 82 | return StrUtil.upperFirst(formatCode); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/po/LikeTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.po; 17 | 18 | import com.baomidou.mybatisplus.core.enums.SqlLike; 19 | import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils; 20 | 21 | /** 22 | * 表名拼接 23 | * 24 | * @author nieqiuqiu 25 | * @date 2019-11-26 26 | * @since 3.3.0 27 | */ 28 | public class LikeTable { 29 | 30 | private String value; 31 | 32 | private SqlLike like = SqlLike.DEFAULT; 33 | 34 | public LikeTable(String value) { 35 | this.value = value; 36 | } 37 | 38 | public LikeTable(String value, SqlLike like) { 39 | this.value = value; 40 | this.like = like; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return getValue(); 46 | } 47 | 48 | public String getValue() { 49 | return SqlUtils.concatLike(this.value, like); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/po/TableFill.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.po; 17 | 18 | import com.baomidou.mybatisplus.annotation.FieldFill; 19 | import lombok.Data; 20 | 21 | /** 22 | * 字段填充 23 | * 24 | * @author hubin 25 | * @since 2017-06-26 26 | */ 27 | @Data 28 | public class TableFill { 29 | 30 | /** 31 | * 字段名称 32 | */ 33 | private String fieldName; 34 | /** 35 | * 忽略类型 36 | */ 37 | private FieldFill fieldFill; 38 | 39 | public TableFill(String fieldName, FieldFill ignore) { 40 | this.fieldName = fieldName; 41 | this.fieldFill = ignore; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/po/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | /** 17 | * 代码生成器,输出相关类 18 | */ 19 | package io.github.dunwu.tool.generator.config.po; 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/querys/AbstractDbQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.querys; 17 | 18 | import io.github.dunwu.tool.generator.config.IDbQuery; 19 | 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | 23 | /** 24 | * 表数据查询抽象类 25 | * 26 | * @author hubin 27 | * @since 2018-01-16 28 | */ 29 | public abstract class AbstractDbQuery implements IDbQuery { 30 | 31 | @Override 32 | public boolean isKeyIdentity(ResultSet results) throws SQLException { 33 | return false; 34 | } 35 | 36 | @Override 37 | public String[] fieldCustom() { 38 | return null; 39 | } 40 | 41 | @Override 42 | public String nullAble() { 43 | return "NULL"; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/querys/DB2Query.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.querys; 17 | 18 | /** 19 | * DB2 表数据查询 20 | * 21 | * @author zhanyao 22 | * @since 2018-05-16 23 | */ 24 | public class DB2Query extends AbstractDbQuery { 25 | 26 | @Override 27 | public String tablesSql() { 28 | return "SELECT * FROM SYSCAT.TABLES where tabschema=%s"; 29 | } 30 | 31 | @Override 32 | public String tableFieldsSql() { 33 | return "SELECT * FROM syscat.columns WHERE tabschema=%s AND tabname='%s'"; 34 | } 35 | 36 | @Override 37 | public String tableName() { 38 | return "TABNAME"; 39 | } 40 | 41 | @Override 42 | public String tableComment() { 43 | return "REMARKS"; 44 | } 45 | 46 | @Override 47 | public String fieldName() { 48 | return "COLNAME"; 49 | } 50 | 51 | @Override 52 | public String fieldType() { 53 | return "TYPENAME"; 54 | } 55 | 56 | @Override 57 | public String fieldComment() { 58 | return "REMARKS"; 59 | } 60 | 61 | @Override 62 | public String fieldKey() { 63 | return "IDENTITY"; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/querys/DbQueryRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.querys; 17 | 18 | import com.baomidou.mybatisplus.annotation.DbType; 19 | import io.github.dunwu.tool.generator.config.IDbQuery; 20 | 21 | import java.util.EnumMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * @author nieqiuqiu 26 | * @date 2020-01-09 27 | * @since 3.3.1 28 | */ 29 | public class DbQueryRegistry { 30 | 31 | private final Map db_query_enum_map = new EnumMap<>(DbType.class); 32 | 33 | public DbQueryRegistry() { 34 | db_query_enum_map.put(DbType.ORACLE, new OracleQuery()); 35 | db_query_enum_map.put(DbType.SQL_SERVER, new SqlServerQuery()); 36 | db_query_enum_map.put(DbType.POSTGRE_SQL, new PostgreSqlQuery()); 37 | db_query_enum_map.put(DbType.DB2, new DB2Query()); 38 | db_query_enum_map.put(DbType.MARIADB, new MariadbQuery()); 39 | db_query_enum_map.put(DbType.H2, new H2Query()); 40 | db_query_enum_map.put(DbType.SQLITE, new SqliteQuery()); 41 | db_query_enum_map.put(DbType.DM, new DMQuery()); 42 | db_query_enum_map.put(DbType.KINGBASE_ES, new KingbaseESQuery()); 43 | db_query_enum_map.put(DbType.MYSQL, new MySqlQuery()); 44 | } 45 | 46 | public IDbQuery getDbQuery(DbType dbType) { 47 | return db_query_enum_map.get(dbType); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/querys/MariadbQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.querys; 17 | 18 | import java.sql.ResultSet; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * MySql 表数据查询 23 | * 24 | * @author hubin 25 | * @since 2018-01-16 26 | */ 27 | public class MariadbQuery extends AbstractDbQuery { 28 | 29 | @Override 30 | public String tablesSql() { 31 | return "show table status WHERE 1=1 "; 32 | } 33 | 34 | @Override 35 | public String tableFieldsSql() { 36 | return "show full fields from `%s`"; 37 | } 38 | 39 | @Override 40 | public String tableName() { 41 | return "NAME"; 42 | } 43 | 44 | @Override 45 | public String tableComment() { 46 | return "COMMENT"; 47 | } 48 | 49 | @Override 50 | public String fieldName() { 51 | return "FIELD"; 52 | } 53 | 54 | @Override 55 | public String fieldType() { 56 | return "TYPE"; 57 | } 58 | 59 | @Override 60 | public String fieldComment() { 61 | return "COMMENT"; 62 | } 63 | 64 | @Override 65 | public String fieldKey() { 66 | return "KEY"; 67 | } 68 | 69 | @Override 70 | public boolean isKeyIdentity(ResultSet results) throws SQLException { 71 | return "auto_increment".equals(results.getString("Extra")); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/querys/MySqlQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.querys; 17 | 18 | import java.sql.ResultSet; 19 | import java.sql.SQLException; 20 | 21 | /** 22 | * MySql 表数据查询 23 | * 24 | * @author hubin 25 | * @since 2018-01-16 26 | */ 27 | public class MySqlQuery extends AbstractDbQuery { 28 | 29 | @Override 30 | public String tablesSql() { 31 | return "show table status WHERE 1=1 "; 32 | } 33 | 34 | @Override 35 | public String tableFieldsSql() { 36 | return "show full fields from `%s`"; 37 | } 38 | 39 | @Override 40 | public String tableName() { 41 | return "NAME"; 42 | } 43 | 44 | @Override 45 | public String tableComment() { 46 | return "COMMENT"; 47 | } 48 | 49 | @Override 50 | public String fieldName() { 51 | return "FIELD"; 52 | } 53 | 54 | @Override 55 | public String fieldType() { 56 | return "TYPE"; 57 | } 58 | 59 | @Override 60 | public String fieldComment() { 61 | return "COMMENT"; 62 | } 63 | 64 | @Override 65 | public String fieldKey() { 66 | return "KEY"; 67 | } 68 | 69 | @Override 70 | public boolean isKeyIdentity(ResultSet results) throws SQLException { 71 | return "auto_increment".equals(results.getString("Extra")); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/querys/SqliteQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.querys; 17 | 18 | /** 19 | * Sqlite 表数据查询 20 | * 21 | * @author chen 22 | * @since 2019-05-08 23 | */ 24 | public class SqliteQuery extends AbstractDbQuery { 25 | 26 | @Override 27 | public String tablesSql() { 28 | return "select * from sqlite_master where type='table'"; 29 | } 30 | 31 | @Override 32 | public String tableFieldsSql() { 33 | return "pragma table_info('%s');"; 34 | } 35 | 36 | @Override 37 | public String tableName() { 38 | return "name"; 39 | } 40 | 41 | @Override 42 | public String tableComment() { 43 | return ""; 44 | } 45 | 46 | @Override 47 | public String fieldName() { 48 | return "name"; 49 | } 50 | 51 | @Override 52 | public String fieldType() { 53 | return "type"; 54 | } 55 | 56 | @Override 57 | public String fieldComment() { 58 | return ""; 59 | } 60 | 61 | @Override 62 | public String fieldKey() { 63 | return "pk"; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/querys/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | /** 17 | * 代码生成器,数据库查询相关类 18 | */ 19 | package io.github.dunwu.tool.generator.config.querys; 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/rules/DateType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.rules; 17 | 18 | /** 19 | * 数据库时间类型 到 实体类时间类型 对应策略 20 | * 21 | * @author miemie 22 | * @since 2018/5/22 23 | */ 24 | public enum DateType { 25 | /** 26 | * 只使用 java.util.date 代替 27 | */ 28 | ONLY_DATE, 29 | /** 30 | * 使用 java.sql 包下的 31 | */ 32 | SQL_PACK, 33 | /** 34 | * 使用 java.time 包下的 35 | *

java8 新的时间类型

36 | */ 37 | TIME_PACK 38 | } 39 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/rules/FileType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.generator.config.rules; 2 | 3 | /** 4 | * 生成文件类型 5 | * 6 | * @author Zhang Peng 7 | * @since 2022-02-13 8 | */ 9 | public enum FileType { 10 | 11 | // 前端文件类型 12 | API("Api", "api_path", "/templates/frontend/api.js"), 13 | LIST("List", "list_path", "/templates/frontend/list.vue"), 14 | FORM("Form", "form_path", "/templates/frontend/form.vue"), 15 | 16 | // 后端文件类型 17 | XML("Xml", "xml_path", "/templates/backend/mapper.xml"), 18 | ENTITY("Entity", "entity_path", "/templates/backend/entity.java"), 19 | DTO("Dto", "dto_path", "/templates/backend/dto.java"), 20 | QUERY("Query", "query_path", "/templates/backend/query.java"), 21 | MAPPER("Mapper", "mapper_path", "/templates/backend/mapper.java"), 22 | DAO("Dao", "dao_path", "/templates/backend/dao.java"), 23 | DAO_IMPL("DaoImpl", "dao_impl_path", "/templates/backend/daoImpl.java"), 24 | SERVICE("Service", "service_path", "/templates/backend/service.java"), 25 | SERVICE_IMPL("ServiceImpl", "service_impl_path", "/templates/backend/serviceImpl.java"), 26 | CONTROLLER("Controller", "controller_path", "/templates/backend/controller.java"), 27 | 28 | OTHER("Other", null, null); 29 | 30 | private final String code; 31 | private final String filePath; 32 | private final String templatePath; 33 | 34 | FileType(String code, String filePath, String templatePath) { 35 | this.code = code; 36 | this.filePath = filePath; 37 | this.templatePath = templatePath; 38 | } 39 | 40 | public String getCode() { 41 | return code; 42 | } 43 | 44 | public String getFilePath() { 45 | return filePath; 46 | } 47 | 48 | public String getTemplatePath() { 49 | return templatePath; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/rules/FormType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.generator.config.rules; 2 | 3 | /** 4 | * 列表控件类型 5 | * 6 | * @author peng.zhang 7 | * @date 2022/1/25 8 | */ 9 | public enum FormType { 10 | Input("Input", "输入框"), 11 | Textarea("Textarea", "文本域输入框"), 12 | InputNumber("InputNumber", "计数器"), 13 | Radio("Radio", "单选框"), 14 | Select("Select", "选择器"), 15 | Switch("Switch", "开关"), 16 | DateTimePicker("DateTimePicker", "日期时间选择器"); 17 | 18 | private final String code; 19 | private final String name; 20 | 21 | FormType(String code, String name) { 22 | this.code = code; 23 | this.name = name; 24 | } 25 | 26 | public String getCode() { 27 | return code; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/rules/IColumnType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package io.github.dunwu.tool.generator.config.rules; 17 | 18 | /** 19 | * 获取实体类字段属性类信息接口 20 | * 21 | * @author miemie 22 | * @since 2018-08-22 23 | */ 24 | public interface IColumnType { 25 | 26 | /** 27 | * 获取字段类型 28 | * 29 | * @return 字段类型 30 | */ 31 | String getType(); 32 | 33 | /** 34 | * 获取字段类型完整名 35 | * 36 | * @return 字段类型完整名 37 | */ 38 | String getPkg(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/rules/ListType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.generator.config.rules; 2 | 3 | /** 4 | * 表单控件类型 5 | * 6 | * @author peng.zhang 7 | * @date 2021/3/23 8 | */ 9 | public enum ListType { 10 | Text("Text", "文本"), 11 | Date("Date", "日期"), 12 | Image("Image", "图片"); 13 | 14 | private final String code; 15 | private final String name; 16 | 17 | ListType(String code, String name) { 18 | this.code = code; 19 | this.name = name; 20 | } 21 | 22 | public String getCode() { 23 | return code; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/rules/ValidateType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.generator.config.rules; 2 | 3 | /** 4 | * 前端校验类型 5 | * 6 | * @author peng.zhang 7 | * @date 2021/3/23 8 | */ 9 | public enum ValidateType { 10 | /** 11 | * 文本校验 12 | */ 13 | STRING("string", "文本校验"), 14 | /** 15 | * 数字校验 16 | */ 17 | NUMBER("number", "数字校验"), 18 | /** 19 | * 布尔校验 20 | */ 21 | BOOLEAN("boolean", "布尔校验"), 22 | /** 23 | * 整数校验 24 | */ 25 | INTEGER("integer", "整型校验"), 26 | /** 27 | * 浮点数校验 28 | */ 29 | FLOAT("float", "浮点数校验"), 30 | /** 31 | * URL校验 32 | */ 33 | URL("url", "URL校验"), 34 | /** 35 | * 邮件校验 36 | */ 37 | EMAIL("email", "邮件校验"); 38 | 39 | private final String code; 40 | private final String desc; 41 | 42 | ValidateType(String code, String desc) { 43 | this.code = code; 44 | this.desc = desc; 45 | } 46 | 47 | public String getCode() { 48 | return code; 49 | } 50 | 51 | public String getDesc() { 52 | return desc; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/config/rules/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2020, baomidou (jobob@qq.com). 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | *

8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | /** 17 | * 代码生成器,规则相关类 18 | */ 19 | package io.github.dunwu.tool.generator.config.rules; 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/engine/CodeGenerateContentDto.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.generator.engine; 2 | 3 | /** 4 | * 模板内容 5 | * 6 | * @author Zhang Peng 7 | * @since 2020-04-30 8 | */ 9 | public class CodeGenerateContentDto { 10 | 11 | private final String name; 12 | private final String content; 13 | 14 | public CodeGenerateContentDto(String name, String content) { 15 | this.name = name; 16 | this.content = content; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public String getContent() { 24 | return content; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/java/io/github/dunwu/tool/generator/util/FreemarkerHelper.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.generator.util; 2 | 3 | import com.baomidou.mybatisplus.core.toolkit.StringPool; 4 | import freemarker.template.Configuration; 5 | import freemarker.template.Template; 6 | import freemarker.template.TemplateException; 7 | import io.github.dunwu.tool.generator.config.ConstVal; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | import java.io.FileOutputStream; 11 | import java.io.IOException; 12 | import java.io.OutputStreamWriter; 13 | import java.io.StringWriter; 14 | import java.util.Map; 15 | 16 | /** 17 | * Freemarker 工具类 18 | * 19 | * @author Zhang Peng 20 | * @since 2022-02-13 21 | */ 22 | @Slf4j 23 | public class FreemarkerHelper { 24 | 25 | public static Configuration getDefaultConfiguration() { 26 | Configuration configuration = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); 27 | configuration.setDefaultEncoding(ConstVal.UTF8); 28 | configuration.setClassForTemplateLoading(FreemarkerHelper.class, StringPool.SLASH); 29 | return configuration; 30 | } 31 | 32 | public static String getMergeContent(Configuration configuration, Map objectMap, 33 | final String templatePath) throws IOException, TemplateException { 34 | /* Get the template (uses cache internally) */ 35 | Template template = configuration.getTemplate(templatePath); 36 | 37 | /* Merge data-model with template */ 38 | StringWriter stringWriter = new StringWriter(); 39 | template.process(objectMap, stringWriter); 40 | String content = stringWriter.toString(); 41 | stringWriter.close(); 42 | return content; 43 | } 44 | 45 | public static void outputFile(Configuration configuration, Map objectMap, String templatePath, 46 | String outputFile) throws IOException, TemplateException { 47 | Template template = configuration.getTemplate(templatePath); 48 | try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) { 49 | template.process(objectMap, new OutputStreamWriter(fileOutputStream, ConstVal.UTF8)); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/resources/templates/backend/dao.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Dao}; 2 | 3 | import ${superDaoClassPackage}; 4 | import ${package.Entity}.${entity}; 5 | 6 | /** 7 | * ${table.comment!} Dao 接口 8 | * 9 | * @author ${author} 10 | * @since ${date} 11 | */ 12 | public interface ${table.daoName} extends ${superDaoClass}<${entity}> { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/resources/templates/backend/daoImpl.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.DaoImpl}; 2 | 3 | import io.github.dunwu.tool.data.annotation.Dao; 4 | import ${superDaoImplClassPackage}; 5 | import ${package.Dao}.${table.daoName}; 6 | import ${package.Mapper}.${table.mapperName}; 7 | import ${package.Entity}.${entity}; 8 | 9 | /** 10 | * ${table.comment!} Dao 类 11 | * 12 | * @author ${author} 13 | * @since ${date} 14 | */ 15 | @Dao 16 | public class ${table.daoImplName} extends ${superDaoImplClass}<${table.mapperName}, ${entity}> implements ${table.daoName} { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/resources/templates/backend/dict.java.ftl: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | import java.util.List; 3 | 4 | /** 5 | * ${dict.note!} 6 | */ 7 | public enum ${dict.formatCode} { 8 | 9 | <#-- ---------- BEGIN 字段循环遍历 ----------> 10 | <#list dict.options as entry> 11 | <#if entry.note!?length gt 0> 12 | /** ${entry.note} */ 13 | 14 | ${entry.code}("${entry.value}", "${entry.name}")<#if entry_has_next>,<#else>; 15 | 16 | 17 | <#------------ END 字段循环遍历 ----------> 18 | private final String code; 19 | private final String name; 20 | 21 | ${dict.formatCode}(String code, String name) { 22 | this.code = code; 23 | this.name = name; 24 | } 25 | 26 | public String getCode() { 27 | return code; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public static ${dict.formatCode} getEnumByCode(String code) { 35 | for (${dict.formatCode} i : ${dict.formatCode}.values()) { 36 | if (i.getCode().equals(code)) { 37 | return i; 38 | } 39 | } 40 | return null; 41 | } 42 | 43 | public static List getEntries() { 44 | List list = new LinkedList<>(); 45 | for (${dict.formatCode} i : ${dict.formatCode}.values()) { 46 | list.add(i.toString()); 47 | } 48 | return list; 49 | } 50 | 51 | public static List getCodes() { 52 | List list = new LinkedList<>(); 53 | for (${dict.formatCode} i : ${dict.formatCode}.values()) { 54 | list.add(i.getCode()); 55 | } 56 | return list; 57 | } 58 | 59 | public static List getNames() { 60 | List list = new LinkedList<>(); 61 | for (${dict.formatCode} i : ${dict.formatCode}.values()) { 62 | list.add(i.getName()); 63 | } 64 | return list; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/resources/templates/backend/mapper.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Mapper}; 2 | 3 | import ${superMapperClassPackage}; 4 | import ${package.Entity}.${entity}; 5 | 6 | /** 7 | * ${table.comment!} Mapper 接口 8 | * 9 | * @author ${author} 10 | * @since ${date} 11 | */ 12 | public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/main/resources/templates/backend/mapper.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <#if enableCache> 6 | 7 | 8 | 9 | 10 | <#if enableBaseResultMap> 11 | 12 | 13 | <#list table.fields as field> 14 | <#if field.keyFlag><#--生成主键排在第一位--> 15 | 16 | 17 | 18 | <#list table.commonFields as field><#--生成公共字段 --> 19 | 20 | 21 | <#list table.fields as field> 22 | <#if !field.keyFlag><#--生成普通字段 --> 23 | 24 | 25 | 26 | 27 | 28 | 29 | <#if enableBaseColumnList> 30 | 31 | 32 | <#list table.commonFields as field> 33 | ${field.fieldName}, 34 | 35 | ${table.fieldNames} 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-generator/src/test/resources/conf/mybatis.properties: -------------------------------------------------------------------------------- 1 | # =============================================================================== 2 | # 数据源配置 3 | # =============================================================================== 4 | spring.datasource.url = jdbc:mysql://localhost:3306/dunwu?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8 5 | spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver 6 | spring.datasource.username = root 7 | spring.datasource.password = root 8 | # =============================================================================== 9 | # Mybatis 配置 10 | # =============================================================================== 11 | mybatis-plus.configuration.default-enum-type-handler = org.apache.ibatis.type.EnumOrdinalTypeHandler 12 | mybatis.generator.gc.output.dir = E:\\Temp 13 | #mybatis.generator.gc.backend.dir = D:/Codes/zp/zjava/dunwu-boot-admin/dunwu-admin/dunwu-admin-modules/dunwu-admin-module-generator 14 | #mybatis.generator.gc.frontend.dir = D:/Codes/zp/zjava/dunwu-boot-admin/dunwu-admin/dunwu-admin-modules/dunwu-admin-module-generator 15 | mybatis.generator.gc.enable.swagger = true 16 | mybatis.generator.gc.author.name = Zhang Peng 17 | mybatis.generator.pc.package.name = io.github.dunwu.module 18 | mybatis.generator.pc.module.name = generator 19 | mybatis.generator.sc.table.name = code_table_config 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-net/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | io.github.dunwu.tool 8 | dunwu-tool 9 | 1.1.2 10 | ../pom.xml 11 | 12 | 13 | dunwu-tool-net 14 | jar 15 | dunwu 网络工具包 16 | https://github.com/dunwu/dunwu-framework/dunwu-tool/dunwu-tool-net 17 | 18 | 19 | 20 | io.github.dunwu.tool 21 | dunwu-tool-core 22 | 23 | 24 | 25 | 26 | 27 | 28 | src/main/resources 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-net/src/main/java/io/github/dunwu/tool/net/ip/Header.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.net.ip; 2 | 3 | public class Header { 4 | 5 | public final int version; 6 | public final int indexPolicy; 7 | public final int createdAt; 8 | public final int startIndexPtr; 9 | public final int endIndexPtr; 10 | public final byte[] buffer; 11 | 12 | public Header(byte[] buff) { 13 | assert buff.length >= 16; 14 | version = Searcher.getInt2(buff, 0); 15 | indexPolicy = Searcher.getInt2(buff, 2); 16 | createdAt = Searcher.getInt(buff, 4); 17 | startIndexPtr = Searcher.getInt(buff, 8); 18 | endIndexPtr = Searcher.getInt(buff, 12); 19 | buffer = buff; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "{" + 25 | "Version: " + version + ',' + 26 | "IndexPolicy: " + indexPolicy + ',' + 27 | "CreatedAt: " + createdAt + ',' + 28 | "StartIndexPtr: " + startIndexPtr + ',' + 29 | "EndIndexPtr: " + endIndexPtr + 30 | '}'; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-net/src/main/java/io/github/dunwu/tool/net/region/County.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.net.region; 2 | 3 | import java.io.Serializable; 4 | import java.util.Objects; 5 | 6 | /** 7 | * @author Zhang Peng 8 | * @since 2018-12-11 9 | */ 10 | public class County implements Comparable, Serializable { 11 | 12 | private static final long serialVersionUID = 7960348116258943881L; 13 | 14 | /** 15 | * 编码 16 | */ 17 | private String code; 18 | 19 | /** 20 | * 名称 21 | */ 22 | private String name; 23 | 24 | /** 25 | * 所属省 26 | */ 27 | private Province province; 28 | 29 | /** 30 | * 所属市 31 | */ 32 | private City city; 33 | 34 | @Override 35 | public int compareTo(County o) { 36 | return this.getCode().compareToIgnoreCase(o.getCode()); 37 | } 38 | 39 | public String getCode() { 40 | return code; 41 | } 42 | 43 | public void setCode(String code) { 44 | this.code = code; 45 | } 46 | 47 | @Override 48 | public int hashCode() { 49 | return Objects.hash(code); 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | if (this == o) { return true; } 55 | if (!(o instanceof County)) { return false; } 56 | County county = (County) o; 57 | return code.equals(county.getCode()); 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "County{" + 63 | "code='" + code + '\'' + 64 | ", name='" + name + '\'' + 65 | '}'; 66 | } 67 | 68 | public String getName() { 69 | return name; 70 | } 71 | 72 | public void setName(String name) { 73 | this.name = name; 74 | } 75 | 76 | public Province getProvince() { 77 | return province; 78 | } 79 | 80 | public void setProvince(Province province) { 81 | this.province = province; 82 | } 83 | 84 | public City getCity() { 85 | return city; 86 | } 87 | 88 | public void setCity(City city) { 89 | this.city = city; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-net/src/main/java/io/github/dunwu/tool/net/region/Province.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.net.region; 2 | 3 | import java.io.Serializable; 4 | import java.util.Objects; 5 | import java.util.Set; 6 | import java.util.TreeSet; 7 | 8 | /** 9 | * @author Zhang Peng 10 | * @since 2018-12-11 11 | */ 12 | public class Province implements Comparable, Serializable { 13 | 14 | private static final long serialVersionUID = 4767006458888002150L; 15 | 16 | /** 17 | * 编码 18 | */ 19 | private String code; 20 | 21 | /** 22 | * 名称 23 | */ 24 | private String name; 25 | 26 | /** 27 | * 下辖城市 28 | */ 29 | private Set children; 30 | 31 | public Province() { 32 | children = new TreeSet<>(); 33 | } 34 | 35 | @Override 36 | public int compareTo(Province o) { 37 | return this.getCode().compareToIgnoreCase(o.getCode()); 38 | } 39 | 40 | public String getCode() { 41 | return code; 42 | } 43 | 44 | public void setCode(String code) { 45 | this.code = code; 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return Objects.hash(code); 51 | } 52 | 53 | @Override 54 | public boolean equals(Object o) { 55 | if (this == o) { return true; } 56 | if (!(o instanceof Province)) { return false; } 57 | Province province = (Province) o; 58 | return code.equals(province.getCode()); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "Province{" + 64 | "code='" + code + '\'' + 65 | ", name='" + name + '\'' + 66 | '}'; 67 | } 68 | 69 | public String getName() { 70 | return name; 71 | } 72 | 73 | public void setName(String name) { 74 | this.name = name; 75 | } 76 | 77 | public Set getChildren() { 78 | return children; 79 | } 80 | 81 | public void setChildren(Set children) { 82 | this.children = children; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-net/src/main/resources/db/ip2region.xdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dunwu/dunwu-framework/HEAD/dunwu-tool/dunwu-tool-net/src/main/resources/db/ip2region.xdb -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-net/src/test/java/io/github/dunwu/tool/net/NetUtilTests.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.net; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.mockito.internal.util.io.IOUtil; 5 | 6 | import java.io.IOException; 7 | import java.net.InetAddress; 8 | import java.net.ServerSocket; 9 | import javax.net.ServerSocketFactory; 10 | 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | import static org.assertj.core.api.Assertions.fail; 13 | 14 | public class NetUtilTests { 15 | 16 | @Test 17 | public void localhost() { 18 | assertThat(NetUtil.getLocalHost()).isNotEqualTo("127.0.0.1"); 19 | assertThat(NetUtil.getLocalAddress().getHostAddress()).isNotEqualTo("127.0.0.1"); 20 | } 21 | 22 | @Test 23 | public void portDetect() throws IOException { 24 | int port = NetUtil.findRandomAvailablePort(20000, 20100); 25 | assertThat(port).isBetween(20000, 20100); 26 | System.out.println("random port:" + port); 27 | 28 | assertThat(NetUtil.isPortAvailable(port)).isTrue(); 29 | 30 | int port2 = NetUtil.findAvailablePortFrom(port); 31 | assertThat(port2).isEqualTo(port); 32 | 33 | int port3 = NetUtil.findRandomAvailablePort(); 34 | 35 | assertThat(port3).isBetween(NetUtil.PORT_RANGE_MIN, NetUtil.PORT_RANGE_MAX); 36 | System.out.println("random port:" + port3); 37 | 38 | // 尝试占住一个端口 39 | ServerSocket serverSocket = null; 40 | try { 41 | serverSocket = ServerSocketFactory.getDefault().createServerSocket(port, 1, 42 | InetAddress.getByName("localhost")); 43 | 44 | assertThat(NetUtil.isPortAvailable(port)).isFalse(); 45 | 46 | int port4 = NetUtil.findAvailablePortFrom(port); 47 | assertThat(port4).isEqualTo(port + 1); 48 | 49 | try { 50 | int port5 = NetUtil.findRandomAvailablePort(port, port); 51 | fail("should fail before"); 52 | } catch (Throwable t) { 53 | assertThat(t).isInstanceOf(IllegalStateException.class); 54 | } 55 | } finally { 56 | IOUtil.close(serverSocket); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-image/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | io.github.dunwu.tool 8 | dunwu-tool 9 | 1.1.2 10 | ../../pom.xml 11 | 12 | 13 | dunwu-tool-image 14 | jar 15 | ${project.artifactId} 16 | 图形处理工具类 17 | 18 | 19 | 20 | io.github.dunwu.tool 21 | dunwu-tool-core 22 | 23 | 24 | net.coobird 25 | thumbnailator 26 | 27 | 28 | cn.hutool 29 | hutool-all 30 | 31 | 32 | commons-io 33 | commons-io 34 | 35 | 36 | ch.qos.logback 37 | logback-classic 38 | true 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-image/src/main/java/io/github/dunwu/tool/image/ImageInfo.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.image; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 图片信息 7 | * 8 | * @author Zhang Peng 9 | * @date 2023-12-14 10 | */ 11 | @Data 12 | public class ImageInfo { 13 | 14 | private Integer width; 15 | private Integer height; 16 | private Long size; 17 | private String format; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-image/src/main/java/io/github/dunwu/tool/image/ImageProperties.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.image; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.ToString; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * 图片处理参数 13 | * 14 | * @author Zhang Peng 15 | * @since 2019-12-10 16 | */ 17 | @Data 18 | @ToString 19 | @Builder 20 | public class ImageProperties implements Serializable { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | private Region source; 25 | 26 | /** 27 | * 图片宽度 28 | */ 29 | private Integer width; 30 | 31 | /** 32 | * 图片高度 33 | */ 34 | private Integer height; 35 | 36 | /** 37 | * 按指定尺寸强制缩放 38 | */ 39 | private Boolean keepAspectRatio; 40 | 41 | /** 42 | * 宽度比例 43 | */ 44 | private Double xscale; 45 | 46 | /** 47 | * 高度比例 48 | */ 49 | private Double yscale; 50 | 51 | /** 52 | * 总比例,相当于将xscale和yscale都设为同比例 53 | */ 54 | private Double scale; 55 | 56 | /** 57 | * 旋转角度,范围为[0.0, 360.0] 58 | */ 59 | private Double rotate; 60 | 61 | /** 62 | * 压缩质量,范围为[0.0, 1.0] 63 | */ 64 | private Double quality; 65 | 66 | /** 67 | * 图片格式,支持jpg,jpeg,png,bmp,gif 68 | */ 69 | private ImageType format; 70 | 71 | /** 72 | * 水印信息 73 | */ 74 | private ImageWaterMark imageWaterMark; 75 | 76 | @Data 77 | @NoArgsConstructor 78 | @AllArgsConstructor 79 | public static class Region { 80 | 81 | private Integer x; 82 | private Integer y; 83 | private Integer width; 84 | private Integer height; 85 | 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-image/src/main/java/io/github/dunwu/tool/image/ImageType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.image; 2 | 3 | /** 4 | * 图片文件类型 5 | * 6 | * @author Zhang Peng 7 | * @since 2019-12-10 8 | */ 9 | public enum ImageType { 10 | png, 11 | jpg, 12 | jpeg, 13 | bmp, 14 | gif 15 | } 16 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-image/src/test/java/io/github/dunwu/tool/image/KaptchaUtilsTest.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.image; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | /** 10 | * @author Zhang Peng 11 | * @since 2019-04-13 12 | */ 13 | class KaptchaUtilsTest { 14 | 15 | static final String OUTPUT_FILE = "D:\\Temp\\kaptcha.png"; 16 | 17 | @Test 18 | void test() { 19 | KaptchaUtils.Kaptcha kaptcha = KaptchaUtils.create(); 20 | System.out.println("验证码的值为:" + kaptcha.getCode()); 21 | try { 22 | KaptchaUtils.toFile(kaptcha, new File(OUTPUT_FILE)); 23 | } catch (IOException e) { 24 | Assertions.fail("生成验证码失败", e); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-image/src/test/resources/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dunwu/dunwu-framework/HEAD/dunwu-tool/dunwu-tool-special/dunwu-tool-image/src/test/resources/images/logo.png -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-image/src/test/resources/images/logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dunwu/dunwu-framework/HEAD/dunwu-tool/dunwu-tool-special/dunwu-tool-image/src/test/resources/images/logo2.png -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-parser/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | io.github.dunwu.tool 8 | dunwu-tool 9 | 1.1.2 10 | ../../pom.xml 11 | 12 | 13 | dunwu-tool-parser 14 | jar 15 | ${project.artifactId} 16 | 包装各种第三方工具包,用于文件解析 17 | 18 | 19 | 20 | io.github.dunwu.tool 21 | dunwu-tool-core 22 | 23 | 24 | 25 | 26 | org.yaml 27 | snakeyaml 28 | 1.30 29 | true 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-parser/src/main/java/io/github/dunwu/tool/parser/git/GitUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.parser.git; 2 | 3 | import cn.hutool.core.collection.CollectionUtil; 4 | import io.github.dunwu.tool.util.RegexUtil; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.File; 8 | import java.io.IOException; 9 | import java.io.InputStreamReader; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * Git 工具 15 | * 16 | * @author Zhang Peng 17 | * @date 2022-04-11 18 | */ 19 | public class GitUtil { 20 | 21 | /** 22 | * 通过调用 Git 命令行工具,获取某 git 仓库下指定文件的第一次创建时间 23 | * 24 | * @param gitProjectPath git 项目目录 25 | * @param filename git 项目中文件的相对路径 26 | * @return 27 | */ 28 | public static String getFileFirstGitPushTime(String gitProjectPath, String filename) { 29 | Process process; 30 | try { 31 | Runtime.getRuntime().exec("git config log.date iso8601"); 32 | process = Runtime.getRuntime().exec("git blame " + filename, null, new File(gitProjectPath)); 33 | BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); 34 | 35 | List lines = new ArrayList<>(); 36 | String line; 37 | while ((line = br.readLine()) != null) { 38 | lines.add(line); 39 | } 40 | 41 | if (CollectionUtil.isEmpty(lines)) { 42 | return null; 43 | } 44 | 45 | String regex = "\\d{4}-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}"; 46 | String lastLine = lines.get(lines.size() - 1); 47 | return RegexUtil.getFirst(lastLine, regex); 48 | } catch (IOException e) { 49 | e.printStackTrace(); 50 | } 51 | 52 | return null; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-parser/src/main/java/io/github/dunwu/tool/parser/yaml/YamlUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.parser.yaml; 2 | 3 | import org.yaml.snakeyaml.Yaml; 4 | 5 | /** 6 | * Yaml 工具类 7 | * 8 | * @author Zhang Peng 9 | * @date 2022-04-27 10 | */ 11 | public class YamlUtil { 12 | 13 | public static T parse(String yamlContent, Class clazz) { 14 | Yaml yaml = new Yaml(); 15 | yaml.load(yamlContent); 16 | return yaml.loadAs(yamlContent, clazz); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-pdf/src/main/resources/fonts/msyh.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dunwu/dunwu-framework/HEAD/dunwu-tool/dunwu-tool-special/dunwu-tool-pdf/src/main/resources/fonts/msyh.ttf -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-pdf/src/test/java/io/github/dunwu/tool/pdf/FreemarkerUtilTest.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.pdf; 2 | 3 | import cn.hutool.core.bean.BeanUtil; 4 | import cn.hutool.core.io.FileUtil; 5 | import org.assertj.core.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | import java.util.Map; 11 | 12 | public class FreemarkerUtilTest { 13 | 14 | @Test 15 | public void test() throws IOException { 16 | 17 | OrderInfo orderInfo = OrderInfo.builder() 18 | .title("账单信息") 19 | .partner("合作伙伴XXX") 20 | .settlementContent("结算内容XXX") 21 | .settlementProduct("结算产品XXX") 22 | .build(); 23 | Map modelMap = BeanUtil.beanToMap(orderInfo); 24 | 25 | String pdfFilePath = "D:\\test.pdf"; 26 | String htmlFilePath = "D:\\temp.html"; 27 | File pdfFile = new File(pdfFilePath); 28 | File htmlFile = null; 29 | try { 30 | // 基于 freemark 模板生成 html 31 | htmlFile = FreemarkerUtil.getMergedFile(modelMap, "template.ftl", htmlFilePath); 32 | Assertions.assertThat(htmlFile).isNotNull(); 33 | Assertions.assertThat(htmlFile.exists()).isTrue(); 34 | 35 | PdfUtil.createPdf(htmlFile, pdfFile); 36 | Assertions.assertThat(pdfFile).isNotNull(); 37 | Assertions.assertThat(pdfFile.exists()).isTrue(); 38 | 39 | // createPdf2(pdfFile, htmlContent); 40 | } finally { 41 | FileUtil.del(pdfFile); 42 | FileUtil.del(htmlFile); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-special/dunwu-tool-pdf/src/test/java/io/github/dunwu/tool/pdf/OrderInfo.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.pdf; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @Builder 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class OrderInfo { 13 | 14 | private String title; 15 | private String partner; 16 | private String settlementContent; 17 | private String settlementProduct; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/CookieUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web; 2 | 3 | import cn.hutool.core.util.ArrayUtil; 4 | import cn.hutool.core.util.StrUtil; 5 | 6 | import javax.servlet.http.Cookie; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | /** 11 | * Cookie 工具类 12 | * 13 | * @author Zhang Peng 14 | * @since 2019-06-15 15 | */ 16 | public class CookieUtil { 17 | 18 | /** 19 | * 添加 Cookie 20 | * 21 | * @param request 22 | * @param response 23 | * @param key 24 | * @param value 25 | */ 26 | public static void addCookie(HttpServletRequest request, HttpServletResponse response, 27 | String key, String value) { 28 | Cookie cookie = new Cookie(key, value); 29 | cookie.setPath(request.getContextPath()); 30 | response.addCookie(cookie); 31 | } 32 | 33 | /** 34 | * 获取 Cookie 35 | * 36 | * @param request HttpServletRequest 37 | * @param key Cookie 中存储的关键字 38 | * @return Cookie 中存储的关键字对应的值 39 | */ 40 | public static String getCookie(HttpServletRequest request, String key) { 41 | Cookie[] cookies = request.getCookies(); 42 | if (ArrayUtil.isEmpty(cookies) || StrUtil.isBlank(key)) { 43 | return null; 44 | } 45 | 46 | for (Cookie cookie : cookies) { 47 | if (key.equals(cookie.getName())) { 48 | return cookie.getValue(); 49 | } 50 | } 51 | 52 | return null; 53 | } 54 | 55 | /** 56 | * 删除 Cookie 57 | * 58 | * @param response 59 | * @param key 60 | * @param path 61 | * @param domain 62 | */ 63 | public static void removeCookie(HttpServletResponse response, String key, String path, 64 | String domain) { 65 | Cookie cookie = new Cookie(key, null); 66 | 67 | if (StrUtil.isEmpty(path)) { 68 | cookie.setPath(path); 69 | } 70 | 71 | if (StrUtil.isEmpty(domain)) { 72 | cookie.setDomain(domain); 73 | } 74 | 75 | cookie.setMaxAge(-1000); 76 | response.addCookie(cookie); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/SpringUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.DisposableBean; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.ApplicationContextAware; 7 | 8 | /** 9 | * @author Zhang Peng 10 | * @since 2019-07-24 11 | */ 12 | public class SpringUtil implements ApplicationContextAware, DisposableBean { 13 | 14 | private static ApplicationContext applicationContext = null; 15 | 16 | public static ApplicationContext getApplicationContext() { 17 | return applicationContext; 18 | } 19 | 20 | @Override 21 | public void setApplicationContext(ApplicationContext applicationContext) 22 | throws BeansException { 23 | if (null == SpringUtil.applicationContext) { 24 | SpringUtil.applicationContext = applicationContext; 25 | } 26 | } 27 | 28 | @Override 29 | public void destroy() throws Exception { 30 | applicationContext = null; 31 | } 32 | 33 | public static Object getBean(String name) { 34 | return applicationContext.getBean(name); 35 | } 36 | 37 | public static Object getBean(String name, Object... args) { 38 | return applicationContext.getBean(name, args); 39 | } 40 | 41 | public static T getBean(Class requiredType) { 42 | return applicationContext.getBean(requiredType); 43 | } 44 | 45 | public static T getBean(Class requiredType, Object... args) { 46 | return applicationContext.getBean(requiredType, args); 47 | } 48 | 49 | public static T getBean(String name, Class requiredType) { 50 | return applicationContext.getBean(name, requiredType); 51 | } 52 | 53 | public static Object getObject(String id) { 54 | Object object = null; 55 | object = applicationContext.getBean(id); 56 | return object; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/aop/SecurityInterceptor.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.aop; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import io.github.dunwu.tool.web.constant.WebConstant; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import javax.servlet.http.HttpSession; 12 | 13 | /** 14 | * @author Zhang Peng 15 | * @since 2019-06-13 16 | */ 17 | public class SecurityInterceptor extends HandlerInterceptorAdapter { 18 | 19 | private final Logger log = LoggerFactory.getLogger(this.getClass()); 20 | 21 | private final String tokenKey; 22 | 23 | public SecurityInterceptor(String tokenKey) { 24 | this.tokenKey = tokenKey; 25 | } 26 | 27 | @Override 28 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, 29 | Object handler) { 30 | if (WebConstant.HTTP_METHOD_OPTIONS.equals(request.getMethod())) { 31 | return true; 32 | } 33 | 34 | HttpSession session = request.getSession(); 35 | log.info("[{}] url = {}", request.getMethod(), request.getRequestURL()); 36 | log.info("session id = {}", session.getId()); 37 | String token = (String) session.getAttribute(tokenKey); 38 | log.info("inceptor {} = {}", tokenKey, token); 39 | if (StrUtil.isBlank(token)) { 40 | return true; 41 | } 42 | log.error("没有 session"); 43 | return true; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/aop/entity/MethodInfo.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.aop.entity; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | import lombok.ToString; 6 | 7 | import java.lang.reflect.Method; 8 | 9 | /** 10 | * 方法信息实体 11 | * 12 | * @author Zhang Peng 13 | * @since 2021-12-30 14 | */ 15 | @Data 16 | @ToString 17 | @Builder 18 | public class MethodInfo { 19 | 20 | private Class clazz; 21 | private Method method; 22 | private Object[] args; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/aop/util/AopUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.aop.util; 2 | 3 | import io.github.dunwu.tool.web.aop.entity.MethodInfo; 4 | import org.aspectj.lang.JoinPoint; 5 | import org.aspectj.lang.reflect.MethodSignature; 6 | 7 | import java.lang.reflect.Method; 8 | 9 | /** 10 | * @author Zhang Peng 11 | * @date 2022-12-14 12 | */ 13 | public class AopUtil { 14 | 15 | public static MethodInfo getMethodInfo(JoinPoint joinPoint) { 16 | Class clazz = joinPoint.getTarget().getClass(); 17 | Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); 18 | Object[] args = joinPoint.getArgs(); 19 | return MethodInfo.builder() 20 | .clazz(clazz) 21 | .method(method) 22 | .args(args) 23 | .build(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/constant/WebConstant.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.constant; 2 | 3 | /** 4 | * @author Zhang Peng 5 | * @since 2019-08-29 6 | */ 7 | public interface WebConstant { 8 | 9 | String HTTP_METHOD_OPTIONS = "OPTIONS"; 10 | 11 | String PATH_SEPARATOR = "/"; 12 | 13 | enum ResponseType { 14 | 15 | HTTP_REPONSE, 16 | MODEL_AND_VIEW 17 | } 18 | 19 | enum BrowserType { 20 | 21 | firefox, 22 | chrome, 23 | safari, 24 | msie, 25 | opera 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/converter/DateConverter.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.converter; 2 | 3 | import cn.hutool.core.date.DatePattern; 4 | import cn.hutool.core.util.StrUtil; 5 | import org.springframework.core.convert.converter.Converter; 6 | 7 | import java.text.ParseException; 8 | import java.util.Date; 9 | 10 | /** 11 | * @author Zhang Peng 12 | * @since 2019-06-14 13 | */ 14 | public class DateConverter implements Converter { 15 | 16 | @Override 17 | public Date convert(String dateString) { 18 | if (StrUtil.isBlank(dateString)) { 19 | return null; 20 | } 21 | 22 | Date date = null; 23 | try { 24 | date = DatePattern.NORM_DATETIME_FORMAT.parse(dateString); 25 | } catch (ParseException e) { 26 | e.printStackTrace(); 27 | } 28 | 29 | return date; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/converter/DateTimeConverter.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.converter; 2 | 3 | import cn.hutool.core.date.DatePattern; 4 | import cn.hutool.core.date.DateTime; 5 | import cn.hutool.core.util.StrUtil; 6 | import io.github.dunwu.tool.util.DateUtil; 7 | import org.springframework.core.convert.converter.Converter; 8 | 9 | import java.text.ParseException; 10 | import java.util.Date; 11 | 12 | /** 13 | * @author Zhang Peng 14 | * @since 2019-06-14 15 | */ 16 | public class DateTimeConverter implements Converter { 17 | 18 | @Override 19 | public DateTime convert(String dateString) { 20 | if (StrUtil.isBlank(dateString)) { 21 | return null; 22 | } 23 | 24 | DateTime dateTime = null; 25 | try { 26 | Date date = DatePattern.NORM_DATETIME_FORMAT.parse(dateString); 27 | dateTime = DateUtil.date(date); 28 | } catch (ParseException e) { 29 | e.printStackTrace(); 30 | } 31 | 32 | return dateTime; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/converter/LocalDateConverter.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.converter; 2 | 3 | import cn.hutool.core.date.DatePattern; 4 | import cn.hutool.core.util.StrUtil; 5 | import io.github.dunwu.tool.util.DateUtil; 6 | import org.springframework.core.convert.converter.Converter; 7 | 8 | import java.text.ParseException; 9 | import java.time.LocalDate; 10 | import java.time.LocalDateTime; 11 | import java.util.Date; 12 | 13 | /** 14 | * @author Zhang Peng 15 | * @since 2019-06-14 16 | */ 17 | public class LocalDateConverter implements Converter { 18 | 19 | @Override 20 | public LocalDate convert(String dateString) { 21 | if (StrUtil.isBlank(dateString)) { 22 | return null; 23 | } 24 | 25 | LocalDate localDate = null; 26 | try { 27 | Date date = DatePattern.NORM_DATETIME_FORMAT.parse(dateString); 28 | LocalDateTime localDateTime = DateUtil.toLocalDateTime(date); 29 | localDate = localDateTime.toLocalDate(); 30 | } catch (ParseException e) { 31 | e.printStackTrace(); 32 | } 33 | 34 | return localDate; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/converter/LocalDateTimeConverter.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.converter; 2 | 3 | import cn.hutool.core.date.DatePattern; 4 | import cn.hutool.core.util.StrUtil; 5 | import io.github.dunwu.tool.util.DateUtil; 6 | import org.springframework.core.convert.converter.Converter; 7 | 8 | import java.text.ParseException; 9 | import java.time.LocalDateTime; 10 | import java.util.Date; 11 | 12 | /** 13 | * @author Zhang Peng 14 | * @since 2019-06-14 15 | */ 16 | public class LocalDateTimeConverter implements Converter { 17 | 18 | @Override 19 | public LocalDateTime convert(String dateString) { 20 | if (StrUtil.isBlank(dateString)) { 21 | return null; 22 | } 23 | 24 | LocalDateTime localDateTime = null; 25 | try { 26 | Date date = DatePattern.NORM_DATETIME_FORMAT.parse(dateString); 27 | localDateTime = DateUtil.toLocalDateTime(date); 28 | } catch (ParseException e) { 29 | e.printStackTrace(); 30 | } 31 | 32 | return localDateTime; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/jsp/BlockTag.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.jsp; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.jsp.JspException; 5 | import javax.servlet.jsp.tagext.TagSupport; 6 | 7 | /** 8 | * @author Zhang Peng 9 | * @since 2019-09-05 10 | */ 11 | public class BlockTag extends TagSupport { 12 | 13 | private static final long serialVersionUID = 5981092740359798010L; 14 | 15 | private static final String BLOCK = "__jsp_override__"; 16 | 17 | protected String name; 18 | 19 | @Override 20 | public int doStartTag() { 21 | return getOverriedContent() == null ? EVAL_BODY_INCLUDE : SKIP_BODY; 22 | } 23 | 24 | @Override 25 | public int doEndTag() throws JspException { 26 | String overriedContent = getOverriedContent(); 27 | if (overriedContent == null) { 28 | return EVAL_PAGE; 29 | } 30 | 31 | try { 32 | pageContext.getOut().write(overriedContent); 33 | } catch (IOException e) { 34 | throw new JspException( 35 | "try to override jsp content failed, block name:" + name, e); 36 | } 37 | return EVAL_PAGE; 38 | } 39 | 40 | private String getOverriedContent() { 41 | String newName = BLOCK + name; 42 | return (String) pageContext.getRequest().getAttribute(newName); 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/jsp/OverrideTag.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.jsp; 2 | 3 | import javax.servlet.jsp.tagext.BodyContent; 4 | import javax.servlet.jsp.tagext.BodyTagSupport; 5 | 6 | /** 7 | * @author Zhang Peng 8 | * @since 2019-09-05 9 | */ 10 | public class OverrideTag extends BodyTagSupport { 11 | 12 | private static final long serialVersionUID = 1692569211455126528L; 13 | 14 | private static final String BLOCK = "__jsp_override__"; 15 | 16 | protected String name; 17 | 18 | @Override 19 | public int doStartTag() { 20 | return isOverrided() ? SKIP_BODY : EVAL_BODY_BUFFERED; 21 | } 22 | 23 | @Override 24 | public int doEndTag() { 25 | if (isOverrided()) { 26 | return EVAL_PAGE; 27 | } 28 | BodyContent b = getBodyContent(); 29 | String newName = BLOCK + name; 30 | 31 | pageContext.getRequest().setAttribute(newName, b.getString()); 32 | return EVAL_PAGE; 33 | } 34 | 35 | private boolean isOverrided() { 36 | String newName = BLOCK + name; 37 | return pageContext.getRequest().getAttribute(newName) != null; 38 | } 39 | 40 | public void setName(String name) { 41 | this.name = name; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/annotation/DataLockLog.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.annotation; 2 | 3 | import io.github.dunwu.tool.web.log.constant.OperationType; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * @author Zhang Peng 12 | * @date 2022-11-29 13 | */ 14 | @Target(ElementType.METHOD) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface DataLockLog { 17 | 18 | /** 19 | * 锁定的表名 20 | */ 21 | String tableName(); 22 | 23 | /** 24 | * 操作类型 25 | */ 26 | OperationType operation() default OperationType.OTHER; 27 | 28 | /** 29 | * 实体(SpEL表达式) 30 | */ 31 | String entity(); 32 | 33 | /** 34 | * 主键关键字名 35 | */ 36 | String id() default "id"; 37 | 38 | /** 39 | * 根据 ID 批量查询数据的方法名,例如:io.github.dunwu.tool.data.mybatis.IDao#listByIds 40 | */ 41 | String queryMethod(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/annotation/OperationLog.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.annotation; 2 | 3 | import io.github.dunwu.tool.web.log.constant.OperationType; 4 | 5 | import java.lang.annotation.Documented; 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Inherited; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | /** 13 | * 操作日志注解 14 | * 15 | * @author Zhang Peng 16 | * @since 2021-12-30 17 | */ 18 | @Target({ ElementType.METHOD }) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | @Inherited 21 | @Documented 22 | public @interface OperationLog { 23 | 24 | /** 业务 NO */ 25 | String bizNo() default ""; 26 | 27 | /** 业务类型 */ 28 | String bizType() default ""; 29 | 30 | /** 更新实体 */ 31 | String entity() default ""; 32 | 33 | /** 操作类型 */ 34 | OperationType operation() default OperationType.OTHER; 35 | 36 | /** 成功信息 SpEl 模板 */ 37 | String success() default ""; 38 | 39 | /** 失败信息 SpEl 模板 */ 40 | String fail() default ""; 41 | 42 | /** 详情信息 SpEl 模板 */ 43 | String detail() default ""; 44 | 45 | /** 操作者ID SpEl 模板 */ 46 | String operatorId() default ""; 47 | 48 | /** 操作者名 SpEl 模板 */ 49 | String operatorName() default ""; 50 | 51 | /** 日志记录条件 SpEl 模板 */ 52 | String condition() default ""; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/constant/OperationType.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.constant; 2 | 3 | /** 4 | * 操作类型枚举 5 | * 6 | * @author peng.zhang 7 | * @date 2021-12-29 8 | */ 9 | public enum OperationType { 10 | 11 | /** 添加 */ 12 | ADD("添加"), 13 | /** 更新 */ 14 | EDIT("更新"), 15 | /** 删除 */ 16 | DEL("删除"), 17 | /** 保存 */ 18 | SAVE("保存"), 19 | /** 批量添加 */ 20 | BATCH_ADD("批量添加"), 21 | /** 批量更新 */ 22 | BATCH_EDIT("批量更新"), 23 | /** 批量删除 */ 24 | BATCH_DEL("批量删除"), 25 | /** 批量保存 */ 26 | BATCH_SAVE("批量保存"), 27 | /** 导入Excel */ 28 | IMPORT_EXCEL("导入Excel"), 29 | /** 导出Excel */ 30 | EXPORT_EXCEL("导出Excel"), 31 | /** 其他 */ 32 | OTHER("其他"); 33 | 34 | private final String name; 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | OperationType(String name) { 41 | this.name = name; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/entity/DataLockLogInfo.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.entity; 2 | 3 | import io.github.dunwu.tool.web.log.annotation.DataLockLog; 4 | import io.github.dunwu.tool.web.log.constant.OperationType; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | 8 | /** 9 | * 数据锁定日志注解 {@link DataLockLog} 对应的数据信息实体 10 | * 11 | * @author Zhang Peng 12 | * @date 2022-11-29 13 | */ 14 | @Data 15 | @Builder 16 | public class DataLockLogInfo { 17 | 18 | /** 19 | * 锁定的表所属 schema 20 | */ 21 | private String schemaName; 22 | 23 | /** 24 | * 锁定的表名 25 | */ 26 | private String tableName; 27 | 28 | /** 29 | * 主键关键字名 30 | */ 31 | private String id; 32 | 33 | /** 34 | * 实体 35 | */ 36 | private String entity; 37 | 38 | /** 39 | * 操作类型 40 | */ 41 | private OperationType operation; 42 | 43 | /** 44 | * 根据 ID 批量查询数据的方法名,例如:io.github.dunwu.tool.data.mybatis.IDao#listByIds 45 | */ 46 | private String queryMethod; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/entity/DataLockLogRecord.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.entity; 2 | 3 | import io.github.dunwu.tool.web.log.annotation.DataLockLog; 4 | import io.github.dunwu.tool.web.log.constant.OperationType; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * 数据锁定日志注解 {@link DataLockLog} 对应的数据信息实体 12 | * 13 | * @author Zhang Peng 14 | * @date 2022-11-29 15 | */ 16 | @Data 17 | @Builder 18 | public class DataLockLogRecord { 19 | 20 | /** ID */ 21 | private Long id; 22 | 23 | /** 锁定的库名 */ 24 | private String schemaName; 25 | 26 | /** 锁定的表名 */ 27 | private String tableName; 28 | 29 | /** 锁定的表名 */ 30 | private String columnName; 31 | 32 | /** 行ID */ 33 | private String rowId; 34 | 35 | /** 单元值 */ 36 | private String cellValue; 37 | 38 | /** 操作类型 */ 39 | private OperationType operation; 40 | 41 | /** 操作者ID */ 42 | private Long operatorId; 43 | 44 | /** 操作者用户名 */ 45 | private String operatorName; 46 | 47 | /** 日志记录时间 */ 48 | private Date createTime; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/entity/ExecuteResult.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * 方法执行结果实体 9 | * 10 | * @author Zhang Peng 11 | * @date 2022-11-29 12 | */ 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class ExecuteResult { 17 | 18 | private boolean success; 19 | private String error; 20 | private Throwable throwable; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/entity/OperationLogInfo.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.entity; 2 | 3 | import io.github.dunwu.tool.web.log.annotation.OperationLog; 4 | import io.github.dunwu.tool.web.log.constant.OperationType; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | 8 | /** 9 | * 操作日志注解 {@link OperationLog} 对应的数据信息实体 10 | * 11 | * @author Zhang Peng 12 | * @since 2021-12-30 13 | */ 14 | @Data 15 | @Builder 16 | public class OperationLogInfo { 17 | 18 | /** 业务 NO */ 19 | private String bizNo; 20 | 21 | /** 业务类型 */ 22 | private String bizType; 23 | 24 | /** 操作类型 */ 25 | private OperationType operation; 26 | 27 | /** 成功信息 SpEl 模板 */ 28 | private String success; 29 | 30 | /** 失败信息 SpEl 模板 */ 31 | private String fail; 32 | 33 | /** 详情信息 SpEl 模板 */ 34 | private String detail; 35 | 36 | /** 操作者ID SpEl 模板 */ 37 | private String operatorId; 38 | 39 | /** 操作者名 SpEl 模板 */ 40 | private String operatorName; 41 | 42 | /** 日志记录条件 SpEl 模板 */ 43 | private String condition; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/entity/OperationLogRecord.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.entity; 2 | 3 | import io.github.dunwu.tool.web.log.constant.OperationType; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | import lombok.ToString; 9 | import lombok.experimental.Accessors; 10 | 11 | import java.util.Date; 12 | 13 | /** 14 | * 操作日志实体 15 | * 16 | * @author Zhang Peng 17 | * @since 2021-12-30 18 | */ 19 | @Data 20 | @ToString 21 | @Builder 22 | @Accessors(chain = true) 23 | @AllArgsConstructor 24 | @NoArgsConstructor 25 | public class OperationLogRecord { 26 | 27 | /** ID */ 28 | private Long id; 29 | 30 | /** 应用名 */ 31 | private String appName; 32 | 33 | /** 业务编码 */ 34 | private String bizNo; 35 | 36 | /** 业务类型 */ 37 | private String bizType; 38 | 39 | /** 是否成功 */ 40 | private boolean success; 41 | 42 | /** 基本信息 */ 43 | private String message; 44 | 45 | /** 详情信息 */ 46 | private String detail; 47 | 48 | /** 异常信息 */ 49 | private String exception; 50 | 51 | /** 操作的类名 */ 52 | private String className; 53 | 54 | /** 操作的方法名 */ 55 | private String methodName; 56 | 57 | /** 被调用方法的参数 */ 58 | private String params; 59 | 60 | /** 操作类型 */ 61 | private OperationType operation; 62 | 63 | /** 操作者ID */ 64 | private Long operatorId; 65 | 66 | /** 操作者用户名 */ 67 | private String operatorName; 68 | 69 | /** 服务端IP地址 */ 70 | private String serverIp; 71 | 72 | /** 客户端IP地址 */ 73 | private String clientIp; 74 | 75 | /** 客户端地理位置 */ 76 | private String clientLocation; 77 | 78 | /** 客户端设备 */ 79 | private String clientDevice; 80 | 81 | /** HTTP请求的耗时 */ 82 | private Long requestTime; 83 | 84 | /** 日志记录时间 */ 85 | private Date createTime; 86 | 87 | } 88 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/service/DataLockLogService.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.service; 2 | 3 | import io.github.dunwu.tool.web.log.entity.DataLockLogRecord; 4 | 5 | import java.util.Collection; 6 | 7 | /** 8 | * 数据锁定日志服务 9 | * 10 | * @author Zhang Peng 11 | * @date 2022-11-29 12 | */ 13 | public interface DataLockLogService { 14 | 15 | /** 16 | * 批量保存日志 17 | * 18 | * @param records 日志记录 19 | * @return 是否保存成功 20 | */ 21 | boolean batchSave(Collection records); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/service/FunctionService.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.service; 2 | 3 | public interface FunctionService { 4 | 5 | String parse(String methodName, String value); 6 | 7 | boolean isBeforeFunction(String functionName); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/service/OperationLogService.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.service; 2 | 3 | import io.github.dunwu.tool.web.log.entity.OperationLogRecord; 4 | 5 | /** 6 | * 操作日志存储接口 7 | * 8 | * @author peng.zhang 9 | * @date 2021-09-29 10 | */ 11 | public interface OperationLogService { 12 | 13 | /** 14 | * 保存日志 15 | * 16 | * @param record 日志记录 17 | * @return true / false 18 | */ 19 | boolean store(OperationLogRecord record); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/service/ParseFunction.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.service; 2 | 3 | import io.github.dunwu.tool.web.log.annotation.OperationLog; 4 | 5 | /** 6 | * 操作日志注解 {@link OperationLog} 的 SpEl 模板中使用的解析函数 7 | * 8 | * @author Zhang Peng 9 | * @since 2021-12-30 10 | */ 11 | public interface ParseFunction { 12 | 13 | /** 14 | * 是否在方法执行前进行解析 15 | * 16 | * @return true / false 17 | */ 18 | default boolean isBeforeFunction() { 19 | return false; 20 | } 21 | 22 | /** 23 | * 获取方法名 24 | * 25 | * @return / 26 | */ 27 | String getFunctionName(); 28 | 29 | /** 30 | * 解析数据 31 | * 32 | * @param value 待解析的数据 33 | * @return / 34 | */ 35 | String parse(String value); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/service/TableColumnConfigService.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.service; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * 表字段配置服务 7 | * 8 | * @author Zhang Peng 9 | * @date 2023-01-13 10 | */ 11 | public interface TableColumnConfigService { 12 | 13 | /** 14 | * 返回表字段配置中被锁定的字段集合 15 | * 16 | * @param tableName 表名 17 | * @return / 18 | */ 19 | Set getLockedColumns(String tableName); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/service/impl/DefaultDataLockLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.service.impl; 2 | 3 | import cn.hutool.json.JSONUtil; 4 | import io.github.dunwu.tool.web.log.entity.DataLockLogRecord; 5 | import io.github.dunwu.tool.web.log.service.DataLockLogService; 6 | import lombok.extern.slf4j.Slf4j; 7 | 8 | import java.util.Collection; 9 | 10 | /** 11 | * 默认数据锁定日志服务实现类 12 | * 13 | * @author Zhang Peng 14 | * @date 2022-11-29 15 | */ 16 | @Slf4j 17 | public class DefaultDataLockLogServiceImpl implements DataLockLogService { 18 | 19 | @Override 20 | public boolean batchSave(Collection records) { 21 | log.info("批量保存【数据锁定日志】{}", JSONUtil.toJsonStr(records)); 22 | return true; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/service/impl/DefaultFunctionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.service.impl; 2 | 3 | import io.github.dunwu.tool.web.log.service.FunctionService; 4 | import io.github.dunwu.tool.web.log.service.ParseFunction; 5 | import io.github.dunwu.tool.web.log.support.ParseFunctionFactory; 6 | import lombok.RequiredArgsConstructor; 7 | 8 | /** 9 | * @author Zhang Peng 10 | * @since 2021-12-30 11 | */ 12 | @RequiredArgsConstructor 13 | public class DefaultFunctionServiceImpl implements FunctionService { 14 | 15 | private final ParseFunctionFactory parseFunctionFactory; 16 | 17 | @Override 18 | public String parse(String methodName, String value) { 19 | ParseFunction function = parseFunctionFactory.getFunction(methodName); 20 | if (function == null) { 21 | return value; 22 | } 23 | return function.parse(value); 24 | } 25 | 26 | @Override 27 | public boolean isBeforeFunction(String functionName) { 28 | return parseFunctionFactory.isBeforeFunction(functionName); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/service/impl/DefaultOperationLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.service.impl; 2 | 3 | import cn.hutool.json.JSONUtil; 4 | import io.github.dunwu.tool.web.log.entity.OperationLogRecord; 5 | import io.github.dunwu.tool.web.log.service.OperationLogService; 6 | import lombok.extern.slf4j.Slf4j; 7 | 8 | /** 9 | * 操作日志存储接口默认实现类 10 | * 11 | * @author Zhang Peng 12 | * @since 2021-12-30 13 | */ 14 | @Slf4j 15 | public class DefaultOperationLogServiceImpl implements OperationLogService { 16 | 17 | @Override 18 | public boolean store(OperationLogRecord record) { 19 | log.info("【操作日志】{}", JSONUtil.toJsonStr(record)); 20 | return true; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/service/impl/DefaultParseFunction.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.service.impl; 2 | 3 | import io.github.dunwu.tool.web.log.annotation.OperationLog; 4 | import io.github.dunwu.tool.web.log.service.ParseFunction; 5 | 6 | /** 7 | * 操作日志注解 {@link OperationLog} 的 SpEl 模板中使用的解析函数默认实现 8 | * 9 | * @author Zhang Peng 10 | * @since 2021-12-30 11 | */ 12 | public class DefaultParseFunction implements ParseFunction { 13 | 14 | @Override 15 | public boolean isBeforeFunction() { 16 | return true; 17 | } 18 | 19 | @Override 20 | public String getFunctionName() { 21 | return null; 22 | } 23 | 24 | @Override 25 | public String parse(String value) { 26 | return null; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/service/impl/DefaultTableColumnConfigServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.service.impl; 2 | 3 | import io.github.dunwu.tool.web.log.service.TableColumnConfigService; 4 | 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | /** 9 | * 表字段配置服务默认实现 10 | * 11 | * @author Zhang Peng 12 | * @date 2023-01-13 13 | */ 14 | public class DefaultTableColumnConfigServiceImpl implements TableColumnConfigService { 15 | 16 | @Override 17 | public Set getLockedColumns(String tableName) { 18 | return new HashSet<>(0); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/support/LogRecordContext.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.support; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Stack; 6 | 7 | /** 8 | * 日志记录变量上下文 9 | * 10 | * @author Zhang Peng 11 | * @since 2021-12-30 12 | */ 13 | public class LogRecordContext { 14 | 15 | private static final InheritableThreadLocal>> VARIABLE_MAP_STACK = 16 | new InheritableThreadLocal<>(); 17 | 18 | public static void putVariable(String name, Object value) { 19 | if (VARIABLE_MAP_STACK.get() == null) { 20 | Stack> stack = new Stack<>(); 21 | VARIABLE_MAP_STACK.set(stack); 22 | } 23 | Stack> mapStack = VARIABLE_MAP_STACK.get(); 24 | if (mapStack.size() == 0) { 25 | VARIABLE_MAP_STACK.get().push(new HashMap<>()); 26 | } 27 | VARIABLE_MAP_STACK.get().peek().put(name, value); 28 | } 29 | 30 | public static Object getVariable(String key) { 31 | Map variableMap = VARIABLE_MAP_STACK.get().peek(); 32 | return variableMap.get(key); 33 | } 34 | 35 | public static Map getVariables() { 36 | Stack> mapStack = VARIABLE_MAP_STACK.get(); 37 | return mapStack.peek(); 38 | } 39 | 40 | public static void clear() { 41 | if (VARIABLE_MAP_STACK.get() != null) { 42 | VARIABLE_MAP_STACK.get().pop(); 43 | } 44 | } 45 | 46 | /** 47 | * 日志使用方不需要使用到这个方法 每进入一个方法初始化一个 span 放入到 stack中,方法执行完后 pop 掉这个span 48 | */ 49 | public static void putEmptySpan() { 50 | Stack> mapStack = VARIABLE_MAP_STACK.get(); 51 | if (mapStack == null) { 52 | Stack> stack = new Stack<>(); 53 | VARIABLE_MAP_STACK.set(stack); 54 | } 55 | VARIABLE_MAP_STACK.get().push(new HashMap<>()); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/support/LogRecordEvaluationContext.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.support; 2 | 3 | import org.springframework.context.expression.MethodBasedEvaluationContext; 4 | import org.springframework.core.ParameterNameDiscoverer; 5 | 6 | import java.lang.reflect.Method; 7 | import java.util.Map; 8 | 9 | /** 10 | * 日志记录上下文 11 | * 12 | * @author Zhang Peng 13 | * @since 2020-12-30 14 | */ 15 | public class LogRecordEvaluationContext extends MethodBasedEvaluationContext { 16 | 17 | public LogRecordEvaluationContext(Object rootObject, Method method, Object[] arguments, 18 | ParameterNameDiscoverer parameterNameDiscoverer, Object result, String error) { 19 | super(rootObject, method, arguments, parameterNameDiscoverer); 20 | Map variables = LogRecordContext.getVariables(); 21 | if (variables != null && variables.size() > 0) { 22 | for (Map.Entry entry : variables.entrySet()) { 23 | setVariable(entry.getKey(), entry.getValue()); 24 | } 25 | } 26 | setVariable("_result", result); 27 | setVariable("_error", error); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/log/support/ParseFunctionFactory.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.log.support; 2 | 3 | import cn.hutool.core.collection.CollectionUtil; 4 | import cn.hutool.core.util.StrUtil; 5 | import io.github.dunwu.tool.web.log.service.ParseFunction; 6 | 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * 解析方法工厂 13 | * 14 | * @author Zhang Peng 15 | * @since 2021-12-30 16 | */ 17 | public class ParseFunctionFactory { 18 | 19 | private Map allFunctionMap; 20 | 21 | public ParseFunctionFactory(List parseFunctions) { 22 | if (CollectionUtil.isEmpty(parseFunctions)) { 23 | return; 24 | } 25 | allFunctionMap = new HashMap<>(); 26 | for (ParseFunction parseFunction : parseFunctions) { 27 | if (StrUtil.isBlank(parseFunction.getFunctionName())) { 28 | continue; 29 | } 30 | allFunctionMap.put(parseFunction.getFunctionName(), parseFunction); 31 | } 32 | } 33 | 34 | public ParseFunction getFunction(String functionName) { 35 | return allFunctionMap.get(functionName); 36 | } 37 | 38 | public boolean isBeforeFunction(String functionName) { 39 | return allFunctionMap.get(functionName) != null && allFunctionMap.get(functionName).isBeforeFunction(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /dunwu-tool/dunwu-tool-web/src/main/java/io/github/dunwu/tool/web/security/SecurityService.java: -------------------------------------------------------------------------------- 1 | package io.github.dunwu.tool.web.security; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 安全服务 7 | * 8 | * @author peng.zhang 9 | * @date 2021-09-26 10 | */ 11 | public interface SecurityService { 12 | 13 | /** 14 | * 获取系统用户ID 15 | * 16 | * @return 系统用户ID 17 | */ 18 | Long getCurrentUserId(); 19 | 20 | /** 21 | * 获取当前用户名称 22 | */ 23 | String getCurrentUsername(); 24 | 25 | /** 26 | * 获取数据权限级别 27 | * 28 | * @return 级别 29 | */ 30 | String getDataScopeType(); 31 | 32 | /** 33 | * 获取当前用户的数据权限 34 | * 35 | * @return / 36 | */ 37 | List getCurrentUserDataScope(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /dunwu-tool/scripts/deploy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem ------------------------------------------------- 3 | rem 本脚本用于发布 dunwu-tool 到中央仓库 4 | rem 环境要求:Maven + JDK8 5 | rem ------------------------------------------------- 6 | 7 | pushd %~dp0.. 8 | call mvn clean install org.apache.maven.plugins:maven-deploy-plugin:2.8:deploy -DskipTests 9 | popd 10 | 11 | pause 12 | --------------------------------------------------------------------------------