| | |
| | | /** |
| | | * 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 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 |
| | | |
| | |
| | | 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;" |
| | |
| | | |
| | | //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;", |
| | |
| | | |
| | | //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;" |
| | |
| | | |
| | | //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" + |
| | | " 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" + |
| | | " 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 = TroopsInfoConvert.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("}"); |
| | | |