| | |
| | | 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/"; |
| | | } |
| | |
| | | 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"; |
| | | } |
| | |
| | | /** |
| | | * po中getter/setter生成方式 传统=1,lombok注解=2 |
| | | */ |
| | | private static final Integer SET_PO_Getter = 1; |
| | | private static final Integer SET_PO_Getter = 2; |
| | | //endregion |
| | | |
| | | //region 类头部文字设置 |
| | |
| | | |
| | | //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 |
| | | |
| | |
| | | |
| | | //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 |
| | | |
| | |
| | | "/**\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" + |
| | |
| | | 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"; |
| | |
| | | "\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" + |
| | |
| | | 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(); |
| | |
| | | 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) |
| | |
| | | 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" + |
| | |
| | | " 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" + |
| | |
| | | "\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" + |
| | |
| | | "// 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" + |
| | |
| | | "// 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" + |
| | |
| | | "\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" + |
| | |
| | | " 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" + |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | " 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 |
| | |
| | | " 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 + "]") |
| | |
| | | .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("}"); |
| | | |