| | |
| | | private static final String DB_NAME = "water_basic"; |
| | | private static final String AUTHOR = "lin.liu"; |
| | | |
| | | private static Connection CONN = null; |
| | | public static Connection CONN = null; |
| | | private static final String DRIVER = "org.postgresql.Driver"; |
| | | private static final String CONNECTION_STR = "jdbc:postgresql://" + HOST + ":" + PORT + "/" + DB_NAME; |
| | | |
| | |
| | | "import com.lunhan.xxx.entity.dto.*;", |
| | | "import com.lunhan.xxx.entity.enums.*;", |
| | | "import com.lunhan.xxx.repository.BasicMapperImpl;", |
| | | "import org.springframework.stereotype.Repository;" |
| | | "import org.springframework.stereotype.Repository;", |
| | | "", |
| | | "import java.util.List;" |
| | | }; |
| | | //endregion |
| | | |
| | |
| | | * 只生成以下配置的表 |
| | | */ |
| | | private static final List<String> ONLY_TABLES = Arrays.asList( |
| | | "admin_menus" |
| | | |
| | | ); |
| | | |
| | | public static void main(String[] args) { |
| | |
| | | listColumn.add("(type = IdType.ASSIGN_ID)"); |
| | | } |
| | | } |
| | | String columnAnnotation = "\t@TableField(\"" + name + "\""; |
| | | //忽略最后修改时间这一列的新增和编辑 |
| | | if (!"id".equals(name)) { |
| | | String columnAnnotation = "\t@TableField(\"" + name + "\""; |
| | | //忽略最后修改时间这一列的新增和编辑 |
| | | // if (UPDATE_TIME_COLUMNS.stream().anyMatch(c -> c.equalsIgnoreCase(name))) { |
| | | // columnAnnotation += ", insertable = false, updatable = false"; |
| | | // } |
| | | listColumn.add(columnAnnotation + ")"); |
| | | } |
| | | if ("datachange_lasttime".equalsIgnoreCase(name)) { |
| | | propName = "dataChangeLastTime"; |
| | | columnNameUpper = "DataChangeLastTime"; |
| | | } |
| | | listColumn.add(columnAnnotation + ")"); |
| | | //追加列 |
| | | listColumn.add(String.format("\tprivate %s %s;", javaType, propName)); |
| | | |
| | |
| | | } |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(SET_CLASS_DESC_TPL |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc) |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc) |
| | | .replaceAll("\\{\\#\\=author\\}", AUTHOR) |
| | | .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/")) |
| | | ); |
| | |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(StringUtil.join(listColumn, ConstantFactory.STR_NEWLINE)); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(StringUtil.join(listGetterSetter, ConstantFactory.STR_NEWLINE)); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | if (!isData) { |
| | | content.append(StringUtil.join(listGetterSetter, ConstantFactory.STR_NEWLINE)); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | } |
| | | content.append("}"); |
| | | |
| | | writeFile(GenCodeGauss.OutSet.PO, modelName + GenCodeGauss.SuffixSet.PO + ".java", content.toString()); |
| | |
| | | |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(SET_CLASS_DESC_TPL |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc) |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc) |
| | | .replaceAll("\\{\\#\\=author\\}", AUTHOR) |
| | | .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/")) |
| | | ); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | if (isData) { |
| | | content.append("@Data"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | } |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("public class "); |
| | |
| | | String modelName = underline2Camel(tableName, true); |
| | | String searchName = "Search" + modelName; |
| | | String tableNamePackage = tableName.toLowerCase().replaceAll("_", ""); |
| | | boolean isData = Objects.equals(SET_PO_Getter, 2); |
| | | |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("package "); |
| | | content.append(GenCodeGauss.PackageSet.SEARCH + ConstantFactory.STR_SEMICOLON); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | if (isData) { |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("import lombok.Data;"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | } |
| | | if (SET_SEARCH_IMPORT.length > 0) { |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | for (String s : SET_SEARCH_IMPORT) { |
| | |
| | | } |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(SET_CLASS_DESC_TPL |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc) |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc) |
| | | .replaceAll("\\{\\#\\=author\\}", AUTHOR) |
| | | .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/")) |
| | | ); |
| | | if (isData) { |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("@Data"); |
| | | } |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("public class " + searchName + " extends SearchBasicDTO {"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t@Override"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\tpublic String toString() {"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\treturn \"" + searchName + "{\" + \"'\" +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\"keywords='\" + getKeywords() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", listId =\" + getListId() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", status =\" + getStatus() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", listStatus =\" + getListStatus() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", createTimeRange='\" + getCreateTimeRange() + \"'\" +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", createTimeStart =\" + getCreateTimeEnd() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", createTimeEnd =\" + getCreateTimeEnd() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", lastId =\" + getListId() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", orderBy='\" + getOrderBy() + \"'\" +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t'}';"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t}"); |
| | | if (!isData) { |
| | | content.append("\t@Override"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\tpublic String toString() {"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\treturn \"" + searchName + "{\" + \"'\" +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\"keywords='\" + getKeywords() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", listId =\" + getListId() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", status =\" + getStatus() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", listStatus =\" + getListStatus() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", createTimeRange='\" + getCreateTimeRange() + \"'\" +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", createTimeStart =\" + getCreateTimeEnd() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", createTimeEnd =\" + getCreateTimeEnd() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", lastId =\" + getListId() +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t\t\", orderBy='\" + getOrderBy() + \"'\" +"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t\t'}';"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t}"); |
| | | } |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("}"); |
| | | |
| | |
| | | content.append(poName + ";\n"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(SET_CLASS_DESC_TPL |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc) |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc) |
| | | .replaceAll("\\{\\#\\=author\\}", AUTHOR) |
| | | .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/")) |
| | | ); |
| | |
| | | content.append(daoName); |
| | | content.append(" extends BasicMapperImpl<"); |
| | | content.append(modelName + GenCodeGauss.SuffixSet.PO); |
| | | content.append("> {"); |
| | | content.append(", " + mapperName + "> {"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("\t" + daoName + "(" + mapperName + " mapper) {\n"); |
| | | content.append("\t\tsuper(mapper);\n"); |
| | |
| | | "\t\t\t\t\tswitch (orderBy) {\n" + |
| | | "\t\t\t\t\t\t// 主键\n" + |
| | | "\t\t\t\t\t\tcase ID:\n" + |
| | | "\t\t\t\t\t\t\tqueryWrapper.orderByAsc(" + poName + "::getId);\n" + |
| | | "\t\t\t\t\t\t\tqueryWrapper.orderByDesc(" + poName + "::getId);\n" + |
| | | "\t\t\t\t\t\t\tbreak;\n" + |
| | | "\t\t\t\t\t\t// 数据创建时间\n" + |
| | | "\t\t\t\t\t\tcase CREATE_TIME:\n" + |
| | | "\t\t\t\t\t\t\tqueryWrapper.orderByAsc(" + poName + "::getCreateTime);\n" + |
| | | "\t\t\t\t\t\t\tqueryWrapper.orderByDesc(" + poName + "::getCreateTime);\n" + |
| | | "\t\t\t\t\t\t\tbreak;\n" + |
| | | "\t\t\t\t\t\t// 最后更新时间\n" + |
| | | "\t\t\t\t\t\tcase UPDATE_TIME:\n" + |
| | | "\t\t\t\t\t\t\tqueryWrapper.orderByAsc(" + poName + "::getUpdateTime);\n" + |
| | | "\t\t\t\t\t\t\tqueryWrapper.orderByDesc(" + poName + "::getUpdateTime);\n" + |
| | | "\t\t\t\t\t\t\tbreak;\n" + |
| | | "\t\t\t\t\t}\n" + |
| | | "\t\t\t\t}\n" + |
| | |
| | | "\t\t} else {\n" + |
| | | "\t\t\tqueryWrapper.orderByDesc(" + poName + "::getId);\n" + |
| | | "\t\t}\n" + |
| | | "\t\tPage<" + poName + "> pageResult = DB.selectPage(new Page<>(search.getPage(), search.getLimit()), queryWrapper);\n" + |
| | | "\t\tPage<" + poName + "> pageResult = super.selectPage(new Page<>(search.getPage(), search.getLimit()), queryWrapper);\n" + |
| | | "\t\treturn new PagerResult<>(pageResult.getSize(), pageResult.getPages(), pageResult.getTotal(), pageResult.getRecords());\n" + |
| | | "\t}"); |
| | | "\t}\n" + |
| | | "\n" + |
| | | "\tpublic Boolean add(" + poName + " item) {\n" + |
| | | "\t\tint rowCount = super.insert(item);\n" + |
| | | "\t\treturn rowCount == 1;\n" + |
| | | "\t}\n" + |
| | | "\n" + |
| | | "\tpublic Boolean addNotIncrement(" + poName + " item) {\n" + |
| | | "\t\tint rowCount = super.insert(item);\n" + |
| | | "\t\treturn rowCount == 1;\n" + |
| | | "\t}\n" + |
| | | "\n" + |
| | | "\tpublic " + poName + " getById(Long id) {\n" + |
| | | "\t\treturn super.get(id);\n" + |
| | | "\t}\n" + |
| | | "\n" + |
| | | "\tpublic List<" + poName + "> getListById(List<Long> listId) {\n" + |
| | | "\t\treturn super.getList(listId);\n" + |
| | | "\t}\n" |
| | | ); |
| | | content.append("}"); |
| | | |
| | | if (new File(GenCodeGauss.OutSet.MAPPER_IMPL + daoName + ".java").exists()) { |
| | |
| | | } |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(SET_CLASS_DESC_TPL |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc) |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc) |
| | | .replaceAll("\\{\\#\\=author\\}", AUTHOR) |
| | | .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/")) |
| | | ); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | if (isData) { |
| | | content.append("@Data"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | } |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("public class "); |
| | |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(StringUtil.join(listColumn, ConstantFactory.STR_NEWLINE)); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(StringUtil.join(listGetterSetter, ConstantFactory.STR_NEWLINE)); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | if (!isData) { |
| | | content.append(StringUtil.join(listGetterSetter, ConstantFactory.STR_NEWLINE)); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | } |
| | | content.append("}"); |
| | | |
| | | if (new File(GenCodeGauss.OutSet.RequestDTO + tableNamePackage + "/" + createDTOName + ".java").exists()) { |
| | |
| | | } |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(SET_CLASS_DESC_TPL |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc) |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc) |
| | | .replaceAll("\\{\\#\\=author\\}", AUTHOR) |
| | | .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/")) |
| | | ); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | if (isData) { |
| | | content.append("@Data"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | } |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("public class "); |
| | |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(StringUtil.join(listColumn, ConstantFactory.STR_NEWLINE)); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(StringUtil.join(listGetterSetter, ConstantFactory.STR_NEWLINE)); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | if (!isData) { |
| | | content.append(StringUtil.join(listGetterSetter, ConstantFactory.STR_NEWLINE)); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | } |
| | | content.append("}"); |
| | | |
| | | if (new File(GenCodeGauss.OutSet.RequestDTO + tableNamePackage + "/" + modifyDTOName + ".java").exists()) { |
| | |
| | | |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(SET_CLASS_DESC_TPL |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc) |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc) |
| | | ); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append("@Mapper"); |
| | |
| | | content.append(responseDTOName + ";\n"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(SET_CLASS_DESC_TPL |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc) |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc) |
| | | .replaceAll("\\{\\#\\=author\\}", AUTHOR) |
| | | .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/")) |
| | | ); |
| | |
| | | " // 设置记录创建时间\n" + |
| | | " item.setCreateTime(LocalDateTimeUtil.nowTimeStamp());\n" + |
| | | " // 是否删除(逻辑删除)初始值\n" + |
| | | " //item.setIsDelete(EYesOrNo.NO.getValue());\n" + |
| | | " item.setIsDelete(EYesOrNo.NO.getValue());\n" + |
| | | "\n" + |
| | | " int rowCount = mapper.insert(item);\n" + |
| | | " if (rowCount != 1) {\n" + |
| | |
| | | content.append(responseDTOName + ";\n"); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(SET_CLASS_DESC_TPL |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc) |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc) |
| | | .replaceAll("\\{\\#\\=author\\}", AUTHOR) |
| | | .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/")) |
| | | ); |
| | |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(ConstantFactory.STR_NEWLINE); |
| | | content.append(SET_CLASS_DESC_TPL |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc + " mapper") |
| | | .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc + " mapper") |
| | | .replaceAll("\\{\\#\\=author\\}", AUTHOR) |
| | | .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/")) |
| | | ); |
| | |
| | | sql = ""; |
| | | |
| | | // 触发器:自动赋值最后更新时间 |
| | | sql += "CREATE TRIGGER \"TG_" + tableName + "\" BEFORE INSERT OR UPDATE OF \"update_time\" ON \"public\".\"" + tableName + "\"\n" + |
| | | sql += "CREATE TRIGGER \"TG_" + tableName + "\" BEFORE INSERT OR UPDATE ON \"public\".\"" + tableName + "\"\n" + |
| | | "FOR EACH ROW\n" + |
| | | "EXECUTE PROCEDURE \"public\".\"update_timestamp_column\"();"; |
| | | result = GenCodeGauss.execSql(connect, sql); |