From bcb3de6093b6638f80bcf9bfceb08865fa8e255b Mon Sep 17 00:00:00 2001
From: liulin <lin.liu@aliyun.com>
Date: 星期二, 03 九月 2024 23:50:05 +0800
Subject: [PATCH] GenCodeGauss

---
 src/test/java/com/lunhan/xxx/GenCodeGauss.java |  125 ++++++++++++++++++-----------------------
 1 files changed, 56 insertions(+), 69 deletions(-)

diff --git a/src/test/java/com/lunhan/xxx/GenCodeGauss.java b/src/test/java/com/lunhan/xxx/GenCodeGauss.java
index 2b2b4f9..4e9ecc7 100644
--- a/src/test/java/com/lunhan/xxx/GenCodeGauss.java
+++ b/src/test/java/com/lunhan/xxx/GenCodeGauss.java
@@ -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 类头部文字设置
@@ -119,18 +119,18 @@
 
     //region vo类 import 内容设置
     private static final String[] SET_VO_IMPORT = new String[]{
-            "import com.lunhan.xxx.common.util.LocalDateTimeUtil;",
-            "import com.lunhan.xxx.common.util.NumericUtil;",
+            "import com.lunhan.farming.common.util.LocalDateTimeUtil;",
+            "import com.lunhan.farming.common.util.NumericUtil;",
             "import java.util.Objects;"
     };
     //endregion
 
     //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
 
@@ -138,12 +138,12 @@
     private static final String[] SET_MAPPER_IMPL_IMPORT = new String[]{
             "import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;",
             "import com.baomidou.mybatisplus.extension.plugins.pagination.Page;",
-            "import com.lunhan.xxx.common.PagerResult;",
-            "import com.lunhan.xxx.common.enums.EYesOrNo;",
-            "import com.lunhan.xxx.common.util.*;",
-            "import com.lunhan.xxx.entity.dto.*;",
-            "import com.lunhan.xxx.entity.enums.*;",
-            "import com.lunhan.xxx.repository.BasicMapperImpl;",
+            "import com.lunhan.farming.common.PagerResult;",
+            "import com.lunhan.farming.common.enums.EYesOrNo;",
+            "import com.lunhan.farming.common.util.*;",
+            "import com.lunhan.farming.entity.dto.*;",
+            "import com.lunhan.farming.entity.enums.*;",
+            "import com.lunhan.farming.repository.BasicMapperImpl;",
             "import org.springframework.stereotype.Repository;",
             "",
             "import java.util.List;"
@@ -152,10 +152,10 @@
 
     //region service类 import 内容设置
     private static final String[] SET_Service_IMPORT = new String[]{
-            "import com.lunhan.xxx.common.*;",
-            "import com.lunhan.xxx.common.enums.*;",
-            "import com.lunhan.xxx.common.model.Tuple;",
-            "import com.lunhan.xxx.common.util.*;",
+            "import com.lunhan.farming.common.*;",
+            "import com.lunhan.farming.common.enums.*;",
+            "import com.lunhan.farming.common.model.Tuple;",
+            "import com.lunhan.farming.common.util.*;",
             "import org.apache.commons.lang3.BooleanUtils;",
             "import org.springframework.beans.factory.annotation.Autowired;",
             "import org.springframework.stereotype.Service;",
@@ -166,13 +166,13 @@
 
     //region Controller类 import 内容设置
     private static final String[] SET_Controller_IMPORT = new String[]{
-            "import com.lunhan.xxx.common.ExecutedResult;",
-            "import com.lunhan.xxx.common.PagerResult;",
-            "import com.lunhan.xxx.common.util.ParameterUtil;",
-            "import com.lunhan.xxx.common.validator.ParameterValidateResult;",
-            "import com.lunhan.xxx.common.validator.ParameterValidator;",
-            "import com.lunhan.xxx.entity.request.ReqListId;",
-            "import com.lunhan.xxx.host.BasicController;",
+            "import com.lunhan.farming.common.ExecutedResult;",
+            "import com.lunhan.farming.common.PagerResult;",
+            "import com.lunhan.farming.common.util.ParameterUtil;",
+            "import com.lunhan.farming.common.validator.ParameterValidateResult;",
+            "import com.lunhan.farming.common.validator.ParameterValidator;",
+            "import com.lunhan.farming.entity.request.ReqListId;",
+            "import com.lunhan.farming.host.BasicController;",
             "import org.springframework.beans.factory.annotation.Autowired;",
             "import org.springframework.web.bind.annotation.*;",
             "import java.util.List;"
@@ -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,7 @@
                 "\n" +
                 "        " + poName + " find = mapper.get(id);\n" +
                 "        if (null != find) {\n" +
-                "            result = CopierUtil.mapTo(find, " + responseDTOName + ".class);\n" +
+                "            result = " + convertMapperName + ".INSTANCE.toVo(find);\n" +
                 "        }\n" +
                 "        return ExecutedResult.success(result);\n" +
                 "    }\n" +
@@ -1092,7 +1079,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 +1096,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 +1148,7 @@
                 "\n" +
                 "        List<" + poName + "> list = mapper.getList(listId);\n" +
                 "        if (ListUtil.isNotNullOrEmpty(list)) {\n" +
-                "            result = CopierUtil.mapTo(list, " + responseDTOName + ".class);\n" +
+                "            result = " + convertMapperName + ".INSTANCE.toVo(list);\n" +
                 "        }\n" +
                 "        return ExecutedResult.success(result);\n" +
                 "    }\n" +
@@ -1182,7 +1169,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 = TroopsInfoConvert.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 +1220,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 +1257,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 +1290,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 +1315,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 +1323,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("}");
 

--
Gitblit v1.9.3