diff --git a/pom.xml b/pom.xml index f8e0bece933bcd55998e48655d39182a8e89ffb9..73ff698d120079e12a7dc66f149eb47570b1d829 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ 1.33.0 1.33.0 1.33.0 + 4.4.0 1.2.75 1.18.20 5.8.10 @@ -96,6 +97,13 @@ ${sa-token-jwt.version} + + + cn.afterturn + easypoi-spring-boot-starter + ${easypoi-spring-boot-starter.version} + + org.projectlombok diff --git a/quick-boot-common/pom.xml b/quick-boot-common/pom.xml index 0784dbfab112c7aa2d228d615d45fa3e95e03301..af7ee1a5fd58eefe92ecf393008c091fc7b6c4a6 100644 --- a/quick-boot-common/pom.xml +++ b/quick-boot-common/pom.xml @@ -66,6 +66,12 @@ sa-token-jwt + + + cn.afterturn + easypoi-spring-boot-starter + + org.projectlombok diff --git a/quick-boot-common/src/main/java/com/quickboot/common/consts/MsgConst.java b/quick-boot-common/src/main/java/com/quickboot/common/consts/MsgConst.java index b04f3df8b0b634ba9395b4ea7791370b4d8611df..c90296c4d58f5ce89fc43993c20598922af45761 100644 --- a/quick-boot-common/src/main/java/com/quickboot/common/consts/MsgConst.java +++ b/quick-boot-common/src/main/java/com/quickboot/common/consts/MsgConst.java @@ -16,6 +16,10 @@ public class MsgConst { public static final String QUERY_SUCCESS = "查询成功"; + public static final String IMPORT_SUCCESS = "导入成功"; + + public static final String EXPORT_SUCCESS = "导出成功"; + public static final String SAVE_ERROR = "新增失败"; public static final String UPDATE_ERROR = "更新失败"; @@ -23,4 +27,8 @@ public class MsgConst { public static final String REMOVE_ERROR = "删除失败"; public static final String QUERY_ERROR = "查询失败"; + + public static final String IMPORT_ERROR = "导入失败"; + + public static final String EXPORT_ERROR = "导出失败"; } diff --git a/quick-boot-common/src/main/java/com/quickboot/common/controller/BaseController.java b/quick-boot-common/src/main/java/com/quickboot/common/controller/BaseController.java index 6684ace75c251b62549870134a3b7a113a9a6f9b..8596cd840e08e3b0e1d30292c82f0fa1d0acd98c 100644 --- a/quick-boot-common/src/main/java/com/quickboot/common/controller/BaseController.java +++ b/quick-boot-common/src/main/java/com/quickboot/common/controller/BaseController.java @@ -1,9 +1,12 @@ package com.quickboot.common.controller; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.quickboot.common.consts.MsgConst; import com.quickboot.common.entity.Result; -import com.quickboot.common.entity.TableResult; +import com.quickboot.common.utils.SpringUtils; + +import javax.servlet.http.HttpServletRequest; /** * 控制层 基类 @@ -13,6 +16,31 @@ import com.quickboot.common.entity.TableResult; */ public class BaseController { + public static final String PAGE_NUM = "pageNum"; + + public static final String PAGE_SIZE = "pageSize"; + + public static final int PAGE_NUM_DEFAULT = 1; + + public static final int PAGE_SIZE_DEFAULT = 100000; + + public static Page getPage() { + int pageNum = PAGE_NUM_DEFAULT; + int pagSize = PAGE_SIZE_DEFAULT; + HttpServletRequest request = SpringUtils.getRequest(); + if (StrUtil.isNotEmpty(request.getParameter(PAGE_NUM)) && Integer.valueOf(request.getParameter(PAGE_NUM)) > 0) { + pageNum = Integer.parseInt(request.getParameter(PAGE_NUM)); + } + if (StrUtil.isNotEmpty(request.getParameter(PAGE_SIZE)) && Integer.valueOf(request.getParameter(PAGE_SIZE)) > 0) { + pagSize = Integer.parseInt(request.getParameter(PAGE_SIZE)); + } + return new Page(pageNum, pagSize); + } + + public static Page getAllPage() { + return new Page(PAGE_NUM_DEFAULT, PAGE_SIZE_DEFAULT); + } + public static Result queryResult(T data) { return Result.ok(MsgConst.QUERY_SUCCESS, data); } diff --git a/quick-boot-common/src/main/java/com/quickboot/common/entity/BaseEntity.java b/quick-boot-common/src/main/java/com/quickboot/common/entity/BaseEntity.java index 336d0baacd3cf69f8feafaa920063f21c672f3ba..f80217bf476af108fed718ea0f6c6beaf01b279a 100644 --- a/quick-boot-common/src/main/java/com/quickboot/common/entity/BaseEntity.java +++ b/quick-boot-common/src/main/java/com/quickboot/common/entity/BaseEntity.java @@ -33,4 +33,6 @@ public class BaseEntity { @ApiModelProperty(value = "更新时间", hidden = true) @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateTime; + + public static final String deleteStatus = "deleteStatus"; } diff --git a/quick-boot-common/src/main/java/com/quickboot/common/utils/EasyPoiExcelUtils.java b/quick-boot-common/src/main/java/com/quickboot/common/utils/EasyPoiExcelUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..5faf14dba9e2c6e32fb8bbe0f2689ccfed246bda --- /dev/null +++ b/quick-boot-common/src/main/java/com/quickboot/common/utils/EasyPoiExcelUtils.java @@ -0,0 +1,72 @@ +package com.quickboot.common.utils; + +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.ExcelImportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; +import cn.afterturn.easypoi.excel.entity.ImportParams; +import com.quickboot.common.consts.MsgConst; +import com.quickboot.common.exception.BusinessException; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.net.URLEncoder; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Objects; + +/** + * EasyPoi 工具类 + * https://blog.csdn.net/qq_38762237/article/details/121607927 + * + * @author Tellsea + * @date 2022/12/3 + */ +@Slf4j +public class EasyPoiExcelUtils { + + public static void exportExcel(List list, String title, Class pojoClass) { + ExportParams exportParams = new ExportParams(title, "Sheet1"); + exportParams.setAutoSize(true); + defaultExport(list, pojoClass, title + ".xlsx", exportParams); + } + + private static void defaultExport(List list, Class pojoClass, String fileName, ExportParams exportParams) { + Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list); + downLoadExcel(fileName, workbook); + } + + private static void downLoadExcel(String fileName, Workbook workbook) { + try { + HttpServletResponse response = SpringUtils.getResponse(); + response.setCharacterEncoding("UTF-8"); + response.setHeader("content-Type", "application/vnd.ms-excel"); + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); + workbook.write(response.getOutputStream()); + } catch (Exception e) { + e.printStackTrace(); + throw new BusinessException("下载失败"); + } + } + + public static List importExcel(MultipartFile file, Integer titleRows, Integer headerRows, Class pojoClass) { + AssertUtils.isTrue(Objects.isNull(file), "找不到文件"); + ImportParams params = new ImportParams(); + params.setTitleRows(titleRows); + params.setHeadRows(headerRows); + List list = null; + try { + list = ExcelImportUtil.importExcel(file.getInputStream(), pojoClass, params); + } catch (NoSuchElementException e) { + e.printStackTrace(); + throw new BusinessException("文件不能为空"); + } catch (Exception e) { + e.printStackTrace(); + throw new BusinessException(MsgConst.IMPORT_ERROR); + } + AssertUtils.isTrue(CollectionUtils.isEmpty(list), "导入数据为空"); + return list; + } +} diff --git a/quick-boot-common/src/main/java/com/quickboot/common/utils/PageUtils.java b/quick-boot-common/src/main/java/com/quickboot/common/utils/PageUtils.java index eefd89ec06e67b0384295dec29571ae97fbf63a2..83eccc0fd51b4f0e6d34b74547ade5cc8cd7c7a4 100644 --- a/quick-boot-common/src/main/java/com/quickboot/common/utils/PageUtils.java +++ b/quick-boot-common/src/main/java/com/quickboot/common/utils/PageUtils.java @@ -1,10 +1,7 @@ package com.quickboot.common.utils; import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.spring.SpringUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; @@ -37,4 +34,8 @@ public class PageUtils { System.out.println(pageNum + "---" + pagSize); return new Page(pageNum, pagSize); } + + public static Page getAllPage() { + return new Page(PAGE_NUM_DEFAULT, PAGE_SIZE_DEFAULT); + } } diff --git a/quick-boot-common/src/main/java/com/quickboot/common/utils/SpringUtils.java b/quick-boot-common/src/main/java/com/quickboot/common/utils/SpringUtils.java index 8eee3c06b2b78ba77d045dadbb0c494b12c2e9ae..3418844c715ac165836067815289a7eda057d19a 100644 --- a/quick-boot-common/src/main/java/com/quickboot/common/utils/SpringUtils.java +++ b/quick-boot-common/src/main/java/com/quickboot/common/utils/SpringUtils.java @@ -5,10 +5,12 @@ import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.Objects; /** @@ -23,8 +25,25 @@ public class SpringUtils implements ApplicationContextAware { private static ApplicationContext applicationContext; + private static ServletRequestAttributes getRequestAttributes() { + RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); + return (ServletRequestAttributes) attributes; + } + + /** + * 获取request + * @return + */ public static HttpServletRequest getRequest() { - return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); + return getRequestAttributes().getRequest(); + } + + /** + * 获取response + * @return + */ + public static HttpServletResponse getResponse() { + return getRequestAttributes().getResponse(); } /** diff --git a/quick-boot-core/src/main/java/com/quickboot/core/handle/PublicFieldMetaObjectHandler.java b/quick-boot-core/src/main/java/com/quickboot/core/handle/PublicFieldMetaObjectHandler.java index 535ee05290fbc884da991f708aa38cbced6da064..255e76a844a36648f981dfd394b99114b771b045 100644 --- a/quick-boot-core/src/main/java/com/quickboot/core/handle/PublicFieldMetaObjectHandler.java +++ b/quick-boot-core/src/main/java/com/quickboot/core/handle/PublicFieldMetaObjectHandler.java @@ -1,12 +1,13 @@ package com.quickboot.core.handle; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import com.quickboot.common.consts.NumberConst; import com.quickboot.common.entity.BaseEntity; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.reflection.MetaObject; import org.springframework.stereotype.Component; -import java.time.LocalDateTime; +import java.util.Date; /** * 公共字段填充 @@ -20,13 +21,14 @@ public class PublicFieldMetaObjectHandler implements MetaObjectHandler { @Override public void insertFill(MetaObject metaObject) { - this.strictInsertFill(metaObject, BaseEntity.Fields.createBy, Long.class, 1L); - this.strictInsertFill(metaObject, BaseEntity.Fields.createTime, LocalDateTime.class, LocalDateTime.now()); + this.setFieldValByName(BaseEntity.Fields.createBy, "1", metaObject); + this.setFieldValByName(BaseEntity.Fields.createTime, new Date(), metaObject); + this.setFieldValByName(BaseEntity.deleteStatus, NumberConst.ONE, metaObject); } @Override public void updateFill(MetaObject metaObject) { - this.strictInsertFill(metaObject, BaseEntity.Fields.updateBy, Long.class, 1L); - this.strictUpdateFill(metaObject, BaseEntity.Fields.updateTime, LocalDateTime.class, LocalDateTime.now()); + this.setFieldValByName(BaseEntity.Fields.updateBy, "1", metaObject); + this.setFieldValByName(BaseEntity.Fields.updateTime, new Date(), metaObject); } } diff --git a/quick-boot-generate/src/main/java/com/quickboot/generate/consts/GenerateConst.java b/quick-boot-generate/src/main/java/com/quickboot/generate/consts/GenerateConst.java index bda3d2ceb755254764e2a88fadbe37e6c0ef712e..8775b0c6e61d0aaa3492611fbdd934abfe38cc0e 100644 --- a/quick-boot-generate/src/main/java/com/quickboot/generate/consts/GenerateConst.java +++ b/quick-boot-generate/src/main/java/com/quickboot/generate/consts/GenerateConst.java @@ -13,10 +13,6 @@ import java.util.List; * @date 2022/11/25 */ public class GenerateConst { - /** - * 默认逻辑删除字段 - */ - public static final String DELETE_STATUS_FIELD = "deleteStatus"; /** * 实体类基类字段 */ @@ -29,7 +25,7 @@ public class GenerateConst { public static final List QUERY_EXCLUDE_LIST = Arrays.asList( BaseEntity.Fields.createBy, BaseEntity.Fields.createTime, BaseEntity.Fields.updateBy, BaseEntity.Fields.updateTime, - DELETE_STATUS_FIELD); + BaseEntity.deleteStatus); /** * 运算符 */ diff --git a/quick-boot-generate/src/main/java/com/quickboot/generate/controller/GenTableController.java b/quick-boot-generate/src/main/java/com/quickboot/generate/controller/GenTableController.java index c07833ecd5b9447e76afa653af1f5c56916216b9..e4e8b492db358513ccf48b1ce0fa5c96709c1f08 100644 --- a/quick-boot-generate/src/main/java/com/quickboot/generate/controller/GenTableController.java +++ b/quick-boot-generate/src/main/java/com/quickboot/generate/controller/GenTableController.java @@ -1,9 +1,13 @@ package com.quickboot.generate.controller; import cn.dev33.satoken.annotation.SaCheckPermission; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.quickboot.common.controller.BaseController; import com.quickboot.common.entity.Result; import com.quickboot.common.entity.TableResult; +import com.quickboot.generate.entity.GenTableColumn; +import com.quickboot.generate.proterties.GenerateProperties; +import com.quickboot.generate.service.GenTableColumnService; import com.quickboot.generate.service.GenTableService; import com.quickboot.generate.utils.VelocityUtils; import com.quickboot.generate.vo.GenTableVo; @@ -13,6 +17,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; + /** * 代码生成-表 控制层 * @@ -26,53 +32,84 @@ import org.springframework.web.bind.annotation.*; public class GenTableController extends BaseController { private final GenTableService genTableService; + private final GenTableColumnService genTableColumnService; + private final GenerateProperties generateProperties; @ApiOperation("查询列表") @SaCheckPermission("generate:genTable:list") @GetMapping("/list") public TableResult queryList(GenTableVo entity) { - return TableResult.ok(genTableService.queryList(entity)); + return TableResult.ok(genTableService.queryList(getPage(), entity)); } @ApiOperation("查询数据库所有表") - @GetMapping("/listAllTable") - public TableResult listAllTable(GenTableVo entity) { - return TableResult.ok(genTableService.listAllTable(entity)); + @GetMapping("/listByDataBase") + public TableResult listByDataBase(GenTableVo entity) { + return TableResult.ok(genTableService.listByDataBase(getPage(), entity)); + } + + @ApiOperation("默认生成配置") + @GetMapping("/getDefaultConfig") + public Result getDefaultConfig() { + return queryResult(generateProperties); } @ApiOperation("根据ID查询") @SaCheckPermission("generate:genTable:get") @GetMapping("/queryById/{id}") - public Result queryById(@PathVariable("id") Long id) { + public Result queryById(@PathVariable("id") Long id) { return queryResult(genTableService.queryById(id)); } - @ApiOperation("导入") + @ApiOperation("新增") @SaCheckPermission("generate:genTable:save") @PostMapping("/save") public Result save(@RequestBody GenTableVo entity) { return saveResult(genTableService.saveEntity(entity)); } + @ApiOperation("根据ID更新") + @SaCheckPermission("generate:genTable:update") + @PostMapping("/updateById") + public Result updateById(@RequestBody GenTableVo entity) { + return updateResult(genTableService.updateEntity(entity)); + } + @ApiOperation("代码生成") @SaCheckPermission("generate:genTable:generate") @GetMapping("/generate/{id}") public Result generate(@PathVariable("id") Long id) { - VelocityUtils.generate(id); + VelocityUtils.generate(id, 1); return Result.ok("生成成功"); } - @ApiOperation("根据ID更新") - @SaCheckPermission("generate:genTable:update") - @PostMapping("/updateById") - public Result updateById(@RequestBody GenTableVo entity) { - return updateResult(genTableService.updateById(entity)); + @ApiOperation("代码预览") + @SaCheckPermission("generate:genTable:preview") + @GetMapping("/preview/{id}") + public Result preview(@PathVariable("id") Long id) { + return Result.ok("生成成功", VelocityUtils.generate(id, 2)); } @ApiOperation("根据ID删除") @SaCheckPermission("generate:genTable:remove") @GetMapping("/removeById/{id}") public Result removeById(@PathVariable("id") Long id) { - return removeResult(genTableService.removeById(id)); + boolean removeFlag = genTableService.removeById(id); + boolean removeBatchFlag = genTableColumnService.remove(new LambdaQueryWrapper() + .eq(GenTableColumn::getTableId, id)); + return removeResult(removeFlag && removeBatchFlag); + } + + @ApiOperation("根据ID批量删除") + @SaCheckPermission("system:sysDict:removeBatch") + @GetMapping("/removeBatchByIds/{ids}") + public Result removeBatchByIds(@PathVariable("ids") List ids) { + boolean removeFlag = genTableService.removeBatchByIds(ids); + for (Long id : ids) { + boolean removeBatchFlag = genTableColumnService.remove(new LambdaQueryWrapper() + .eq(GenTableColumn::getTableId, id)); + removeFlag = removeFlag && removeBatchFlag; + } + return removeResult(removeFlag); } } diff --git a/quick-boot-generate/src/main/java/com/quickboot/generate/entity/GenTable.java b/quick-boot-generate/src/main/java/com/quickboot/generate/entity/GenTable.java index 36747b4a8f20e45ba7d1868cf447857b5e263757..7b1a079b436b50c2de9222e6cb1568a5f0713774 100644 --- a/quick-boot-generate/src/main/java/com/quickboot/generate/entity/GenTable.java +++ b/quick-boot-generate/src/main/java/com/quickboot/generate/entity/GenTable.java @@ -1,24 +1,26 @@ package com.quickboot.generate.entity; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.*; import com.quickboot.common.entity.BaseEntity; import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; +import lombok.experimental.FieldNameConstants; /** * 代码生成-表 实体类 * * @author Tellsea - * @date 2022-11-28 + * @date 2022-12-05 */ @Data @ApiModel("代码生成-表") @Accessors(chain = true) @EqualsAndHashCode(callSuper = true) +@FieldNameConstants public class GenTable extends BaseEntity { /** @@ -86,4 +88,47 @@ public class GenTable extends BaseEntity { * xml文件名 */ private String mapperXml; + /** + * 主键java属性名 + */ + private String pkJavaField; + /** + * 主键列名称 + */ + private String pkColumnName; + /** + * PC端 1-是 + */ + private Integer isPc; + /** + * 新增 1-是 + */ + private Integer isSave; + /** + * 更新 1-是 + */ + private Integer isUpdate; + /** + * 删除 1-是 + */ + private Integer isRemove; + /** + * 批量删除 1-是 + */ + private Integer isRemoveBatch; + /** + * 导入 1-是 + */ + private Integer isImport; + /** + * 导出 1-是 + */ + private Integer isExport; + /** + * 数据状态 1-正常 2-删除 + */ + @TableLogic + @ApiModelProperty(hidden = true) + @TableField(fill = FieldFill.INSERT) + private Integer deleteStatus; } diff --git a/quick-boot-generate/src/main/java/com/quickboot/generate/entity/GenTableColumn.java b/quick-boot-generate/src/main/java/com/quickboot/generate/entity/GenTableColumn.java index 23640572edc1ac065243bfe17b974b8d803f7ed7..b5cc92a6c7466c713f2ef6e3bffdc4fe02b25504 100644 --- a/quick-boot-generate/src/main/java/com/quickboot/generate/entity/GenTableColumn.java +++ b/quick-boot-generate/src/main/java/com/quickboot/generate/entity/GenTableColumn.java @@ -1,9 +1,9 @@ package com.quickboot.generate.entity; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.*; import com.quickboot.common.entity.BaseEntity; import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; @@ -90,4 +90,11 @@ public class GenTableColumn extends BaseEntity { * 排序 */ private Integer sort; + /** + * 数据状态 1-正常 2-删除 + */ + @TableLogic + @ApiModelProperty(hidden = true) + @TableField(fill = FieldFill.INSERT) + private Integer deleteStatus; } diff --git a/quick-boot-generate/src/main/java/com/quickboot/generate/mapper/GenTableMapper.java b/quick-boot-generate/src/main/java/com/quickboot/generate/mapper/GenTableMapper.java index e327b430f524f4131231062bc30ad48a4f5e0e81..19591e2f5a0a13779f4e86c2232f8d4158da345b 100644 --- a/quick-boot-generate/src/main/java/com/quickboot/generate/mapper/GenTableMapper.java +++ b/quick-boot-generate/src/main/java/com/quickboot/generate/mapper/GenTableMapper.java @@ -24,13 +24,13 @@ public interface GenTableMapper extends BaseMapper { Page queryList(Page page, @Param("entity") GenTableVo entity); /** - * 查询导入列表 + * 查询数据库所有表 * * @param page * @param entity * @return */ - Page listAllTable(Page page, @Param("entity") GenTableVo entity); + Page listByDataBase(Page page, @Param("entity") GenTableVo entity); /** * 根据ID查询 diff --git a/quick-boot-generate/src/main/java/com/quickboot/generate/service/GenTableService.java b/quick-boot-generate/src/main/java/com/quickboot/generate/service/GenTableService.java index fa6b63a036f897997a7b30b12505117a3795f108..4ca19a3a2c1e70e7d359ce7b223cd6314baf11bd 100644 --- a/quick-boot-generate/src/main/java/com/quickboot/generate/service/GenTableService.java +++ b/quick-boot-generate/src/main/java/com/quickboot/generate/service/GenTableService.java @@ -16,18 +16,20 @@ public interface GenTableService extends IService { /** * 查询列表 * + * @param page * @param entity * @return */ - Page queryList(GenTableVo entity); + Page queryList(Page page, GenTableVo entity); /** - * 查询导入列表 + * 查询数据库所有表 * + * @param page * @param entity * @return */ - Page listAllTable(GenTableVo entity); + Page listByDataBase(Page page, GenTableVo entity); /** * 根据ID查询 @@ -44,4 +46,12 @@ public interface GenTableService extends IService { * @return */ boolean saveEntity(GenTableVo entity); + + /** + * 根据ID更新 + * + * @param entity + * @return + */ + boolean updateEntity(GenTableVo entity); } diff --git a/quick-boot-generate/src/main/java/com/quickboot/generate/service/impl/GenTableServiceImpl.java b/quick-boot-generate/src/main/java/com/quickboot/generate/service/impl/GenTableServiceImpl.java index c6488ad5b1b039f563e0833403080c097b0c8f58..28607ab1df934460cc41d29c653807764f925f8a 100644 --- a/quick-boot-generate/src/main/java/com/quickboot/generate/service/impl/GenTableServiceImpl.java +++ b/quick-boot-generate/src/main/java/com/quickboot/generate/service/impl/GenTableServiceImpl.java @@ -1,15 +1,17 @@ package com.quickboot.generate.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.comparator.CompareUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.quickboot.common.utils.PageUtils; +import com.quickboot.common.entity.BaseEntity; import com.quickboot.generate.consts.GenerateConst; import com.quickboot.generate.entity.GenTable; import com.quickboot.generate.entity.GenTableColumn; import com.quickboot.generate.mapper.GenTableMapper; -import com.quickboot.generate.proterties.GenerateProperties; import com.quickboot.generate.service.GenTableColumnService; import com.quickboot.generate.service.GenTableService; import com.quickboot.generate.vo.GenTableColumnVo; @@ -18,9 +20,11 @@ import com.quickboot.generate.vo.JavaToMysqlType; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * 代码生成-表 接口实现类 @@ -33,16 +37,15 @@ import java.util.Objects; public class GenTableServiceImpl extends ServiceImpl implements GenTableService { private final GenTableColumnService genTableColumnService; - private final GenerateProperties generateProperties; @Override - public Page queryList(GenTableVo entity) { - return this.baseMapper.queryList(PageUtils.getPage(), entity); + public Page queryList(Page page, GenTableVo entity) { + return this.baseMapper.queryList(page, entity); } @Override - public Page listAllTable(GenTableVo entity) { - return this.baseMapper.listAllTable(PageUtils.getPage(), entity); + public Page listByDataBase(Page page, GenTableVo entity) { + return this.baseMapper.listByDataBase(page, entity); } @Override @@ -52,49 +55,88 @@ public class GenTableServiceImpl extends ServiceImpl i @Override public boolean saveEntity(GenTableVo entity) { - // 两个参数:table_name、table_comment - entity.setAuthor(generateProperties.getAuthor()); - entity.setParentPackage(generateProperties.getParentPackage()); - entity.setMavenModule(generateProperties.getMavenModule()); - entity.setModule(generateProperties.getModule()); - entity.setBusiness(StrUtil.toCamelCase(entity.getTableName())); - entity.setEntity(StrUtil.upperFirst(entity.getBusiness())); - entity.setEntityVo(StrUtil.addSuffixIfNot(entity.getEntity(), "Vo")); - entity.setController(StrUtil.addSuffixIfNot(entity.getEntity(), "Controller")); - entity.setService(StrUtil.addSuffixIfNot(entity.getEntity(), "Service")); - entity.setServiceAttr(StrUtil.lowerFirst(entity.getService())); - entity.setServiceImpl(StrUtil.addSuffixIfNot(entity.getEntity(), "ServiceImpl")); - entity.setMapper(StrUtil.addSuffixIfNot(entity.getEntity(), "Mapper")); - entity.setMapperXml(StrUtil.addSuffixIfNot(entity.getEntity(), "Mapper")); - int insertFlag = this.baseMapper.insert(entity); - // 表字段 - List entityColumnVoList = genTableColumnService.queryByStructure(entity.getTableName()); - for (GenTableColumnVo column : entityColumnVoList) { - column.setTableId(entity.getId()); - String mysqlType = column.getColumnType(); - column.setJavaField(StrUtil.toCamelCase(column.getColumnName())); - column.setIsQuery(GenerateConst.QUERY_EXCLUDE_LIST.contains(column.getJavaField()) ? 0 : 1); - column.setIsForm(GenerateConst.QUERY_EXCLUDE_LIST.contains(column.getJavaField()) ? 0 : 1); - column.setIsRequired(GenerateConst.QUERY_EXCLUDE_LIST.contains(column.getJavaField()) ? 0 : 1); - column.setIsTable(GenerateConst.QUERY_EXCLUDE_LIST.contains(column.getJavaField()) ? 0 : 1); - column.setIsLogicDelete(Objects.equals(column.getColumnName(), GenerateConst.DELETE_STATUS_FIELD) ? 1 : 0); - if (column.getColumnType().indexOf("(") > -1) { - mysqlType = column.getColumnType().substring(0, column.getColumnType().indexOf("(")); - } - for (JavaToMysqlType javaToMysqlType : GenerateConst.JAVA_TYPE_TO_MYSQL_TYPE) { - if (javaToMysqlType.getTypeList().contains(mysqlType)) { - column.setJavaPackage(javaToMysqlType.getJavaPackage()); - column.setJavaType(javaToMysqlType.getJavaType()); + List genTableList = JSON.parseArray(entity.getGenTableJson(), GenTable.class); + boolean flag = true; + for (GenTable table : genTableList) { + List list = this.baseMapper.selectList(new LambdaQueryWrapper().eq(GenTable::getTableName, table.getTableName())); + if (!CollectionUtils.isEmpty(list)) { + this.baseMapper.deleteBatchIds(list.stream().map(GenTable::getId).collect(Collectors.toList())); + for (GenTable genTable : list) { + genTableColumnService.remove(new LambdaQueryWrapper().eq(GenTableColumn::getTableId, genTable.getId())); } } - column.setHtmlType("input"); - column.setQueryType("="); - if ("String".equals(column.getJavaType())) { - column.setQueryType("like"); + // 两个参数:table_name、table_comment + table.setAuthor(entity.getAuthor()); + table.setParentPackage(entity.getParentPackage()); + table.setMavenModule(entity.getMavenModule()); + table.setModule(entity.getModule()); + table.setBusiness(StrUtil.toCamelCase(table.getTableName())); + table.setEntity(StrUtil.upperFirst(table.getBusiness())); + table.setEntityVo(StrUtil.addSuffixIfNot(table.getEntity(), "Vo")); + table.setController(StrUtil.addSuffixIfNot(table.getEntity(), "Controller")); + table.setService(StrUtil.addSuffixIfNot(table.getEntity(), "Service")); + table.setServiceAttr(StrUtil.lowerFirst(table.getService())); + table.setServiceImpl(StrUtil.addSuffixIfNot(table.getEntity(), "ServiceImpl")); + table.setMapper(StrUtil.addSuffixIfNot(table.getEntity(), "Mapper")); + table.setMapperXml(StrUtil.addSuffixIfNot(table.getEntity(), "Mapper")); + table.setIsPc(1); + table.setIsSave(1); + table.setIsUpdate(1); + table.setIsRemove(1); + table.setIsRemoveBatch(1); + table.setIsImport(1); + table.setIsExport(1); + int insertFlag = this.baseMapper.insert(table); + // 表字段 + List tableColumnVoList = genTableColumnService.queryByStructure(table.getTableName()); + for (GenTableColumnVo column : tableColumnVoList) { + column.setTableId(table.getId()); + String mysqlType = column.getColumnType(); + column.setJavaField(StrUtil.toCamelCase(column.getColumnName())); + if (CompareUtil.compare(column.getIsPk(), 1) == 0) { + table.setPkJavaField(column.getJavaField()); + table.setPkColumnName(column.getColumnName()); + this.baseMapper.updateById(table); + column.setIsQuery(0); + column.setIsForm(0); + column.setIsRequired(0); + column.setIsTable(0); + column.setIsLogicDelete(0); + } else { + column.setIsQuery(GenerateConst.QUERY_EXCLUDE_LIST.contains(column.getJavaField()) ? 0 : 1); + column.setIsForm(GenerateConst.QUERY_EXCLUDE_LIST.contains(column.getJavaField()) ? 0 : 1); + column.setIsRequired(GenerateConst.QUERY_EXCLUDE_LIST.contains(column.getJavaField()) ? 0 : 1); + column.setIsTable(GenerateConst.QUERY_EXCLUDE_LIST.contains(column.getJavaField()) ? 0 : 1); + column.setIsLogicDelete(Objects.equals(column.getJavaField(), BaseEntity.deleteStatus) ? 1 : 0); + } + column.setIsLogicDelete(Objects.equals(column.getJavaField(), BaseEntity.deleteStatus) ? 1 : 0); + if (column.getColumnType().indexOf("(") > -1) { + mysqlType = column.getColumnType().substring(0, column.getColumnType().indexOf("(")); + } + for (JavaToMysqlType javaToMysqlType : GenerateConst.JAVA_TYPE_TO_MYSQL_TYPE) { + if (javaToMysqlType.getTypeList().contains(mysqlType)) { + column.setJavaPackage(javaToMysqlType.getJavaPackage()); + column.setJavaType(javaToMysqlType.getJavaType()); + } + } + column.setHtmlType("input"); + column.setQueryType("="); + if ("String".equals(column.getJavaType())) { + column.setQueryType("like"); + } + column.setSort(0); } - column.setSort(0); + boolean saveBatchFlag = genTableColumnService.saveBatch(BeanUtil.copyToList(tableColumnVoList, GenTableColumn.class)); + flag = flag && ((insertFlag > 0) && saveBatchFlag); } - boolean saveBatchFlag = genTableColumnService.saveBatch(BeanUtil.copyToList(entityColumnVoList, GenTableColumn.class)); - return (insertFlag > 0) && saveBatchFlag; + return flag; + } + + @Override + public boolean updateEntity(GenTableVo entity) { + List columnList = JSON.parseArray(entity.getGenTableColumnJson(), GenTableColumn.class); + int insertFlag = this.baseMapper.updateById(entity); + boolean batchFlag = genTableColumnService.saveOrUpdateBatch(columnList); + return (insertFlag > 0) && batchFlag; } } diff --git a/quick-boot-generate/src/main/java/com/quickboot/generate/utils/VelocityUtils.java b/quick-boot-generate/src/main/java/com/quickboot/generate/utils/VelocityUtils.java index 2da9e609054ed399f3c07bd0afe99127af59c50d..5e2a53e593d5fe2c79005f3b0b2c8a163df0d2ae 100644 --- a/quick-boot-generate/src/main/java/com/quickboot/generate/utils/VelocityUtils.java +++ b/quick-boot-generate/src/main/java/com/quickboot/generate/utils/VelocityUtils.java @@ -12,6 +12,7 @@ import com.quickboot.generate.entity.GenTable; import com.quickboot.generate.entity.GenTableColumn; import com.quickboot.generate.mapper.GenTableColumnMapper; import com.quickboot.generate.mapper.GenTableMapper; +import org.apache.commons.lang3.StringUtils; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; @@ -41,9 +42,11 @@ public class VelocityUtils { /** * 代码生成 * - * @param id 代码生成-表ID + * @param id 代码生成-表ID + * @param type 类型 1-生成文件 2-代码预览 + * @return */ - public static void generate(Long id) { + public static Map generate(Long id, int type) { GenTableMapper genTableMapper = SpringUtil.getBean(GenTableMapper.class); GenTableColumnMapper genTableColumnMapper = SpringUtil.getBean(GenTableColumnMapper.class); @@ -82,15 +85,25 @@ public class VelocityUtils { templateMap.put("/vm/vue/views/index.vue.vm", "/" + genTable.getMavenModule() + "/vue/views/" + genTable.getModule() + "/" + genTable.getBusiness() + "/index.vue"); templateMap.put("/vm/vue/views/dataForm.vue.vm", "/" + genTable.getMavenModule() + "/vue/views/" + genTable.getModule() + "/" + genTable.getBusiness() + "/dataForm.vue"); + if (type == 1) { + for (Map.Entry entry : templateMap.entrySet()) { + String newFilePath = newPath + entry.getValue(); + FileUtil.touch(newFilePath); + StringWriter writer = new StringWriter(); + Velocity.getTemplate(entry.getKey(), "UTF-8").merge(context, writer); + FileUtil.writeString(writer.toString(), FileUtil.file(newFilePath), CharsetUtil.UTF_8); + } + return null; + } + Map fileMap = new HashMap<>(16); for (Map.Entry entry : templateMap.entrySet()) { - String templateFilePath = entry.getKey(); String newFilePath = newPath + entry.getValue(); - System.out.println("模板:" + templateFilePath); - System.out.println("生成:" + newFilePath); FileUtil.touch(newFilePath); StringWriter writer = new StringWriter(); - Velocity.getTemplate(templateFilePath, "UTF-8").merge(context, writer); + Velocity.getTemplate(entry.getKey(), "UTF-8").merge(context, writer); FileUtil.writeString(writer.toString(), FileUtil.file(newFilePath), CharsetUtil.UTF_8); + fileMap.put(StringUtils.substringAfterLast(entry.getKey(), "/").replace(".vm", ""), writer.toString()); } + return fileMap; } } diff --git a/quick-boot-generate/src/main/java/com/quickboot/generate/vo/GenTableVo.java b/quick-boot-generate/src/main/java/com/quickboot/generate/vo/GenTableVo.java index 0b401109b9da42e6183e70318bc7a84427b163d1..ca02095abd3519824deb5413d86806db7ac69a3b 100644 --- a/quick-boot-generate/src/main/java/com/quickboot/generate/vo/GenTableVo.java +++ b/quick-boot-generate/src/main/java/com/quickboot/generate/vo/GenTableVo.java @@ -17,4 +17,13 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @EqualsAndHashCode(callSuper = true) public class GenTableVo extends GenTable { + + /** + * 导入选中的表 + */ + private String genTableJson; + /** + * 更新列信息 + */ + private String genTableColumnJson; } diff --git a/quick-boot-generate/src/main/resources/mapper/generate/GenTableMapper.xml b/quick-boot-generate/src/main/resources/mapper/generate/GenTableMapper.xml index 5b9fea32193a87e2eca615e57cd7d4a378958762..c4d3c0fab15e74f2f730e926ad6f877e010f2d87 100644 --- a/quick-boot-generate/src/main/resources/mapper/generate/GenTableMapper.xml +++ b/quick-boot-generate/src/main/resources/mapper/generate/GenTableMapper.xml @@ -58,7 +58,33 @@ and A.mapper_xml like concat('%', #{entity.mapperXml}, '%') + + and A.pk_column_name like concat('%', #{entity.pkColumnName}, '%') + + + and A.is_pc = #{entity.isPc} + + + and A.is_save = #{entity.isSave} + + + and A.is_update = #{entity.isUpdate} + + + and A.is_remove = #{entity.isRemove} + + + and A.is_remove_batch = #{entity.isRemoveBatch} + + + and A.is_import = #{entity.isImport} + + + and A.is_export = #{entity.isExport} + + and A.delete_status = 1 + order by create_time desc - + select table_name, table_comment comment, create_time from information_schema.tables where table_schema = (select database()) + + and table_name like concat('%', #{entity.tableName}, '%') + + + and table_comment like concat('%', #{entity.comment}, '%') + order by create_time desc @@ -91,7 +123,16 @@ A.service_attr, A.service_impl, A.mapper, - A.mapper_xml + A.mapper_xml, + A.pk_column_name, + A.is_pc, + A.is_save, + A.is_update, + A.is_remove, + A.is_remove_batch, + A.is_import, + A.is_export, + A.delete_status diff --git a/quick-boot-generate/src/main/resources/vm/java/controller.java.vm b/quick-boot-generate/src/main/resources/vm/java/controller.java.vm index 88e919443fa62f4e554d0ef4a93230ace44bc6b2..c1e2f4b065b1f7335c093384429fc86e35d499ce 100644 --- a/quick-boot-generate/src/main/resources/vm/java/controller.java.vm +++ b/quick-boot-generate/src/main/resources/vm/java/controller.java.vm @@ -1,9 +1,17 @@ package ${table.parentPackage}.${table.module}.controller; import cn.dev33.satoken.annotation.SaCheckPermission; +#if(${table.isExport}) +import cn.hutool.core.date.DateUtil; +#end +import ${table.parentPackage}.common.consts.MsgConst; import ${table.parentPackage}.common.controller.BaseController; import ${table.parentPackage}.common.entity.Result; import ${table.parentPackage}.common.entity.TableResult; +#if(${table.isImport} || ${table.isExport}) +import ${table.parentPackage}.common.utils.EasyPoiExcelUtils; +#end +import ${table.parentPackage}.${table.module}.entity.${table.entity}; import ${table.parentPackage}.${table.module}.service.${table.service}; import ${table.parentPackage}.${table.module}.vo.${table.entityVo}; import io.swagger.annotations.Api; @@ -11,6 +19,11 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +#if(${table.isImport}) +import org.springframework.web.multipart.MultipartFile; +#end + +import java.util.List; /** * ${table.comment} 控制层 @@ -30,34 +43,70 @@ public class ${table.controller} extends BaseController { @SaCheckPermission("${table.module}:${table.business}:list") @GetMapping("/list") public TableResult<${table.entityVo}> queryList(${table.entityVo} entity) { - return TableResult.ok(${table.serviceAttr}.queryList(entity)); + return TableResult.ok(${table.serviceAttr}.queryList(getPage(), entity)); + } + + #if(${table.isImport}) + @ApiOperation("导入") + @SaCheckPermission("${table.module}:${table.business}:import") + @PostMapping("/importExcel") + public Result importExcel(@RequestParam("file") MultipartFile file) { + List<${table.entity}> list = EasyPoiExcelUtils.importExcel(file, 1, 1, ${table.entity}.class); + ${table.serviceAttr}.saveBatch(list, list.size()); + return Result.ok(MsgConst.IMPORT_SUCCESS + list.size() + "条数据"); } + #end + + #if(${table.isExport}) + @ApiOperation("导出") + @SaCheckPermission("${table.module}:${table.business}:export") + @GetMapping("/exportExcel") + public void exportExcel(${table.entityVo} entity) { + List<${table.entityVo}> list = ${table.serviceAttr}.queryList(getAllPage(), entity).getRecords(); + EasyPoiExcelUtils.exportExcel(list, "${table.comment}-" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss"), ${table.entityVo}.class); + } + #end @ApiOperation("根据ID查询") @SaCheckPermission("${table.module}:${table.business}:get") - @GetMapping("/queryById/{id}") - public Result<${table.entityVo}> queryById(@PathVariable("id") Long id) { - return queryResult(${table.serviceAttr}.queryById(id)); + @GetMapping("/queryById/{${table.pkJavaField}}") + public Result<${table.entityVo}> queryById(@PathVariable("${table.pkJavaField}") Long ${table.pkJavaField}) { + return queryResult(${table.serviceAttr}.queryById(${table.pkJavaField})); } + #if(${table.isSave}) @ApiOperation("新增") @SaCheckPermission("${table.module}:${table.business}:save") @PostMapping("/save") public Result save(@RequestBody ${table.entityVo} entity) { return saveResult(${table.serviceAttr}.save(entity)); } + #end + #if(${table.isUpdate}) @ApiOperation("根据ID更新") @SaCheckPermission("${table.module}:${table.business}:update") @PostMapping("/updateById") public Result updateById(@RequestBody ${table.entityVo} entity) { return updateResult(${table.serviceAttr}.updateById(entity)); } + #end + #if(${table.isRemove}) @ApiOperation("根据ID删除") @SaCheckPermission("${table.module}:${table.business}:remove") - @GetMapping("/removeById/{id}") - public Result removeById(@PathVariable("id") Long id) { - return removeResult(${table.serviceAttr}.removeById(id)); + @GetMapping("/removeById/{${table.pkJavaField}}") + public Result removeById(@PathVariable("${table.pkJavaField}") Long ${table.pkJavaField}) { + return removeResult(${table.serviceAttr}.removeById(${table.pkJavaField})); + } + #end + + #if(${table.isRemoveBatch}) + @ApiOperation("根据ID批量删除") + @SaCheckPermission("${table.module}:${table.business}:removeBatch") + @GetMapping("/removeBatchByIds/{ids}") + public Result removeBatchByIds(@PathVariable("ids") List ids) { + return removeResult(${table.serviceAttr}.removeBatchByIds(ids)); } + #end } diff --git a/quick-boot-generate/src/main/resources/vm/java/entity.java.vm b/quick-boot-generate/src/main/resources/vm/java/entity.java.vm index 1ad4f948d40d030e51525cb08319c55c3fd3249c..1da317f66a042b3d83a88875cce5d31bd10fbe24 100644 --- a/quick-boot-generate/src/main/resources/vm/java/entity.java.vm +++ b/quick-boot-generate/src/main/resources/vm/java/entity.java.vm @@ -1,5 +1,8 @@ package ${table.parentPackage}.${table.module}.entity; +#if(${table.isImport} || ${table.isExport}) +import cn.afterturn.easypoi.excel.annotation.Excel; +#end import com.baomidou.mybatisplus.annotation.*; import com.quickboot.common.entity.BaseEntity; import io.swagger.annotations.ApiModel; @@ -38,6 +41,9 @@ public class ${table.entity} extends BaseEntity { @ApiModelProperty(hidden = true) @TableField(fill = FieldFill.INSERT) #end + #if(${table.isImport} || ${table.isExport}) + @Excel(name = "${column.columnComment}") + #end private ${column.javaType} ${column.javaField}; #end } diff --git a/quick-boot-generate/src/main/resources/vm/java/mapper.java.vm b/quick-boot-generate/src/main/resources/vm/java/mapper.java.vm index 50304cdead6e922bff929cb0b99d70aa2db3599e..fc5a30eee29e629ddab5e8f7779e175beba66b94 100644 --- a/quick-boot-generate/src/main/resources/vm/java/mapper.java.vm +++ b/quick-boot-generate/src/main/resources/vm/java/mapper.java.vm @@ -26,8 +26,8 @@ public interface ${table.mapper} extends BaseMapper<${table.entity}> { /** * 根据ID查询 * - * @param id + * @param ${table.pkJavaField} * @return */ - ${table.entityVo} queryById(@Param("id") Long id); + ${table.entityVo} queryById(@Param("${table.pkJavaField}") Long ${table.pkJavaField}); } diff --git a/quick-boot-generate/src/main/resources/vm/java/mapper.xml.vm b/quick-boot-generate/src/main/resources/vm/java/mapper.xml.vm index 6c40e7c8e80e7b5ecb685bc19fc946e068255545..8b410d555bcfa3fbdf3cb63ec857b12952267d47 100644 --- a/quick-boot-generate/src/main/resources/vm/java/mapper.xml.vm +++ b/quick-boot-generate/src/main/resources/vm/java/mapper.xml.vm @@ -25,22 +25,13 @@ #end #foreach($column in ${columnList}) - #if(${column.javaField} == 'sort') - order by A.sort - #end + #if(${column.javaField} == 'createTime') order by#if(${column.javaField} == 'sort') A.sort,#end A.create_time desc#end #end diff --git a/quick-boot-generate/src/main/resources/vm/java/service.java.vm b/quick-boot-generate/src/main/resources/vm/java/service.java.vm index ad19cfe2f5d57f6ded91213216372894989ffe2d..7042a0db8056bba714b9d7e01f2e88a7d434508d 100644 --- a/quick-boot-generate/src/main/resources/vm/java/service.java.vm +++ b/quick-boot-generate/src/main/resources/vm/java/service.java.vm @@ -16,16 +16,17 @@ public interface ${table.service} extends IService<${table.entity}> { /** * 查询列表 * + * @param page * @param entity * @return */ - Page<${table.entityVo}> queryList(${table.entityVo} entity); + Page<${table.entityVo}> queryList(Page page, ${table.entityVo} entity); /** * 根据ID查询 * - * @param id + * @param ${table.pkJavaField} * @return */ - ${table.entityVo} queryById(Long id); + ${table.entityVo} queryById(Long ${table.pkJavaField}); } diff --git a/quick-boot-generate/src/main/resources/vm/java/serviceImpl.java.vm b/quick-boot-generate/src/main/resources/vm/java/serviceImpl.java.vm index 8911a27976203e2cc53eb843ed50b5662e32903d..8bc05749a3c59b70af670a6c53f7045f615cae36 100644 --- a/quick-boot-generate/src/main/resources/vm/java/serviceImpl.java.vm +++ b/quick-boot-generate/src/main/resources/vm/java/serviceImpl.java.vm @@ -2,11 +2,12 @@ package ${table.parentPackage}.${table.module}.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import ${table.parentPackage}.common.utils.PageUtils; import ${table.parentPackage}.${table.module}.entity.${table.entity}; import ${table.parentPackage}.${table.module}.mapper.${table.mapper}; import ${table.parentPackage}.${table.module}.service.${table.service}; import ${table.parentPackage}.${table.module}.vo.${table.entityVo}; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -16,15 +17,16 @@ import org.springframework.stereotype.Service; * @date ${date} */ @Service +@RequiredArgsConstructor(onConstructor_ = @Autowired) public class ${table.serviceImpl} extends ServiceImpl<${table.mapper}, ${table.entity}> implements ${table.service} { @Override - public Page<${table.entityVo}> queryList(${table.entityVo} entity) { - return this.baseMapper.queryList(PageUtils.getPage(), entity); + public Page<${table.entityVo}> queryList(Page page, ${table.entityVo} entity) { + return this.baseMapper.queryList(page, entity); } @Override - public ${table.entityVo} queryById(Long id) { - return this.baseMapper.queryById(id); + public ${table.entityVo} queryById(Long ${table.pkJavaField}) { + return this.baseMapper.queryById(${table.pkJavaField}); } } diff --git a/quick-boot-generate/src/main/resources/vm/vue/api/js.ts.vm b/quick-boot-generate/src/main/resources/vm/vue/api/js.ts.vm index 80a202c98001b0055885e8083db30bcfbb7f3823..49f3b288427101a19d30ecf0f4a2fbee5d1f236d 100644 --- a/quick-boot-generate/src/main/resources/vm/vue/api/js.ts.vm +++ b/quick-boot-generate/src/main/resources/vm/vue/api/js.ts.vm @@ -1,4 +1,4 @@ -import request from '~/framwork/request'; +import request, {downloadRequest} from '~/framwork/request'; /** 查询列表 */ export async function list${table.entity}(params: any): Promise { @@ -9,22 +9,38 @@ export async function list${table.entity}(params: any): Promise { }); } -/** 根据ID查询 */ -export async function get${table.entity}(id: any): Promise { +#if(${table.isImport}) +/** 导入 */ +export async function import${table.entity}(params: any): Promise { return request({ - url: '/${table.module}/${table.business}/queryById/' + id, - method: 'get' + url: '/${table.module}/${table.business}/importExcel', + method: 'post', + params }); } +#end +#if(${table.isExport}) /** 导出 */ -export async function export${table.entity}(): Promise { +export async function export${table.entity}(params: any) { + return downloadRequest({ + url: '/${table.module}/${table.business}/exportExcel', + method: 'get', + params, + responseType: 'blob' + }); +} +#end + +/** 根据ID查询 */ +export async function get${table.entity}(${table.pkJavaField}: any): Promise { return request({ - url: '/${table.module}/${table.business}/export', - method: 'post', + url: '/${table.module}/${table.business}/queryById/' + ${table.pkJavaField}, + method: 'get' }); } +#if(${table.isSave}) /** 新增 */ export async function save${table.entity}(data: any): Promise { return request({ @@ -33,7 +49,9 @@ export async function save${table.entity}(data: any): Promise { data }); } +#end +#if(${table.isUpdate}) /** 根据ID更新 */ export async function update${table.entity}(data: any): Promise { return request({ @@ -42,15 +60,19 @@ export async function update${table.entity}(data: any): Promise { data }); } +#end +#if(${table.isRemove}) /** 根据ID删除 */ -export async function remove${table.entity}(id: any): Promise { +export async function remove${table.entity}(${table.pkJavaField}: any): Promise { return request({ - url: '/${table.module}/${table.business}/removeById/' + id, + url: '/${table.module}/${table.business}/removeById/' + ${table.pkJavaField}, method: 'get', }); } +#end +#if(${table.isRemoveBatch}) /** 根据ID批量删除 */ export async function removeBatch${table.entity}(ids: any): Promise { return request({ @@ -58,3 +80,4 @@ export async function removeBatch${table.entity}(ids: any): Promise { method: 'get', }); } +#end diff --git a/quick-boot-generate/src/main/resources/vm/vue/views/dataForm.vue.vm b/quick-boot-generate/src/main/resources/vm/vue/views/dataForm.vue.vm index 25ab8d5334cfa9a3e15594bc6335b1c159aff00b..889e8c6d2e83eeea7466dbe4fc0f6e7a56ba9165 100644 --- a/quick-boot-generate/src/main/resources/vm/vue/views/dataForm.vue.vm +++ b/quick-boot-generate/src/main/resources/vm/vue/views/dataForm.vue.vm @@ -1,8 +1,8 @@ - + + #end + #end + #end
+ #if(${table.isSave}) 新增 - 导出 - 批量删除 + #end + #if(${table.isImport}) + 导入 + #end + #if(${table.isExport}) + 导出 + #end + #if(${table.isRemoveBatch}) + 批量删除 + #end
- + - #foreach($column in ${columnList}) #if(${column.isTable}) @@ -45,47 +55,81 @@ #end
-
- - -
+ + + #if(${table.isSave} || ${table.isUpdate}) + + v-if="data.visible" + :title="data.title" + :form="data.form" + @ok="handleClose" + @close="data.visible = false"/> + #end + + #if(${table.isImport}) + + + + + + +
将文件拖到此处,或点击上传
+ +
+ +
+ #end