diff --git a/blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java b/blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java index 76f5e89d..6a0d9d6a 100644 --- a/blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java +++ b/blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java @@ -27,6 +27,16 @@ public interface CommonConstant { */ String SENTINEL_PROD_ADDR = "192.168.186.129:8858"; + /** + * sword 系统名 + */ + String SWORD_NAME = "sword"; + + /** + * saber 系统名 + */ + String SABER_NAME = "saber"; + /** * 顶级父节点id */ diff --git a/blade-ops/blade-develop/src/main/java/org/springblade/develop/controller/CodeController.java b/blade-ops/blade-develop/src/main/java/org/springblade/develop/controller/CodeController.java index c87b9c11..6d793fab 100644 --- a/blade-ops/blade-develop/src/main/java/org/springblade/develop/controller/CodeController.java +++ b/blade-ops/blade-develop/src/main/java/org/springblade/develop/controller/CodeController.java @@ -97,10 +97,11 @@ public class CodeController extends BladeController { */ @PostMapping("/gen-code") @ApiOperation(value = "代码生成", notes = "传入ids", position = 8) - public R genCode(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { + public R genCode(@ApiParam(value = "主键集合", required = true) @RequestParam String ids, @RequestParam(defaultValue = "sword") String system) { Collection codes = codeService.listByIds(Func.toIntList(ids)); codes.forEach(code -> { BladeGenerator generator = new BladeGenerator(); + generator.setSystemName(system); generator.setServiceName(code.getServiceName()); generator.setPackageName(code.getPackageName()); generator.setPackageDir(code.getApiPath()); diff --git a/blade-ops/blade-develop/src/main/java/org/springblade/develop/support/BladeGenerator.java b/blade-ops/blade-develop/src/main/java/org/springblade/develop/support/BladeGenerator.java index 37461ee7..6d7456e1 100644 --- a/blade-ops/blade-develop/src/main/java/org/springblade/develop/support/BladeGenerator.java +++ b/blade-ops/blade-develop/src/main/java/org/springblade/develop/support/BladeGenerator.java @@ -28,6 +28,7 @@ import com.baomidou.mybatisplus.generator.config.po.TableInfo; import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; import lombok.Data; import lombok.extern.slf4j.Slf4j; +import org.springblade.common.constant.CommonConstant; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringUtil; import org.springframework.core.io.ClassPathResource; @@ -46,6 +47,10 @@ import java.util.*; @Data @Slf4j public class BladeGenerator { + /** + * 代码所在系统 + */ + private String systemName = CommonConstant.SWORD_NAME; /** * 代码所在服务名 */ @@ -195,48 +200,63 @@ public class BladeGenerator { } }); if (Func.isNotBlank(packageWebDir)) { - focList.add(new FileOutConfig("/templates/sword/action.js.vm") { - @Override - public String outputFile(TableInfo tableInfo) { - return getOutputWebDir() + "/actions" + "/" + tableInfo.getEntityName().toLowerCase() + ".js"; - } - }); - focList.add(new FileOutConfig("/templates/sword/model.js.vm") { - @Override - public String outputFile(TableInfo tableInfo) { - return getOutputWebDir() + "/models" + "/" + tableInfo.getEntityName().toLowerCase() + ".js"; - } - }); - focList.add(new FileOutConfig("/templates/sword/service.js.vm") { - @Override - public String outputFile(TableInfo tableInfo) { - return getOutputWebDir() + "/services" + "/" + tableInfo.getEntityName().toLowerCase() + ".js"; - } - }); - focList.add(new FileOutConfig("/templates/sword/list.js.vm") { - @Override - public String outputFile(TableInfo tableInfo) { - return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + ".js"; - } - }); - focList.add(new FileOutConfig("/templates/sword/add.js.vm") { - @Override - public String outputFile(TableInfo tableInfo) { - return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "Add.js"; - } - }); - focList.add(new FileOutConfig("/templates/sword/edit.js.vm") { - @Override - public String outputFile(TableInfo tableInfo) { - return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "Edit.js"; - } - }); - focList.add(new FileOutConfig("/templates/sword/view.js.vm") { - @Override - public String outputFile(TableInfo tableInfo) { - return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "View.js"; - } - }); + if (Func.equals(systemName, CommonConstant.SWORD_NAME)) { + focList.add(new FileOutConfig("/templates/sword/action.js.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return getOutputWebDir() + "/actions" + "/" + tableInfo.getEntityName().toLowerCase() + ".js"; + } + }); + focList.add(new FileOutConfig("/templates/sword/model.js.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return getOutputWebDir() + "/models" + "/" + tableInfo.getEntityName().toLowerCase() + ".js"; + } + }); + focList.add(new FileOutConfig("/templates/sword/service.js.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return getOutputWebDir() + "/services" + "/" + tableInfo.getEntityName().toLowerCase() + ".js"; + } + }); + focList.add(new FileOutConfig("/templates/sword/list.js.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + ".js"; + } + }); + focList.add(new FileOutConfig("/templates/sword/add.js.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "Add.js"; + } + }); + focList.add(new FileOutConfig("/templates/sword/edit.js.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "Edit.js"; + } + }); + focList.add(new FileOutConfig("/templates/sword/view.js.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "View.js"; + } + }); + } else if (Func.equals(systemName, CommonConstant.SABER_NAME)) { + focList.add(new FileOutConfig("/templates/saber/api.js.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return getOutputWebDir() + "/api" + "/" + servicePackage.toLowerCase() + "/" + tableInfo.getEntityName().toLowerCase() + ".js"; + } + }); + focList.add(new FileOutConfig("/templates/saber/crud.vue.vm") { + @Override + public String outputFile(TableInfo tableInfo) { + return getOutputWebDir() + "/views" + "/" + servicePackage.toLowerCase() + "/" + tableInfo.getEntityName().toLowerCase() + ".vue"; + } + }); + } } cfg.setFileOutConfigList(focList); return cfg; @@ -265,7 +285,7 @@ public class BladeGenerator { * @return outputDir */ public String getOutputDir() { - return Func.isBlank(packageDir) ? System.getProperty("user.dir") : packageDir + "/src/main/java"; + return (Func.isBlank(packageDir) ? System.getProperty("user.dir") : packageDir) + "/src/main/java"; } /** @@ -274,7 +294,7 @@ public class BladeGenerator { * @return outputDir */ public String getOutputWebDir() { - return Func.isBlank(packageWebDir) ? System.getProperty("user.dir") : packageWebDir + "/src"; + return (Func.isBlank(packageWebDir) ? System.getProperty("user.dir") : packageWebDir) + "/src"; } /** diff --git a/blade-ops/blade-develop/src/main/java/org/springblade/develop/support/CodeGenerator.java b/blade-ops/blade-develop/src/main/java/org/springblade/develop/support/CodeGenerator.java index 3e80f0f6..accf4c11 100644 --- a/blade-ops/blade-develop/src/main/java/org/springblade/develop/support/CodeGenerator.java +++ b/blade-ops/blade-develop/src/main/java/org/springblade/develop/support/CodeGenerator.java @@ -29,9 +29,13 @@ public class CodeGenerator { */ public static String PACKAGE_NAME = "org.springblade.demo"; /** - * 代码生成的地址 + * 前端代码生成所属系统 */ - public static String PACKAGE_DIR = "/blade-ops/blade-codegen/src/main/java"; + public static String SYSTEM_NAME = "saber"; + /** + * 前端代码生成地址 + */ + public static String PACKAGE_WEB_DIR = "/Users/chill/Workspaces/dev/Saber"; /** * 需要去掉的表前缀 */ @@ -39,7 +43,7 @@ public class CodeGenerator { /** * 需要生成的表名(两者只能取其一) */ - public static String[] INCLUDE_TABLES = {"blade_blog"}; + public static String[] INCLUDE_TABLES = {"blade_notice"}; /** * 需要排除的表名(两者只能取其一) */ @@ -53,13 +57,15 @@ public class CodeGenerator { */ public static String[] SUPER_ENTITY_COLUNMS = {"id", "create_time", "create_user", "update_time", "update_user", "status", "is_deleted"}; + /** * RUN THIS */ - public static void generate() { + public static void main(String[] args) { BladeGenerator generator = new BladeGenerator(); + generator.setSystemName(SYSTEM_NAME); generator.setPackageName(PACKAGE_NAME); - generator.setPackageDir(PACKAGE_DIR); + generator.setPackageWebDir(PACKAGE_WEB_DIR); generator.setTablePrefix(TABLE_PREFIX); generator.setIncludeTables(INCLUDE_TABLES); generator.setExcludeTables(EXCLUDE_TABLES); diff --git a/blade-ops/blade-develop/src/main/resources/templates/saber/api.js.vm b/blade-ops/blade-develop/src/main/resources/templates/saber/api.js.vm new file mode 100644 index 00000000..1c65e554 --- /dev/null +++ b/blade-ops/blade-develop/src/main/resources/templates/saber/api.js.vm @@ -0,0 +1,50 @@ +import request from '@/router/axios'; + +export const getList = (current, size, params) => { + return request({ + url: '/api/$!{cfg.serviceName}/$!{table.entityPath}/list', + method: 'get', + params: { + ...params, + current, + size, + } + }) +} + +export const getDetail = (id) => { + return request({ + url: '/api/$!{cfg.serviceName}/$!{table.entityPath}/detail', + method: 'get', + params: { + id + } + }) +} + +export const remove = (ids) => { + return request({ + url: '/api/$!{cfg.serviceName}/$!{table.entityPath}/remove', + method: 'post', + params: { + ids, + } + }) +} + +export const add = (row) => { + return request({ + url: '/api/$!{cfg.serviceName}/$!{table.entityPath}/submit', + method: 'post', + data: row + }) +} + +export const update = (row) => { + return request({ + url: '/api/$!{cfg.serviceName}/$!{table.entityPath}/submit', + method: 'post', + data: row + }) +} + diff --git a/blade-ops/blade-develop/src/main/resources/templates/saber/crud.vue.vm b/blade-ops/blade-develop/src/main/resources/templates/saber/crud.vue.vm new file mode 100644 index 00000000..616be75e --- /dev/null +++ b/blade-ops/blade-develop/src/main/resources/templates/saber/crud.vue.vm @@ -0,0 +1,174 @@ + + + + +