diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 43f0835..5b76295 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -9,11 +9,13 @@
+
+
@@ -30,6 +32,8 @@
+
+
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index 7d38b99..2e792de 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -9,6 +9,8 @@
+
+
diff --git a/ds-biz/ds-miniapps/ds-miniapps-biz/pom.xml b/ds-biz/ds-miniapps/ds-miniapps-biz/pom.xml
index ce21b9b..2a4c455 100644
--- a/ds-biz/ds-miniapps/ds-miniapps-biz/pom.xml
+++ b/ds-biz/ds-miniapps/ds-miniapps-biz/pom.xml
@@ -41,6 +41,16 @@
0.0.1-SNAPSHOT
compile
+
+ com.ds.common.web.config
+ ds-mybatisplus-config
+ 0.0.1-SNAPSHOT
+
+
+ com.ds.common.web.config
+ ds-mybatisplus-support
+ 0.0.1-SNAPSHOT
+
\ No newline at end of file
diff --git a/ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/MiniAppsApplication.java b/ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/MiniAppsApplication.java
index 3915a0a..bee8708 100644
--- a/ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/MiniAppsApplication.java
+++ b/ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/MiniAppsApplication.java
@@ -1,5 +1,6 @@
package com.ds.miniapps.biz;
+import com.ds.commons.support.generator.config.MybatisPlusGeneratorConfig;
import com.ds.commons.web.config.exection.WebGlobalExceptionHandler;
import com.ds.commons.web.config.swagger.SwaggerConfig;
import org.springframework.boot.SpringApplication;
@@ -11,7 +12,7 @@ import org.springframework.context.annotation.Import;
* @since 2023/8/27
*/
@SpringBootApplication
-@Import({SwaggerConfig.class, WebGlobalExceptionHandler.class})
+@Import({SwaggerConfig.class, WebGlobalExceptionHandler.class, MybatisPlusGeneratorConfig.class})
public class MiniAppsApplication {
public static void main(String[] args) {
diff --git a/ds-biz/ds-miniapps/ds-miniapps-model/pom.xml b/ds-biz/ds-miniapps/ds-miniapps-model/pom.xml
index 05c0ecd..aae7df4 100644
--- a/ds-biz/ds-miniapps/ds-miniapps-model/pom.xml
+++ b/ds-biz/ds-miniapps/ds-miniapps-model/pom.xml
@@ -18,7 +18,11 @@
-
+
+ com.ds.common.web.config
+ ds-mybatisplus-config
+ 0.0.1-SNAPSHOT
+
\ No newline at end of file
diff --git a/ds-commons/ds-config/ds-mybatisplus-config/pom.xml b/ds-commons/ds-config/ds-mybatisplus-config/pom.xml
new file mode 100644
index 0000000..18acae8
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-config/pom.xml
@@ -0,0 +1,33 @@
+
+
+ 4.0.0
+
+ com.ds
+ ds-config
+ 0.0.1-SNAPSHOT
+
+
+ com.ds.common.web.config
+ ds-mybatisplus-config
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.24
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.5.3.2
+
+
+
\ No newline at end of file
diff --git a/ds-commons/ds-config/ds-mybatisplus-config/src/main/java/com/ds/common/web/config/Main.java b/ds-commons/ds-config/ds-mybatisplus-config/src/main/java/com/ds/common/web/config/Main.java
new file mode 100644
index 0000000..1d09a4b
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-config/src/main/java/com/ds/common/web/config/Main.java
@@ -0,0 +1,11 @@
+package com.ds.common.web.config;
+
+/**
+ * @author ds
+ * @since 2023/9/2
+ */
+public class Main {
+ public static void main(String[] args) {
+ System.out.println(System.getProperty("user.dir"));
+ }
+}
\ No newline at end of file
diff --git a/ds-commons/ds-config/ds-mybatisplus-support/pom.xml b/ds-commons/ds-config/ds-mybatisplus-support/pom.xml
new file mode 100644
index 0000000..4cc1481
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-support/pom.xml
@@ -0,0 +1,44 @@
+
+
+ 4.0.0
+
+ com.ds
+ ds-config
+ 0.0.1-SNAPSHOT
+
+
+ com.ds.common.web.config
+ ds-mybatisplus-support
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+ org.apache.velocity
+ velocity-engine-core
+ 2.3
+
+
+ com.baomidou
+ mybatis-plus-generator
+ 3.5.3.1
+
+
+ com.ds.common.web.config
+ ds-mybatisplus-config
+ 0.0.1-SNAPSHOT
+
+
+ com.ds.common.web.config
+ ds-web-config
+ 0.0.1-SNAPSHOT
+
+
+
+
\ No newline at end of file
diff --git a/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/MybatisPlusGeneratorConfig.java b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/MybatisPlusGeneratorConfig.java
new file mode 100644
index 0000000..d52467c
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/MybatisPlusGeneratorConfig.java
@@ -0,0 +1,51 @@
+package com.ds.commons.support.generator;
+
+import com.baomidou.mybatisplus.generator.FastAutoGenerator;
+import com.baomidou.mybatisplus.generator.config.OutputFile;
+import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
+
+import java.sql.Types;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author ds
+ * @since 2023/9/3
+ */
+public class MybatisPlusGeneratorConfig {
+ public static void main(String[] args) {
+
+ Map map = new HashMap<>();
+ map.put(OutputFile.entity,"C:\\Users\\21113\\Desktop\\dev\\dashan\\dashan-cloud\\ds-commons\\ds-config\\ds-mybatisplus-support\\src\\main\\java\\com\\ds\\commons\\entity");
+ map.put(OutputFile.xml,"C:\\Users\\21113\\Desktop\\dev\\dashan\\dashan-cloud\\ds-commons\\ds-config\\ds-mybatisplus-support\\src\\main\\java\\com\\ds\\commons\\mpgenerator");
+ FastAutoGenerator.create("jdbc:mysql://server:3306/mini_apps?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false", "mini_apps", "ds4810")
+ .globalConfig(builder -> {
+ builder.author("ds") // 设置作者
+ .enableSpringdoc()
+ .fileOverride() // 覆盖已生成文件
+ .outputDir(System.getProperty("user.dir")+ "/" + "\\ds-commons\\ds-config\\ds-mybatisplus-support" + "/src/main/java"); // 指定输出目录
+ })
+ .dataSourceConfig(builder -> builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
+ int typeCode = metaInfo.getJdbcType().TYPE_CODE;
+ if (typeCode == Types.SMALLINT) {
+ // 自定义类型转换
+ return DbColumnType.INTEGER;
+ }
+ return typeRegistry.getColumnType(metaInfo);
+
+ }))
+ .packageConfig(builder -> {
+ builder.parent("com.ds.commons") // 设置父包名
+ .moduleName("mpgenerator") // 设置父包模块名
+ .controller("api.test")
+ .pathInfo(map); // 设置mapperXml生成路径
+ })
+ .strategyConfig(builder -> {
+ builder
+ .addInclude("tbl_test")
+ .addTablePrefix("tbl_"); // 设置需要生成的表名
+ })
+// .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
+ .execute();
+ }
+}
diff --git a/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/api/MybatisPlusGeneratorApi.java b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/api/MybatisPlusGeneratorApi.java
new file mode 100644
index 0000000..ca864e1
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/api/MybatisPlusGeneratorApi.java
@@ -0,0 +1,29 @@
+package com.ds.commons.support.generator.api;
+
+import com.ds.commons.basemodel.response.R;
+import com.ds.commons.support.generator.service.IMybatisPlusGeneratorService;
+import com.ds.commons.support.generator.vo.GeneratorReq;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author ds
+ * @since 2023/9/4
+ */
+@RestController
+@RequestMapping("/support")
+@AllArgsConstructor
+@Tag(name="代码生成器",description = "代码生成器,用于生成entity,service,controller,xml 文件")
+public class MybatisPlusGeneratorApi {
+
+ private final IMybatisPlusGeneratorService mybatisPlusGeneratorService;
+
+ @PostMapping("/generator")
+ public R generator(@RequestBody GeneratorReq req){
+ return R.success(mybatisPlusGeneratorService.generator(req));
+ }
+}
diff --git a/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/bean/JDBCInfoYml.java b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/bean/JDBCInfoYml.java
new file mode 100644
index 0000000..d857fc6
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/bean/JDBCInfoYml.java
@@ -0,0 +1,22 @@
+package com.ds.commons.support.generator.bean;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author ds
+ * @since 2023/9/4
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "spring.datasource")
+public class JDBCInfoYml {
+
+ private String url;
+
+ private String username;
+
+ private String password;
+
+}
diff --git a/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/bean/MybatisPlusGeneratorYml.java b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/bean/MybatisPlusGeneratorYml.java
new file mode 100644
index 0000000..1d307e4
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/bean/MybatisPlusGeneratorYml.java
@@ -0,0 +1,24 @@
+package com.ds.commons.support.generator.bean;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author ds
+ * @since 2023/9/4
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "mp.generator")
+public class MybatisPlusGeneratorYml {
+
+ private String outputDir;
+
+ private String entityOutputDir;
+
+ private String packagePath;
+
+ private String entityPackagePath;
+
+}
diff --git a/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/config/MybatisPlusGeneratorConfig.java b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/config/MybatisPlusGeneratorConfig.java
new file mode 100644
index 0000000..b5e0025
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/config/MybatisPlusGeneratorConfig.java
@@ -0,0 +1,17 @@
+package com.ds.commons.support.generator.config;
+
+import com.ds.commons.support.generator.api.MybatisPlusGeneratorApi;
+import com.ds.commons.support.generator.bean.JDBCInfoYml;
+import com.ds.commons.support.generator.bean.MybatisPlusGeneratorYml;
+import com.ds.commons.support.generator.service.impl.MybatisPlusGeneratorServiceImpl;
+import org.springframework.context.annotation.Import;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author ds
+ * @since 2023/9/4
+ */
+@Component
+@Import({JDBCInfoYml.class, MybatisPlusGeneratorYml.class, MybatisPlusGeneratorServiceImpl.class, MybatisPlusGeneratorApi.class})
+public class MybatisPlusGeneratorConfig {
+}
diff --git a/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/service/IMybatisPlusGeneratorService.java b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/service/IMybatisPlusGeneratorService.java
new file mode 100644
index 0000000..5e18446
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/service/IMybatisPlusGeneratorService.java
@@ -0,0 +1,11 @@
+package com.ds.commons.support.generator.service;
+
+import com.ds.commons.support.generator.vo.GeneratorReq;
+
+/**
+ * @author ds
+ * @since 2023/9/4
+ */
+public interface IMybatisPlusGeneratorService {
+ boolean generator(GeneratorReq req);
+}
diff --git a/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/service/impl/MybatisPlusGeneratorServiceImpl.java b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/service/impl/MybatisPlusGeneratorServiceImpl.java
new file mode 100644
index 0000000..e8f09d2
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/service/impl/MybatisPlusGeneratorServiceImpl.java
@@ -0,0 +1,75 @@
+package com.ds.commons.support.generator.service.impl;
+
+import com.baomidou.mybatisplus.generator.FastAutoGenerator;
+import com.baomidou.mybatisplus.generator.config.OutputFile;
+import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
+import com.ds.commons.support.generator.bean.JDBCInfoYml;
+import com.ds.commons.support.generator.bean.MybatisPlusGeneratorYml;
+import com.ds.commons.support.generator.service.IMybatisPlusGeneratorService;
+import com.ds.commons.support.generator.vo.GeneratorReq;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.sql.Types;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author ds
+ * @since 2023/9/4
+ */
+@Service
+@AllArgsConstructor
+public class MybatisPlusGeneratorServiceImpl implements IMybatisPlusGeneratorService {
+
+ private final MybatisPlusGeneratorYml mybatisPlusGeneratorYml;
+
+ private final JDBCInfoYml jdbcInfoYml;
+
+ public static void main(String[] args) {
+ System.out.println("com.ds.miniapps.model");
+ System.out.println("com.ds.miniapps.model".replace(".","/"));
+ }
+ private static final String USER_DIR = System.getProperty("user.dir");
+ private static final String JAVA_PATH ="/src/main/java/";
+ private static final String XML_PATH = "/src/main/resources/";
+
+
+ @Override
+ public boolean generator(GeneratorReq req) {
+ Map map = new HashMap<>();
+ map.put(OutputFile.entity, USER_DIR + mybatisPlusGeneratorYml.getEntityOutputDir() + JAVA_PATH + mybatisPlusGeneratorYml.getEntityPackagePath().replace(".","/")+ req.buildPath("/entity"));
+ map.put(OutputFile.xml, USER_DIR + mybatisPlusGeneratorYml.getOutputDir() + XML_PATH + mybatisPlusGeneratorYml.getPackagePath().replace(".","/") + req.buildPath("/mapper"));
+ FastAutoGenerator.create(jdbcInfoYml.getUrl(), jdbcInfoYml.getUsername(), jdbcInfoYml.getPassword())
+ .globalConfig(builder -> {
+ builder.author(req.getAuthor()) // 设置作者
+ .enableSpringdoc()
+ .outputDir(USER_DIR + mybatisPlusGeneratorYml.getOutputDir() + JAVA_PATH); // 指定输出目录
+ })
+ .dataSourceConfig(builder -> builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
+ int typeCode = metaInfo.getJdbcType().TYPE_CODE;
+ if (typeCode == Types.SMALLINT) {
+ // 自定义类型转换
+ return DbColumnType.INTEGER;
+ }
+ return typeRegistry.getColumnType(metaInfo);
+
+ }))
+ .packageConfig(builder -> {
+ builder.parent(mybatisPlusGeneratorYml.getPackagePath()) // 设置父包名
+ .controller(req.buildModule("api"))
+ .service(req.buildModule("service"))
+ .serviceImpl(req.buildModule("service.impl"))
+ .mapper(req.buildModule("mapper"))
+ .entity(req.buildModule("entity"))
+ .pathInfo(map); // 设置mapperXml生成路径
+ })
+ .strategyConfig(builder -> {
+ builder
+ .addInclude(req.getTableNames())
+ .addTablePrefix("tbl_"); // 设置需要生成的表名
+ })
+ .execute();
+ return true;
+ }
+}
diff --git a/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/vo/GeneratorReq.java b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/vo/GeneratorReq.java
new file mode 100644
index 0000000..6fbaeb4
--- /dev/null
+++ b/ds-commons/ds-config/ds-mybatisplus-support/src/main/java/com/ds/commons/support/generator/vo/GeneratorReq.java
@@ -0,0 +1,42 @@
+package com.ds.commons.support.generator.vo;
+
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotBlank;
+import lombok.Data;
+
+import java.util.List;
+
+
+/**
+ * @author ds
+ * @since 2023/9/4
+ */
+@Data
+@Schema(description = "代码生成传参")
+public class GeneratorReq {
+ @Schema(description = "作者",requiredMode = Schema.RequiredMode.NOT_REQUIRED,defaultValue = "ds")
+ private String author="ds";
+ @Schema(description = "子模块名称",requiredMode = Schema.RequiredMode.NOT_REQUIRED,defaultValue = "")
+ private String moduleName;
+
+ @Schema(description = "要进行生成的表名列表")
+ @NotBlank(message = "要进行生成的表名列表不能为空")
+ private List tableNames;
+
+ public String buildModule(String p) {
+ if (StringUtils.isEmpty(moduleName)){
+ return p;
+ }else{
+ return p+"."+moduleName;
+ }
+ }
+
+ public String buildPath(String p) {
+ if (StringUtils.isEmpty(moduleName)){
+ return p;
+ }else{
+ return p+"/"+moduleName;
+ }
+ }
+}
diff --git a/ds-commons/ds-config/ds-web-config/src/main/java/com/ds/commons/web/config/exection/WebGlobalExceptionHandler.java b/ds-commons/ds-config/ds-web-config/src/main/java/com/ds/commons/web/config/exection/WebGlobalExceptionHandler.java
index 4de6304..2eb7a0d 100644
--- a/ds-commons/ds-config/ds-web-config/src/main/java/com/ds/commons/web/config/exection/WebGlobalExceptionHandler.java
+++ b/ds-commons/ds-config/ds-web-config/src/main/java/com/ds/commons/web/config/exection/WebGlobalExceptionHandler.java
@@ -14,6 +14,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -131,4 +132,28 @@ public class WebGlobalExceptionHandler {
log.error(request.getMethod()+"-"+request.getRequestURI() + ":自定义内部异常",e);
return R.failure(e);
}
+
+ /**
+ * 处理Error异常
+ *
+ * @param req
+ * @param e
+ * @return
+ */
+ @ExceptionHandler(value = Error.class)
+ @ResponseBody
+ public R errorHandler(HttpServletRequest req, Error e) {
+ log.error("URL : " + req.getRequestURL().toString());
+ log.error("HTTP_METHOD : " + req.getMethod());
+ log.error("未知Error!原因是:", e);
+ // 发送警报通知
+// sendAlertNotification();
+
+ // 执行清理操作(关闭数据库连接、释放资源等)
+// cleanup();
+
+ // 终止应用程序
+ System.exit(1);
+ return R.failure();
+ }
}
\ No newline at end of file
diff --git a/ds-commons/ds-config/pom.xml b/ds-commons/ds-config/pom.xml
index f180bc2..0cb20b1 100644
--- a/ds-commons/ds-config/pom.xml
+++ b/ds-commons/ds-config/pom.xml
@@ -13,6 +13,8 @@
pom
ds-web-config
+ ds-mybatisplus-config
+ ds-mybatisplus-support