处理代码生成器关联查询

This commit is contained in:
TinyAnts 2022-12-30 10:35:58 +08:00
parent 9d4964af1b
commit c5781cd796
5 changed files with 19 additions and 1 deletions

View File

@ -264,6 +264,7 @@ public class GenerateServiceImpl implements IGenerateService {
model.setGenType(genParam.getGenType());
model.setGenPath(genParam.getGenPath());
model.setSubTableFk(genParam.getSubTableFk());
model.setSubTableFr(genParam.getSubTableFr());
model.setSubTableName(genParam.getSubTableName());
genTableMapper.updateById(model);

View File

@ -248,4 +248,17 @@ public class GenUtil {
}
}
/**
* 获取表的别名
*
* @param tableName 表名
* @return String
*/
public static String getTableAlias(String tableName) {
StringBuilder val = new StringBuilder();
for (String name : tableName.split("_")) {
val.append(name.charAt(0));
}
return val.toString();
}
}

View File

@ -70,6 +70,7 @@ public class VelocityUtil {
// 替换前缀
table.setSubTableName(table.getSubTableName().replace(GlobalConfig.tablePrefix, ""));
System.out.println(GenUtil.getTableAlias(table.getSubTableName()));
// 设置模板变量
VelocityContext velocityContext = new VelocityContext();
@ -84,6 +85,7 @@ public class VelocityUtil {
velocityContext.put("notesType", GenConfig.notesType);
velocityContext.put("table", table);
velocityContext.put("columns", columns);
velocityContext.put("subTableAlias", GenUtil.getTableAlias(table.getSubTableName()));
velocityContext.put("dateFields", SqlConstants.COLUMN_TIME_NAME);
velocityContext.put("primaryKey", primaryKey);
velocityContext.put("primaryField", primaryField);

View File

@ -88,4 +88,6 @@ public class GenParam implements Serializable {
private String subTableFk = "";
private String subTableFr = "";
}

View File

@ -93,7 +93,7 @@ public class ${EntityName}ServiceImpl implements I${EntityName}Service {
#set($queryWrapper = "mpjQueryWrapper")
MPJQueryWrapper<${EntityName}> mpjQueryWrapper = new MPJQueryWrapper<>();
mpjQueryWrapper.selectAll(${EntityName}.class);
mpjQueryWrapper.innerJoin("?_$table.subTableName f ON f.$table.SubTableFr=t.$table.SubTableFk".replace("?_", GlobalConfig.tablePrefix));
mpjQueryWrapper.innerJoin("?_$table.subTableName $subTableAlias ON $subTableAlias.$table.SubTableFk=t.$table.SubTableFr".replace("?_", GlobalConfig.tablePrefix));
#if($allFields.contains("is_delete"))
mpjQueryWrapper.eq("t.is_delete", 0);
#end