liulin
2024-12-02 abda7b6998f4fad0a5b62f718c297405079394d8
src/test/java/com/lunhan/xxx/GenCodeGauss.java
@@ -36,7 +36,7 @@
        public static final String MAPPER = "./src/main/java/com/lunhan/xxx/repository/mapper/";
        public static final String SERVICE = "./src/main/java/com/lunhan/xxx/service/";
        public static final String Controller = "./src/main/java/com/lunhan/xxx/host/controller/";
        public static final String SEARCH = "./src/main/java/com/lunhan/xxx/entity/dto/search/";
        public static final String SEARCH = "./src/main/java/com/lunhan/xxx/entity/search/";
        public static final String RequestDTO = "./src/main/java/com/lunhan/xxx/entity/request/";
        public static final String ResponseDTO = "./src/main/java/com/lunhan/xxx/entity/response/";
    }
@@ -51,7 +51,7 @@
        public static final String MAPPER = "com.lunhan.xxx.repository.mapper";
        public static final String SERVICE = "com.lunhan.xxx.service";
        public static final String Controller = "com.lunhan.xxx.host.controller";
        public static final String SEARCH = "com.lunhan.xxx.entity.dto.search";
        public static final String SEARCH = "com.lunhan.xxx.entity.search";
        public static final String Request = "com.lunhan.xxx.entity.request";
        public static final String Response = "com.lunhan.xxx.entity.response";
    }
@@ -77,7 +77,7 @@
    /**
     * po中getter/setter生成方式 传统=1,lombok注解=2
     */
    private static final Integer SET_PO_Getter = 1;
    private static final Integer SET_PO_Getter = 2;
    //endregion
    //region 类头部文字设置
@@ -127,10 +127,10 @@
    //region 实体属性映射类 import 内容设置
    private static final String[] SET_CONVERT_IMPORT = new String[]{
            "import org.mapstruct.Mapper;" +
                    "import org.mapstruct.factory.Mappers;" +
                    "" +
                    "import java.util.List;"
            "import org.mapstruct.Mapper;",
            "import org.mapstruct.factory.Mappers;",
            "",
            "import java.util.List;"
    };
    //endregion
@@ -181,7 +181,7 @@
    //region search类 import 内容设置
    private static final String[] SET_SEARCH_IMPORT = new String[]{
            "import " + GenCodeGauss.PackageSet.SEARCH.replaceAll("\\.search", "") + ".SearchBasicDTO;",
            "import " + GenCodeGauss.PackageSet.SEARCH.replaceAll("\\.search", "") + ".dto.SearchBasicDTO;",
    };
    //endregion
@@ -192,13 +192,11 @@
            "/**\n" +
                    " * {#=desc}\n" +
                    " * @author {#=author}\n" +
                    " * @description {#=desc}\n" +
                    " */";
    private static final String SET_METHOD_DESC_TPL =
            "    /**\n" +
                    "     * {#=desc}\n" +
                    "     * @author {#=author}\n" +
                    "     * @description {#=desc}\n" +
                    "     */";
    private static final String SET_PRO_DESC_TPL =
            "\t/**\n" +
@@ -334,8 +332,12 @@
                    listColumn.add("(type = IdType.ASSIGN_ID)");
                }
            }
            if ("is_delete".equals(name)) {
                String columnAnnotation = "\t@TableLogic";
                listColumn.add(columnAnnotation);
            }
            if (!"id".equals(name)) {
                String columnAnnotation = "\t@TableField(\"" + name + "\"";
                String columnAnnotation = "\t@TableField(value = \"" + name + "\"";
                //忽略最后修改时间这一列的新增和编辑
//            if (UPDATE_TIME_COLUMNS.stream().anyMatch(c -> c.equalsIgnoreCase(name))) {
//                columnAnnotation += ", insertable = false, updatable = false";
@@ -659,7 +661,7 @@
                "\t\t\tqueryWrapper.orderByDesc(" + poName + "::getId);\n" +
                "\t\t}\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\treturn new PagerResult<>(pageResult.getSize(), pageResult.getCurrent(), pageResult.getTotal(), pageResult.getRecords());\n" +
                "\t}\n" +
                "\n" +
                "\tpublic Boolean add(" + poName + " item) {\n" +
@@ -969,6 +971,7 @@
        String modifyDTOName = GenCodeGauss.SuffixSet.Modify + modelName;
        String responseDTOName = modelName + "VO";
        String searchName = "Search" + modelName;
        String convertMapperName = modelName + SuffixSet.CONVERT_MAPPER;
        String tableNamePackage = tableName.toLowerCase().replaceAll("_", "");
        StringBuilder content = new StringBuilder();
@@ -985,29 +988,13 @@
                content.append(ConstantFactory.STR_NEWLINE);
            }
        }
        content.append("import ");
        content.append(GenCodeGauss.PackageSet.MAPPER_IMPL);
        content.append(".");
        content.append(daoName + ";\n");
        content.append("import ");
        content.append(GenCodeGauss.PackageSet.PO);
        content.append(".");
        content.append(poName + ";\n");
        content.append("import ");
        content.append(GenCodeGauss.PackageSet.Request);
        content.append("." + tableNamePackage + ".");
        content.append(createDTOName + ";\n");
        content.append("import ");
        content.append(GenCodeGauss.PackageSet.Request);
        content.append("." + tableNamePackage + ".");
        content.append(modifyDTOName + ";\n");
        content.append("import ");
        content.append(GenCodeGauss.PackageSet.SEARCH + ".");
        content.append(searchName + ";\n");
        content.append("import ");
        content.append(GenCodeGauss.PackageSet.VO);
        content.append(".");
        content.append(responseDTOName + ";\n");
        content.append(String.format("import %s.%s;\n", GenCodeGauss.PackageSet.MAPPER_IMPL, daoName));
        content.append(String.format("import %s.%s;\n", GenCodeGauss.PackageSet.PO, poName));
        content.append(String.format("import %s.%s.%s;\n", GenCodeGauss.PackageSet.Request, tableNamePackage, createDTOName));
        content.append(String.format("import %s.%s.%s;\n", GenCodeGauss.PackageSet.Request, tableNamePackage, modifyDTOName));
        content.append(String.format("import %s.%s;\n", GenCodeGauss.PackageSet.SEARCH, searchName));
        content.append(String.format("import %s.%s;\n", GenCodeGauss.PackageSet.VO, responseDTOName));
        content.append(String.format("import %s.%s;\n", GenCodeGauss.PackageSet.CONVERT_MAPPER, convertMapperName));
        content.append(ConstantFactory.STR_NEWLINE);
        content.append(SET_CLASS_DESC_TPL
                .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc)
@@ -1024,7 +1011,7 @@
        content.append(ConstantFactory.STR_NEWLINE);
        content.append("    public ExecutedResult<Long> create(" + createDTOName + " request) {\n" +
                "        // 转换po\n" +
                "        " + poName + " item = CopierUtil.mapTo(request, " + poName + ".class);\n" +
                "        " + poName + " item = " + convertMapperName + ".INSTANCE.toCreate(request);\n" +
                "        // 设置状态\n" +
                "        //item.setStatus(EState.NORMAL.getValue());\n" +
                "        // 设置记录创建时间\n" +
@@ -1046,7 +1033,7 @@
                "            return ExecutedResult.failed(checkExists.getMsg());\n" +
                "        }\n" +
                "        // 转换po\n" +
                "        " + poName + " item = CopierUtil.mapTo(request, " + poName + ".class);\n" +
                "        " + poName + " item = " + convertMapperName + ".INSTANCE.toModify(request);\n" +
                "\n" +
                "        int rowCount = mapper.updateById(item);\n" +
                "        if (rowCount != 1) {\n" +
@@ -1060,7 +1047,8 @@
                "\n" +
                "        " + poName + " find = mapper.get(id);\n" +
                "        if (null != find) {\n" +
                "            result = CopierUtil.mapTo(find, " + responseDTOName + ".class);\n" +
                "            // 转换vo\n" +
                "            result = " + convertMapperName + ".INSTANCE.toVo(find);\n" +
                "        }\n" +
                "        return ExecutedResult.success(result);\n" +
                "    }\n" +
@@ -1092,7 +1080,7 @@
                "//        item.setId(id);\n" +
                "//        item.setStatus(EState.NORMAL.getValue());\n" +
                "//\n" +
                "//        int rowCount = mapper.updateById(item);\\n\" +\n" +
                "//        int rowCount = mapper.updateById(item);\n" +
                "//        if (rowCount != 1) {\n" +
                "//            return ExecutedResult.failed(\"启用[" + tableDesc + "]失败。\");\n" +
                "//        }\n" +
@@ -1109,7 +1097,7 @@
                "//        item.setId(request.getId());\n" +
                "//        item.setSort(request.getSort());\n" +
                "//\n" +
                "//        int rowCount = mapper.updateById(item);\\n\" +\n" +
                "//        int rowCount = mapper.updateById(item);\n" +
                "//        if (rowCount != 1) {\n" +
                "//            return ExecutedResult.failed(\"设置[" + tableDesc + "]排序值失败。\");\n" +
                "//        }\n" +
@@ -1161,7 +1149,8 @@
                "\n" +
                "        List<" + poName + "> list = mapper.getList(listId);\n" +
                "        if (ListUtil.isNotNullOrEmpty(list)) {\n" +
                "            result = CopierUtil.mapTo(list, " + responseDTOName + ".class);\n" +
                "            // 转换vo\n" +
                "            result = " + convertMapperName + ".INSTANCE.toVo(list);\n" +
                "        }\n" +
                "        return ExecutedResult.success(result);\n" +
                "    }\n" +
@@ -1182,7 +1171,7 @@
                "        if (ListUtil.isNotNullOrEmpty(list)) {\n" +
                "            pageList.setLastId(list.get(list.size() - 1).getId());\n" +
                "            // 转换vo\n" +
                "            listVo = CopierUtil.mapTo(list, " + responseDTOName + ".class);\n" +
                "            listVo = " + convertMapperName + ".INSTANCE.toVo(list);\n" +
                "        }\n" +
                "        PagerResult<" + responseDTOName + "> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo);\n" +
                "        result.setLastId(pageList.getLastId());\n" +
@@ -1233,7 +1222,7 @@
        String modifyDTOName = GenCodeGauss.SuffixSet.Modify + modelName;
        String responseDTOName = modelName + "VO";
        String searchName = "Search" + modelName;
        String tableNamePackage = tableName.toLowerCase().replaceAll("_", "");
        String tableNamePackage = tableName.toLowerCase().replaceAll("\\_", "");
        StringBuilder content = new StringBuilder();
        content.append(SET_BEFORE_TEXT);
@@ -1270,8 +1259,8 @@
        content.append(responseDTOName + ";\n");
        content.append(ConstantFactory.STR_NEWLINE);
        content.append(SET_CLASS_DESC_TPL
                .replaceAll("\\{\\#\\=desc\\}", tableDesc == null ? modelName : tableDesc)
                .replaceAll("\\{\\#\\=author\\}", AUTHOR)
                .replaceAll("\\{\\#\\=desc\\}", "9000." + (tableDesc == null ? modelName : tableDesc))
                .replaceAll("\\{\\#\\=author\\}", AUTHOR + "\n * @order 9000")
                .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/"))
        );
        content.append(ConstantFactory.STR_NEWLINE);
@@ -1303,7 +1292,7 @@
                "            return failed(result.getErrorMsg());\n" +
                "        }\n" +
                "        //#endregion\n" +
                "        return this.service.create(request);\n" +
                "        return service.create(request);\n" +
                "    }\n" +
                "\n");
        content.append(SET_METHOD_DESC_TPL
@@ -1328,7 +1317,7 @@
                "            return failed(result.getErrorMsg());\n" +
                "        }\n" +
                "        //#endregion\n" +
                "        return this.service.modify(request);\n" +
                "        return service.modify(request);\n" +
                "    }\n\n");
        content.append(SET_METHOD_DESC_TPL
                .replaceAll("\\{\\#\\=desc\\}", "获取[" + tableDesc + "]")
@@ -1336,19 +1325,19 @@
                .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/"))
        );
        content.append(ConstantFactory.STR_NEWLINE);
        content.append("    @GetMapping(value = \"get\")\n" +
                "    public ExecutedResult<" + voName + "> get(@RequestParam Long id) {\n" +
                "        return this.service.get(id);\n" +
        content.append("    @GetMapping(value = \"get/{id}\")\n" +
                "    public ExecutedResult<" + voName + "> get(@PathVariable Long id) {\n" +
                "        return service.get(id);\n" +
                "    }\n\n");
        content.append(SET_METHOD_DESC_TPL
                .replaceAll("\\{\\#\\=desc\\}", "根据id批量获取[" + tableDesc + "]")
                .replaceAll("\\{\\#\\=desc\\}", "查询[" + tableDesc + "]")
                .replaceAll("\\{\\#\\=author\\}", AUTHOR)
                .replaceAll("\\{\\#\\=date\\}", LocalDateTimeUtil.todayStr().replaceAll("\\-", "/"))
        );
        content.append(ConstantFactory.STR_NEWLINE);
        content.append("    @PostMapping(value = \"search\")\n" +
                "    public ExecutedResult<PagerResult<" + voName + ">> search(@RequestBody " + searchName + " request) {\n" +
                "        return this.service.search(request);\n" +
                "        return service.search(request);\n" +
                "    }\n");
        content.append("}");