【修复】修复一些代码生成的已知问题

This commit is contained in:
小诺 2020-12-29 21:13:22 +08:00 committed by 小诺
parent 26e57a749a
commit d061671c45
5 changed files with 32 additions and 30 deletions

View File

@ -1,6 +1,8 @@
package com.cn.xiaonuo.generate.core.config; package com.cn.xiaonuo.generate.core.config;
import java.io.File;
/** /**
* 代码生成配置 * 代码生成配置
* *
@ -9,6 +11,11 @@ package com.cn.xiaonuo.generate.core.config;
*/ */
public class Config { public class Config {
/**
* 路径分离不通的机器取不同的路径
*/
public static String FILE_SEP = File.separator;
/** /**
* 存放vm模板位置 * 存放vm模板位置
*/ */
@ -63,20 +70,20 @@ public class Config {
/** /**
* 各个代码存放路径文件夹 * 各个代码存放路径文件夹
*/ */
public static String[] xnCodeGenFilePath (String busName, String packageName, String className) { public static String[] xnCodeGenFilePath (String busName, String packageName) {
String packageNameString = packageName.replace(".",File.separator) + File.separator; String packageNameString = packageName.replace(".",FILE_SEP) + FILE_SEP;
controllerPath = BASE_JAVA_PAHT + packageNameString + MODULAR_NAME + File.separator + busName + File.separator + "controller" + File.separator; controllerPath = BASE_JAVA_PAHT + packageNameString + MODULAR_NAME + FILE_SEP + busName + FILE_SEP + "controller" + FILE_SEP;
entityPath = BASE_JAVA_PAHT + packageNameString + MODULAR_NAME + File.separator + busName + File.separator + "entity" + File.separator; entityPath = BASE_JAVA_PAHT + packageNameString + MODULAR_NAME + FILE_SEP + busName + FILE_SEP + "entity" + FILE_SEP;
enumsPath = BASE_JAVA_PAHT+ packageNameString + MODULAR_NAME + File.separator + busName + File.separator + "enums" + File.separator; enumsPath = BASE_JAVA_PAHT+ packageNameString + MODULAR_NAME + FILE_SEP + busName + FILE_SEP + "enums" + FILE_SEP;
mapperPath = BASE_JAVA_PAHT + packageNameString + MODULAR_NAME + File.separator + busName + File.separator + "mapper" + File.separator; mapperPath = BASE_JAVA_PAHT + packageNameString + MODULAR_NAME + FILE_SEP + busName + FILE_SEP + "mapper" + FILE_SEP;
mappingPath = mapperPath + File.separator + "mapping" + File.separator; mappingPath = mapperPath + FILE_SEP + "mapping" + FILE_SEP;
paramPath = BASE_JAVA_PAHT+ File.separator + packageNameString + MODULAR_NAME + File.separator + busName + File.separator + "param" + File.separator; paramPath = BASE_JAVA_PAHT+ FILE_SEP + packageNameString + MODULAR_NAME + FILE_SEP + busName + FILE_SEP + "param" + FILE_SEP;
servicePath = BASE_JAVA_PAHT+ File.separator + packageNameString + MODULAR_NAME + File.separator + busName + File.separator + "service" + File.separator; servicePath = BASE_JAVA_PAHT+ FILE_SEP + packageNameString + MODULAR_NAME + FILE_SEP + busName + FILE_SEP + "service" + FILE_SEP;
serviceImplPath = servicePath + File.separator + "impl" + File.separator; serviceImplPath = servicePath + FILE_SEP + "impl" + FILE_SEP;
manageJsPath = BASE_VUE_PAHT + File.separator + "api" + File.separator + MODULAR_NAME + File.separator + "main" + File.separator + busName + File.separator; manageJsPath = BASE_VUE_PAHT + FILE_SEP + "api" + FILE_SEP + MODULAR_NAME + FILE_SEP + "main" + FILE_SEP + busName + FILE_SEP;
vueIndexPath = BASE_VUE_PAHT + File.separator + "views" + File.separator + "main" + File.separator + busName + File.separator + StrUtil.lowerFirst(className) + File.separator; vueIndexPath = BASE_VUE_PAHT + FILE_SEP + "views" + FILE_SEP + "main" + FILE_SEP + busName + FILE_SEP;
vueAddFromPath = BASE_VUE_PAHT + File.separator + "views" + File.separator + "main" + File.separator + busName + File.separator + StrUtil.lowerFirst(className) + File.separator; vueAddFromPath = BASE_VUE_PAHT + FILE_SEP + "views" + FILE_SEP + "main" + FILE_SEP + busName + FILE_SEP;
vueEditFromPath = BASE_VUE_PAHT + File.separator + "views" + File.separator + "main" + File.separator + busName + File.separator + StrUtil.lowerFirst(className) + File.separator; vueEditFromPath = BASE_VUE_PAHT + FILE_SEP + "views" + FILE_SEP + "main" + FILE_SEP + busName + FILE_SEP;
return new String[] { return new String[] {
controllerPath, entityPath, enumsPath, mapperPath, mappingPath, paramPath, servicePath, serviceImplPath, manageJsPath, vueIndexPath, vueAddFromPath, vueEditFromPath controllerPath, entityPath, enumsPath, mapperPath, mappingPath, paramPath, servicePath, serviceImplPath, manageJsPath, vueIndexPath, vueAddFromPath, vueEditFromPath
}; };
@ -104,13 +111,13 @@ public class Config {
* 本地项目根目录 * 本地项目根目录
*/ */
public static String getLocalPath () { public static String getLocalPath () {
return System.getProperty("user.dir") + "\\" + BASE_MODULAR_NAME + "\\"; return System.getProperty("user.dir") + FILE_SEP + BASE_MODULAR_NAME + FILE_SEP;
} }
/** /**
* vue前端 * vue前端
*/ */
public static String getLocalFrontPath () { public static String getLocalFrontPath () {
return System.getProperty("user.dir") + "\\" ; return System.getProperty("user.dir") + FILE_SEP ;
} }
} }

View File

@ -266,12 +266,12 @@ public class CodeGenerateServiceImpl extends ServiceImpl<CodeGenerateMapper, Cod
//实例化一个VelocityEngine对象 //实例化一个VelocityEngine对象
VelocityEngine velocityEngine=new VelocityEngine(properties); VelocityEngine velocityEngine=new VelocityEngine(properties);
String[] filePath = Config.xnCodeGenFilePath(xnCodeGenParam.getBusName(), xnCodeGenParam.getPackageName(), xnCodeGenParam.getClassName()); String[] filePath = Config.xnCodeGenFilePath(xnCodeGenParam.getBusName(), xnCodeGenParam.getPackageName());
for (int i = 0; i < filePath.length; i++) { for (int i = 0; i < filePath.length; i++) {
String templateName = Config.xnCodeGenTempFile[i]; String templateName = Config.xnCodeGenTempFile[i];
String fileBaseName = ResetFileBaseName(xnCodeGenParam.getClassName(), String fileBaseName = ResetFileBaseName(xnCodeGenParam.getClassName(),
templateName.substring(templateName.indexOf("/") + 1, templateName.lastIndexOf(TEMP_SUFFIX))); templateName.substring(templateName.indexOf(Config.FILE_SEP) + 1, templateName.lastIndexOf(TEMP_SUFFIX)));
String path = Config.getLocalPath (); String path = Config.getLocalPath ();
// 前端VUE位置有所变化 // 前端VUE位置有所变化
if (fileBaseName.contains(INDEX_PAGE_NAME) || fileBaseName.contains(ADD_FORM_PAGE_NAME) || if (fileBaseName.contains(INDEX_PAGE_NAME) || fileBaseName.contains(ADD_FORM_PAGE_NAME) ||
@ -308,12 +308,12 @@ public class CodeGenerateServiceImpl extends ServiceImpl<CodeGenerateMapper, Cod
Util.initVelocity(); Util.initVelocity();
XnVelocityContext context = new XnVelocityContext(); XnVelocityContext context = new XnVelocityContext();
String[] filePath = Config.xnCodeGenFilePath(xnCodeGenParam.getBusName(), xnCodeGenParam.getPackageName(), xnCodeGenParam.getClassName()); String[] filePath = Config.xnCodeGenFilePath(xnCodeGenParam.getBusName(), xnCodeGenParam.getPackageName());
for (int a = 0; a < filePath.length; a++) { for (int a = 0; a < filePath.length; a++) {
String templateName = Config.xnCodeGenTempFile[a]; String templateName = Config.xnCodeGenTempFile[a];
String fileBaseName = ResetFileBaseName(xnCodeGenParam.getClassName(), String fileBaseName = ResetFileBaseName(xnCodeGenParam.getClassName(),
templateName.substring(templateName.indexOf("/") + 1, templateName.lastIndexOf(TEMP_SUFFIX))); templateName.substring(templateName.indexOf(Config.FILE_SEP) + 1, templateName.lastIndexOf(TEMP_SUFFIX)));
XnZipOutputStream(context.createVelContext(xnCodeGenParam), XnZipOutputStream(context.createVelContext(xnCodeGenParam),
Config.templatePath + templateName, Config.templatePath + templateName,
filePath[a] + fileBaseName, filePath[a] + fileBaseName,

View File

@ -37,7 +37,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
/** /**
* ${functionName}控制器 * ${functionName}控制器
@ -87,8 +86,8 @@ public class ${ClassName}Controller {
@Permission @Permission
@PostMapping("/${className}/delete") @PostMapping("/${className}/delete")
@BusinessLog(title = "${functionName}_删除", opType = LogAnnotionOpTypeEnum.DELETE) @BusinessLog(title = "${functionName}_删除", opType = LogAnnotionOpTypeEnum.DELETE)
public ResponseData delete(@RequestBody @Validated(${ClassName}Param.delete.class) List<${ClassName}Param> ${className}ParamList) { public ResponseData delete(@RequestBody @Validated(${ClassName}Param.delete.class) ${ClassName}Param ${className}Param) {
${className}Service.delete(${className}ParamList); ${className}Service.delete(${className}Param);
return new SuccessResponseData(); return new SuccessResponseData();
} }

View File

@ -68,7 +68,7 @@ public interface ${ClassName}Service extends IService<${ClassName}> {
* @author ${authorName} * @author ${authorName}
* @date ${createDateString} * @date ${createDateString}
*/ */
void delete(List<${ClassName}Param> ${className}ParamList); void delete(${ClassName}Param ${className}Param);
/** /**
* 编辑${functionName} * 编辑${functionName}

View File

@ -111,16 +111,12 @@ public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${C
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void delete(List<${ClassName}Param> ${className}ParamList) { public void delete(${ClassName}Param ${className}Param) {
${className}ParamList.forEach(${className}Param -> {
${ClassName} ${className} = this.query${ClassName}(${className}Param);
#foreach ($column in $tableField) #foreach ($column in $tableField)
#if (${column.primaryKeyFlag}) #if (${column.primaryKeyFlag})
this.removeById(${className}.get${column.columnKeyName}()); this.removeById(${className}Param.get${column.columnKeyName}());
});
#end #end
#end #end
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)