From 595a2172e36e4cca45fd73e43b3004b86965b614 Mon Sep 17 00:00:00 2001 From: Carina Date: Fri, 28 May 2021 20:36:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=99=A8=E6=A8=A1=E6=9D=BF=20=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20(80%)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/opsli/core/utils/DictUtil.java | 34 +- .../api/GenTemplateDetailRestApi.java | 144 +++++++++ .../template/api/GenTemplateRestApi.java | 152 +++++++++ .../template/entity/GenTemplate.java | 54 ++++ .../template/entity/GenTemplateDetail.java | 58 ++++ .../mapper/GenTemplateDetailMapper.java | 36 +++ .../template/mapper/GenTemplateMapper.java | 36 +++ .../mapper/xml/GenTemplateDetailMapper.xml | 7 + .../template/mapper/xml/GenTemplateMapper.xml | 8 + .../service/IGenTemplateDetailService.java | 49 +++ .../template/service/IGenTemplateService.java | 52 ++++ .../impl/GenTemplateDetailServiceImpl.java | 230 ++++++++++++++ .../service/impl/GenTemplateServiceImpl.java | 175 +++++++++++ .../web/GenTemplateDetailRestController.java | 217 +++++++++++++ .../web/GenTemplateRestController.java | 241 ++++++++++++++ .../wrapper/GenTemplateAndDetailModel.java | 78 +++++ .../wrapper/GenTemplateDetailModel.java | 89 ++++++ .../template/wrapper/GenTemplateModel.java | 77 +++++ .../generator/utils/GenTemplateUtil.java | 294 ++++++++++++++++++ .../src/main/resources/generator.yaml | 2 + .../tpl/backend/api/TemplateRestApi.html | 1 + .../backend/web/TemplateRestController.html | 1 - .../tpl/foreend/index/TemplateIndex.html | 2 +- 23 files changed, 2034 insertions(+), 3 deletions(-) create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/api/GenTemplateDetailRestApi.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/api/GenTemplateRestApi.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/entity/GenTemplate.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/entity/GenTemplateDetail.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/GenTemplateDetailMapper.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/GenTemplateMapper.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/xml/GenTemplateDetailMapper.xml create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/xml/GenTemplateMapper.xml create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/IGenTemplateDetailService.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/IGenTemplateService.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/impl/GenTemplateDetailServiceImpl.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/impl/GenTemplateServiceImpl.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/web/GenTemplateDetailRestController.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/web/GenTemplateRestController.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateAndDetailModel.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateDetailModel.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateModel.java create mode 100644 opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/plugins/generator/utils/GenTemplateUtil.java diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java index 57e33a9..01c6361 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java @@ -51,6 +51,9 @@ import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; @Lazy(false) public class DictUtil { + /** 增加初始状态开关 防止异常使用 */ + private static boolean IS_INIT; + /** 字典Service */ private static DictDetailApi dictDetailApi; @@ -62,6 +65,10 @@ public class DictUtil { * @return String */ public static String getDictNameByValue(String typeCode, String dictValue, String defaultVal){ + // 判断 工具类是否初始化完成 + ThrowExceptionUtil.isThrowException(!IS_INIT, + CoreMsg.OTHER_EXCEPTION_UTILS_INIT); + // 缓存Key String cacheKey = DictConstants.CACHE_PREFIX_VALUE + typeCode; // 缓存Key + VALUE @@ -142,6 +149,10 @@ public class DictUtil { * @return String */ public static String getDictValueByName(String typeCode, String dictName, String defaultVal){ + // 判断 工具类是否初始化完成 + ThrowExceptionUtil.isThrowException(!IS_INIT, + CoreMsg.OTHER_EXCEPTION_UTILS_INIT); + // 缓存Key String cacheKey = DictConstants.CACHE_PREFIX_NAME + typeCode; // 缓存Key + VALUE @@ -219,6 +230,10 @@ public class DictUtil { * @return List */ public static List getDictList(String typeCode){ + // 判断 工具类是否初始化完成 + ThrowExceptionUtil.isThrowException(!IS_INIT, + CoreMsg.OTHER_EXCEPTION_UTILS_INIT); + // 缓存Key String cacheKey = DictConstants.CACHE_PREFIX_NAME + typeCode; @@ -336,6 +351,10 @@ public class DictUtil { * @param model 字典模型 */ public static void put(DictWrapper model){ + // 判断 工具类是否初始化完成 + ThrowExceptionUtil.isThrowException(!IS_INIT, + CoreMsg.OTHER_EXCEPTION_UTILS_INIT); + // 清除缓存 DictUtil.del(model); @@ -351,6 +370,10 @@ public class DictUtil { * @return boolean */ public static boolean del(DictWrapper model){ + // 判断 工具类是否初始化完成 + ThrowExceptionUtil.isThrowException(!IS_INIT, + CoreMsg.OTHER_EXCEPTION_UTILS_INIT); + if(model == null){ return true; } @@ -418,6 +441,10 @@ public class DictUtil { * @return boolean */ public static boolean delAll(String typeCode){ + // 判断 工具类是否初始化完成 + ThrowExceptionUtil.isThrowException(!IS_INIT, + CoreMsg.OTHER_EXCEPTION_UTILS_INIT); + List dictWrapperList = DictUtil.getDictList(typeCode); if(CollUtil.isEmpty(dictWrapperList)){ return true; @@ -465,9 +492,14 @@ public class DictUtil { // =================================== + /** + * 初始化 + */ @Autowired - public void setDictDetailApi(DictDetailApi dictDetailApi) { + public void init(DictDetailApi dictDetailApi) { DictUtil.dictDetailApi = dictDetailApi; + + IS_INIT = true; } } diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/api/GenTemplateDetailRestApi.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/api/GenTemplateDetailRestApi.java new file mode 100644 index 0000000..ab72bd4 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/api/GenTemplateDetailRestApi.java @@ -0,0 +1,144 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.api; + + +import org.opsli.api.base.result.ResultVo; +import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; + + +/** + * 代码模板详情 Api + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * @author 周鹏程 + * @date 2021-05-28 17:12:38 + */ +public interface GenTemplateDetailRestApi { + + /** 标题 */ + String TITLE = "代码模板详情"; + /** 子标题 */ + String SUB_TITLE = "代码模板详情"; + + /** + * 代码模板详情 查一条 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/get") + ResultVo get(GenTemplateDetailModel model); + + /** + * 代码模板详情 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @GetMapping("/findPage") + ResultVo findPage( + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest request + ); + + /** + * 代码模板详情 新增 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/insert") + ResultVo insert(@RequestBody GenTemplateDetailModel model); + + /** + * 代码模板详情 修改 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/update") + ResultVo update(@RequestBody GenTemplateDetailModel model); + + /** + * 代码模板详情 删除 + * @param id ID + * @return ResultVo + */ + @PostMapping("/del") + ResultVo del(String id); + + /** + * 代码模板详情 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @PostMapping("/delAll") + ResultVo delAll(String ids); + + /** + * 代码模板详情 Excel 导出 + * + * 导出时,Token认证和方法权限认证 全部都由自定义完成 + * 因为在 导出不成功时,需要推送错误信息, + * 前端直接走下载流,当失败时无法获得失败信息,即使前后端换一种方式后端推送二进制文件前端再次解析也是最少2倍的耗时 + * ,且如果数据量过大,前端进行渲染时直接会把浏览器卡死 + * 而直接开启socket接口推送显然是太过浪费资源了,所以目前采用Java最原始的手段 + * response 推送 javascript代码 alert 提示报错信息 + * + * @param request request + * @param response response + */ + @GetMapping("/exportExcel") + void exportExcel(HttpServletRequest request, HttpServletResponse response); + + /** + * 代码模板详情 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @PostMapping("/importExcel") + ResultVo importExcel(MultipartHttpServletRequest request); + + /** + * 代码模板详情 Excel 下载导入模版 + * @param response response + */ + @GetMapping("/importExcel/template") + void importTemplate(HttpServletResponse response); + + + /** + * 代码模板详情 Excel 下载导入模版 + * @param parentId parentId + * @return ResultVo + */ + @GetMapping("/findListByParentId") + ResultVo> findListByParentId(String parentId); + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/api/GenTemplateRestApi.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/api/GenTemplateRestApi.java new file mode 100644 index 0000000..4296608 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/api/GenTemplateRestApi.java @@ -0,0 +1,152 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.api; + + +import org.opsli.api.base.result.ResultVo; +import org.opsli.modulars.generator.template.wrapper.GenTemplateAndDetailModel; +import org.opsli.modulars.generator.template.wrapper.GenTemplateModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + + +/** + * 代码模板 Api + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * @author 周鹏程 + * @date 2021-05-27 14:33:49 + */ +public interface GenTemplateRestApi { + + /** 标题 */ + String TITLE = "代码模板"; + /** 子标题 */ + String SUB_TITLE = "代码模板"; + + /** + * 代码模板 查一条 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/get") + ResultVo get(GenTemplateModel model); + + /** + * 代码模板 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @GetMapping("/findPage") + ResultVo findPage( + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest request + ); + + /** + * 代码模板 新增 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/insert") + ResultVo insert(@RequestBody GenTemplateModel model); + + /** + * 代码模板 新增 和 明细 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/insertAndDetail") + ResultVo insertAndDetail(@RequestBody GenTemplateAndDetailModel model); + + /** + * 代码模板 修改 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/update") + ResultVo update(@RequestBody GenTemplateModel model); + + /** + * 代码模板 修改 和 明细 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/updateAndDetail") + ResultVo updateAndDetail(@RequestBody GenTemplateAndDetailModel model); + + /** + * 代码模板 删除 + * @param id ID + * @return ResultVo + */ + @PostMapping("/del") + ResultVo del(String id); + + /** + * 代码模板 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @PostMapping("/delAll") + ResultVo delAll(String ids); + + /** + * 代码模板 Excel 导出 + * + * 导出时,Token认证和方法权限认证 全部都由自定义完成 + * 因为在 导出不成功时,需要推送错误信息, + * 前端直接走下载流,当失败时无法获得失败信息,即使前后端换一种方式后端推送二进制文件前端再次解析也是最少2倍的耗时 + * ,且如果数据量过大,前端进行渲染时直接会把浏览器卡死 + * 而直接开启socket接口推送显然是太过浪费资源了,所以目前采用Java最原始的手段 + * response 推送 javascript代码 alert 提示报错信息 + * + * @param request request + * @param response response + */ + @GetMapping("/exportExcel") + void exportExcel(HttpServletRequest request, HttpServletResponse response); + + /** + * 代码模板 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @PostMapping("/importExcel") + ResultVo importExcel(MultipartHttpServletRequest request); + + /** + * 代码模板 Excel 下载导入模版 + * @param response response + */ + @GetMapping("/importExcel/template") + void importTemplate(HttpServletResponse response); + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/entity/GenTemplate.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/entity/GenTemplate.java new file mode 100644 index 0000000..6b9cfb8 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/entity/GenTemplate.java @@ -0,0 +1,54 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.entity; + + + +import java.math.BigDecimal; + +import java.util.Date; + +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; + +/** + * 代码模板 Entity + * + * @author 周鹏程 + * @date 2021-05-27 14:33:49 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class GenTemplate extends BaseEntity { + + /** 模板名称 */ + private String tempName; + + /** 表类型 */ + private String tableType; + + /** 备注信息 */ + private String remark; + + // ======================================== + + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/entity/GenTemplateDetail.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/entity/GenTemplateDetail.java new file mode 100644 index 0000000..26cdf64 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/entity/GenTemplateDetail.java @@ -0,0 +1,58 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.entity; + + + +import java.math.BigDecimal; + +import java.util.Date; + +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; + +/** + * 代码模板详情 Entity + * + * @author 周鹏程 + * @date 2021-05-28 17:12:38 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class GenTemplateDetail extends BaseEntity { + + + /** 父级ID */ + private String parentId; + + /** 路径 */ + private String path; + + /** 文件名 */ + private String fileName; + + /** 文件内容 */ + private String fileContent; + + // ======================================== + + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/GenTemplateDetailMapper.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/GenTemplateDetailMapper.java new file mode 100644 index 0000000..5762689 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/GenTemplateDetailMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import org.opsli.modulars.generator.template.entity.GenTemplateDetail; + + +/** + * 代码模板详情 Mapper + * + * @author 周鹏程 + * @date 2021-05-28 17:12:38 + */ +@Mapper +public interface GenTemplateDetailMapper extends BaseMapper { + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/GenTemplateMapper.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/GenTemplateMapper.java new file mode 100644 index 0000000..f1999ab --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/GenTemplateMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import org.opsli.modulars.generator.template.entity.GenTemplate; + + +/** + * 代码模板 Mapper + * + * @author 周鹏程 + * @date 2021-05-27 14:33:49 + */ +@Mapper +public interface GenTemplateMapper extends BaseMapper { + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/xml/GenTemplateDetailMapper.xml b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/xml/GenTemplateDetailMapper.xml new file mode 100644 index 0000000..2906766 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/xml/GenTemplateDetailMapper.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/xml/GenTemplateMapper.xml b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/xml/GenTemplateMapper.xml new file mode 100644 index 0000000..d77a503 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/mapper/xml/GenTemplateMapper.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/IGenTemplateDetailService.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/IGenTemplateDetailService.java new file mode 100644 index 0000000..182e472 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/IGenTemplateDetailService.java @@ -0,0 +1,49 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.service; + + +import org.opsli.core.base.service.interfaces.CrudServiceInterface; +import org.opsli.modulars.generator.template.entity.GenTemplateDetail; +import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel; + +import java.util.List; + + +/** + * 代码模板详情 Service + * + * @author 周鹏程 + * @date 2021-05-28 17:12:38 + */ +public interface IGenTemplateDetailService extends CrudServiceInterface { + + /** + * 根据父类ID 删除 + * @param parentId 父类ID + * @return boolean + */ + boolean delByParent(String parentId); + + /** + * 根据父类ID 查询List 集合 + * @param parentId 父类ID + * @return List + */ + List findListByParent(String parentId); + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/IGenTemplateService.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/IGenTemplateService.java new file mode 100644 index 0000000..f204b49 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/IGenTemplateService.java @@ -0,0 +1,52 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.service; + + +import org.opsli.core.base.service.interfaces.CrudServiceInterface; + + + +import org.opsli.modulars.generator.template.entity.GenTemplate; +import org.opsli.modulars.generator.template.wrapper.GenTemplateAndDetailModel; +import org.opsli.modulars.generator.template.wrapper.GenTemplateModel; + + +/** + * 代码模板 Service + * + * @author 周鹏程 + * @date 2021-05-27 14:33:49 + */ +public interface IGenTemplateService extends CrudServiceInterface { + + /** + * 新增 且 操作明细数据 + * @param model model + * @return GenTemplateModel + */ + GenTemplateModel insertAndDetail(GenTemplateAndDetailModel model); + + /** + * 修改 且 操作明细数据 + * @param model model + * @return GenTemplateModel + */ + GenTemplateModel updateAndDetail(GenTemplateAndDetailModel model); + + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/impl/GenTemplateDetailServiceImpl.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/impl/GenTemplateDetailServiceImpl.java new file mode 100644 index 0000000..72f210d --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/impl/GenTemplateDetailServiceImpl.java @@ -0,0 +1,230 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.service.impl; + + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.convert.Convert; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.common.collect.Lists; +import org.apache.commons.lang3.StringUtils; +import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.exception.ServiceException; +import org.opsli.common.utils.FieldUtil; +import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.core.msg.CoreMsg; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.modulars.generator.template.entity.GenTemplateDetail; +import org.opsli.modulars.generator.template.mapper.GenTemplateDetailMapper; +import org.opsli.modulars.generator.template.service.IGenTemplateDetailService; +import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel; +import org.opsli.plugins.generator.utils.GenTemplateUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + + +/** + * 代码模板详情 Service Impl + * + * @author 周鹏程 + * @date 2021-05-28 17:12:38 + */ +@Service +public class GenTemplateDetailServiceImpl extends CrudServiceImpl + implements IGenTemplateDetailService { + + @Autowired(required = false) + private GenTemplateDetailMapper mapper; + + + /** + * 新增 + * @param model model 数据模型 + * @return DictDetailModel + */ + @Transactional(rollbackFor = Exception.class) + @Override + public GenTemplateDetailModel insert(GenTemplateDetailModel model) { + GenTemplateDetailModel ret = super.insert(model); + if(ret != null){ + // 删除缓存 + this.clearCache(Collections.singletonList( + ret.getParentId() + )); + } + + return ret; + } + + + /** + * 修改 + * @param model model 数据模型 + * @return GenTemplateDetailModel + */ + @Transactional(rollbackFor = Exception.class) + @Override + public GenTemplateDetailModel update(GenTemplateDetailModel model) { + // 旧数据 用于删除老缓存 + GenTemplateDetailModel oldModel = this.get(model); + + GenTemplateDetailModel ret = super.update(model); + if(ret != null){ + // 删除缓存 + this.clearCache(Collections.singletonList( + oldModel.getParentId() + )); + } + + return ret; + } + + /** + * 删除 + * @param id ID + * @return boolean + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean delete(String id) { + GenTemplateDetailModel baseModel = this.get(id); + boolean ret = super.delete(id); + if(ret){ + // 删除缓存 + this.clearCache(Collections.singletonList( + baseModel.getParentId() + )); + } + return ret; + } + + /** + * 删除 - 多个 + * @param ids id数组 + * @return boolean + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean deleteAll(String[] ids) { + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper queryWrapper = queryBuilder.build(); + List idList = Convert.toList(ids); + queryWrapper.in(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID),idList); + List list = this.findList(queryWrapper); + boolean ret = super.deleteAll(ids); + + if(ret){ + if(CollUtil.isNotEmpty(list)){ + Set parentIds = new HashSet<>(); + // 封装数据 + for (GenTemplateDetail genTemplateDetail : list) { + parentIds.add(genTemplateDetail.getParentId()); + } + + List parentIdList = Lists.newArrayListWithCapacity(parentIds.size()); + + // 删除缓存 + this.clearCache(parentIdList); + } + } + return ret; + } + + /** + * 根据 父类ID 全部删除 + * @param parentId 父类ID + * @return boolean + */ + @Transactional(rollbackFor = Exception.class) + @Override + public boolean delByParent(String parentId) { + if(StringUtils.isEmpty(parentId)) { + return false; + } + + String key = FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID); + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper queryWrapper = queryBuilder.build(); + queryWrapper.eq(key, parentId); + + boolean removeFlag = super.remove(queryWrapper); + if(removeFlag){ + // 删除缓存 + this.clearCache(Collections.singletonList( + parentId + )); + } + return removeFlag; + } + + /** + * 根据 父类ID 全部删除 + * @param parentId 父类ID + * @return boolean + */ + @Transactional(rollbackFor = Exception.class) + @Override + public List findListByParent(String parentId) { + if(StringUtils.isEmpty(parentId)) { + return ListUtil.empty(); + } + + String key = FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID); + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper queryWrapper = queryBuilder.build(); + queryWrapper.eq(key, parentId); + + return super.transformTs2Ms(this.findList(queryWrapper)); + } + + + // ==================== + + + /** + * 清除缓存 + * @param parentIdList 父级ID集合 + */ + private void clearCache(List parentIdList) { + // 删除缓存 + if (CollUtil.isNotEmpty(parentIdList)) { + int cacheCount = 0; + for (String parentId : parentIdList) { + cacheCount++; + boolean tmp = GenTemplateUtil.delAll(parentId); + if(tmp){ + cacheCount--; + } + } + // 判断删除状态 + if(cacheCount != 0){ + // 删除缓存失败 + throw new ServiceException(CoreMsg.CACHE_DEL_EXCEPTION); + } + } + } + + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/impl/GenTemplateServiceImpl.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/impl/GenTemplateServiceImpl.java new file mode 100644 index 0000000..1dc05df --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/service/impl/GenTemplateServiceImpl.java @@ -0,0 +1,175 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.service.impl; + + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.exception.ServiceException; +import org.opsli.common.utils.WrapperUtil; +import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.core.msg.CoreMsg; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.modulars.generator.template.entity.GenTemplate; +import org.opsli.modulars.generator.template.mapper.GenTemplateMapper; +import org.opsli.modulars.generator.template.service.IGenTemplateDetailService; +import org.opsli.modulars.generator.template.service.IGenTemplateService; +import org.opsli.modulars.generator.template.wrapper.GenTemplateAndDetailModel; +import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel; +import org.opsli.modulars.generator.template.wrapper.GenTemplateModel; +import org.opsli.plugins.generator.utils.GenTemplateUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collections; +import java.util.List; + + +/** + * 代码模板 Service Impl + * + * @author 周鹏程 + * @date 2021-05-27 14:33:49 + */ +@Service +public class GenTemplateServiceImpl extends CrudServiceImpl + implements IGenTemplateService { + + @Autowired(required = false) + private GenTemplateMapper mapper; + @Autowired + private IGenTemplateDetailService iGenTemplateDetailService; + + @Transactional(rollbackFor = Exception.class) + @Override + public GenTemplateModel insertAndDetail(GenTemplateAndDetailModel model) { + if(model == null){ + return null; + } + + GenTemplateModel insertModel = super.insert( + WrapperUtil.transformInstance(model, GenTemplateModel.class)); + + if(insertModel != null){ + + // 保存模型明细 + List detailList = model.getDetailList(); + if(!CollUtil.isEmpty(detailList)){ + for (GenTemplateDetailModel templateDetailModel : detailList) { + templateDetailModel.setParentId(insertModel.getId()); + iGenTemplateDetailService.insert(templateDetailModel); + } + } + } + + return insertModel; + } + + @Transactional(rollbackFor = Exception.class) + @Override + public GenTemplateModel updateAndDetail(GenTemplateAndDetailModel model) { + if(model == null){ + return null; + } + + GenTemplateModel updateModel = super.update( + WrapperUtil.transformInstance(model, GenTemplateModel.class)); + + if(updateModel != null){ + + // 删除子表明细 + iGenTemplateDetailService.delByParent(model.getId()); + // 保存模型明细 + List detailList = model.getDetailList(); + if(!CollUtil.isEmpty(detailList)){ + for (GenTemplateDetailModel templateDetailModel : detailList) { + templateDetailModel.setParentId(updateModel.getId()); + iGenTemplateDetailService.insert(templateDetailModel); + } + } + + // 删除缓存 + this.clearCache(Collections.singletonList( + updateModel.getId() + )); + } + + return updateModel; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean delete(String id) { + GenTemplateModel base = this.get(id); + if (base == null) { + return false; + } + + iGenTemplateDetailService.delByParent(id); + + return this.delete(id); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean deleteAll(String[] ids) { + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper queryWrapper = queryBuilder.build(); + queryWrapper.in(MyBatisConstants.FIELD_ID, Convert.toList(String.class, ids)); + + // 查询数据 抽取Map 字典 便于后续查询 + List baseList = this.findList(queryWrapper); + for (GenTemplate base : baseList) { + // 先删除子数据 + iGenTemplateDetailService.delByParent(base.getId()); + } + + return super.deleteAll(ids); + } + + + // ==================== + + + /** + * 清除缓存 + * @param parentIdList 父级ID集合 + */ + private void clearCache(List parentIdList) { + // 删除缓存 + if (CollUtil.isNotEmpty(parentIdList)) { + int cacheCount = 0; + for (String parentId : parentIdList) { + cacheCount++; + boolean tmp = GenTemplateUtil.delAll(parentId); + if(tmp){ + cacheCount--; + } + } + // 判断删除状态 + if(cacheCount != 0){ + // 删除缓存失败 + throw new ServiceException(CoreMsg.CACHE_DEL_EXCEPTION); + } + } + } + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/web/GenTemplateDetailRestController.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/web/GenTemplateDetailRestController.java new file mode 100644 index 0000000..5e99e37 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/web/GenTemplateDetailRestController.java @@ -0,0 +1,217 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.web; + + +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.convert.Convert; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.opsli.common.annotation.RequiresPermissionsCus; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.core.base.controller.BaseRestController; +import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.modulars.generator.template.api.GenTemplateDetailRestApi; +import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel; +import org.opsli.plugins.generator.utils.GenTemplateUtil; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.lang.reflect.Method; +import java.util.List; + + +import org.opsli.modulars.generator.template.entity.GenTemplateDetail; +import org.opsli.modulars.generator.template.service.IGenTemplateDetailService; + + +/** + * 代码模板详情 Controller + * + * @author 周鹏程 + * @date 2021-05-28 17:12:38 + */ +@Api(tags = GenTemplateDetailRestApi.TITLE) +@Slf4j +@ApiRestController("/generator/template/detail") +public class GenTemplateDetailRestController extends BaseRestController + implements GenTemplateDetailRestApi { + + + /** + * 代码模板详情 查一条 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "获得单条代码模板详情", notes = "获得单条代码模板详情 - ID") + @RequiresPermissions("generator_template_select") + @Override + public ResultVo get(GenTemplateDetailModel model) { + // 如果系统内部调用 则直接查数据库 + if(model != null && model.getIzApi() != null && model.getIzApi()){ + model = IService.get(model); + } + return ResultVo.success(model); + } + + /** + * 代码模板详情 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器") + + @RequiresPermissions("generator_template_select") + + @Override + public ResultVo findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { + + QueryBuilder queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap()); + Page page = new Page<>(pageNo, pageSize); + page.setQueryWrapper(queryBuilder.build()); + page = IService.findPage(page); + + return ResultVo.success(page.getPageData()); + } + + /** + * 代码模板详情 新增 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "新增代码模板详情数据", notes = "新增代码模板详情数据") + @RequiresPermissions("generator_template_insert") + @EnableLog + @Override + public ResultVo insert(GenTemplateDetailModel model) { + // 调用新增方法 + IService.insert(model); + return ResultVo.success("新增代码模板详情成功"); + } + + /** + * 代码模板详情 修改 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "修改代码模板详情数据", notes = "修改代码模板详情数据") + @RequiresPermissions("generator_template_update") + @EnableLog + @Override + public ResultVo update(GenTemplateDetailModel model) { + // 调用修改方法 + IService.update(model); + return ResultVo.success("修改代码模板详情成功"); + } + + + /** + * 代码模板详情 删除 + * @param id ID + * @return ResultVo + */ + @ApiOperation(value = "删除代码模板详情数据", notes = "删除代码模板详情数据") + @RequiresPermissions("generator_template_update") + @EnableLog + @Override + public ResultVo del(String id){ + IService.delete(id); + return ResultVo.success("删除代码模板详情成功"); + } + + /** + * 代码模板详情 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @ApiOperation(value = "批量删除代码模板详情数据", notes = "批量删除代码模板详情数据") + @RequiresPermissions("generator_template_update") + @EnableLog + @Override + public ResultVo delAll(String ids){ + String[] idArray = Convert.toStrArray(ids); + IService.deleteAll(idArray); + return ResultVo.success("批量删除代码模板详情成功"); + } + + + /** + * 代码模板详情 Excel 导出 + * 注:这里 RequiresPermissionsCus 引入的是 自定义鉴权注解 + * + * 导出时,Token认证和方法权限认证 全部都由自定义完成 + * 因为在 导出不成功时,需要推送错误信息, + * 前端直接走下载流,当失败时无法获得失败信息,即使前后端换一种方式后端推送二进制文件前端再次解析也是最少2倍的耗时 + * ,且如果数据量过大,前端进行渲染时直接会把浏览器卡死 + * 而直接开启socket接口推送显然是太过浪费资源了,所以目前采用Java最原始的手段 + * response 推送 javascript代码 alert 提示报错信息 + * + * @param request request + * @param response response + */ + @ApiOperation(value = "导出Excel", notes = "导出Excel") + @RequiresPermissionsCus("generator_template_export") + @EnableLog + @Override + public void exportExcel(HttpServletRequest request, HttpServletResponse response) { + // 当前方法 + Method method = ReflectUtil.getMethodByName(this.getClass(), "exportExcel"); + QueryBuilder queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap()); + super.excelExport(GenTemplateDetailRestApi.SUB_TITLE, queryBuilder.build(), response, method); + } + + /** + * 代码模板详情 Excel 导入 + * 注:这里 RequiresPermissions 引入的是 Shiro原生鉴权注解 + * @param request 文件流 request + * @return ResultVo + */ + @ApiOperation(value = "导入Excel", notes = "导入Excel") + @RequiresPermissions("generator_template_import") + @EnableLog + @Override + public ResultVo importExcel(MultipartHttpServletRequest request) { + return super.importExcel(request); + } + + /** + * 代码模板详情 Excel 下载导入模版 + * 注:这里 RequiresPermissionsCus 引入的是 自定义鉴权注解 + * @param response response + */ + @ApiOperation(value = "导出Excel模版", notes = "导出Excel模版") + @RequiresPermissionsCus("generator_template_import") + @Override + public void importTemplate(HttpServletResponse response) { + // 当前方法 + Method method = ReflectUtil.getMethodByName(this.getClass(), "importTemplate"); + super.importTemplate(GenTemplateDetailRestApi.SUB_TITLE, response, method); + } + + @Override + public ResultVo> findListByParentId(String parentId) { + return ResultVo.success(GenTemplateUtil.getTemplateDetailList(parentId)); + } +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/web/GenTemplateRestController.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/web/GenTemplateRestController.java new file mode 100644 index 0000000..3e9100a --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/web/GenTemplateRestController.java @@ -0,0 +1,241 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.web; + + +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.convert.Convert; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.opsli.common.annotation.RequiresPermissionsCus; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.core.base.controller.BaseRestController; +import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.modulars.generator.template.api.GenTemplateRestApi; +import org.opsli.modulars.generator.template.wrapper.GenTemplateAndDetailModel; +import org.opsli.modulars.generator.template.wrapper.GenTemplateModel; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.lang.reflect.Method; + + +import org.opsli.modulars.generator.template.entity.GenTemplate; +import org.opsli.modulars.generator.template.service.IGenTemplateService; + + +/** + * 代码模板 Controller + * + * @author 周鹏程 + * @date 2021-05-27 14:33:49 + */ +@Api(tags = GenTemplateRestApi.TITLE) +@Slf4j + +@ApiRestController("/generator/template") + +public class GenTemplateRestController extends BaseRestController + implements GenTemplateRestApi { + + + /** + * 代码模板 查一条 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "获得单条代码模板", notes = "获得单条代码模板 - ID") + @RequiresPermissions("generator_template_select") + @Override + public ResultVo get(GenTemplateModel model) { + // 如果系统内部调用 则直接查数据库 + if(model != null && model.getIzApi() != null && model.getIzApi()){ + model = IService.get(model); + } + return ResultVo.success(model); + } + + /** + * 代码模板 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器") + @RequiresPermissions("generator_template_select") + @Override + public ResultVo findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { + + QueryBuilder queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap()); + Page page = new Page<>(pageNo, pageSize); + page.setQueryWrapper(queryBuilder.build()); + page = IService.findPage(page); + + return ResultVo.success(page.getPageData()); + } + + /** + * 代码模板 新增 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "新增代码模板数据", notes = "新增代码模板数据") + @RequiresPermissions("generator_template_insert") + @EnableLog + @Override + public ResultVo insert(GenTemplateModel model) { + // 调用新增方法 + IService.insert(model); + return ResultVo.success("新增代码模板成功"); + } + + /** + * 代码模板 新增 和 明细 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "新增代码模板数据", notes = "新增代码模板数据") + @RequiresPermissions("generator_template_insert") + @EnableLog + @Override + public ResultVo insertAndDetail(GenTemplateAndDetailModel model) { + // 调用新增方法 + IService.insertAndDetail(model); + return ResultVo.success("新增代码模板成功"); + } + + /** + * 代码模板 修改 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "修改代码模板数据", notes = "修改代码模板数据") + @RequiresPermissions("generator_template_update") + @EnableLog + @Override + public ResultVo update(GenTemplateModel model) { + // 调用修改方法 + IService.update(model); + return ResultVo.success("修改代码模板成功"); + } + + /** + * 代码模板 修改 和 明细 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "修改代码模板数据", notes = "修改代码模板数据") + @RequiresPermissions("generator_template_update") + @EnableLog + @Override + public ResultVo updateAndDetail(GenTemplateAndDetailModel model) { + // 调用修改方法 + IService.updateAndDetail(model); + return ResultVo.success("修改代码模板成功"); + } + + /** + * 代码模板 删除 + * @param id ID + * @return ResultVo + */ + @ApiOperation(value = "删除代码模板数据", notes = "删除代码模板数据") + @RequiresPermissions("generator_template_update") + @EnableLog + @Override + public ResultVo del(String id){ + IService.delete(id); + return ResultVo.success("删除代码模板成功"); + } + + /** + * 代码模板 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @ApiOperation(value = "批量删除代码模板数据", notes = "批量删除代码模板数据") + @RequiresPermissions("generator_template_update") + @EnableLog + @Override + public ResultVo delAll(String ids){ + String[] idArray = Convert.toStrArray(ids); + IService.deleteAll(idArray); + return ResultVo.success("批量删除代码模板成功"); + } + + + /** + * 代码模板 Excel 导出 + * 注:这里 RequiresPermissionsCus 引入的是 自定义鉴权注解 + * + * 导出时,Token认证和方法权限认证 全部都由自定义完成 + * 因为在 导出不成功时,需要推送错误信息, + * 前端直接走下载流,当失败时无法获得失败信息,即使前后端换一种方式后端推送二进制文件前端再次解析也是最少2倍的耗时 + * ,且如果数据量过大,前端进行渲染时直接会把浏览器卡死 + * 而直接开启socket接口推送显然是太过浪费资源了,所以目前采用Java最原始的手段 + * response 推送 javascript代码 alert 提示报错信息 + * + * @param request request + * @param response response + */ + @ApiOperation(value = "导出Excel", notes = "导出Excel") + @RequiresPermissionsCus("generator_template_export") + @EnableLog + @Override + public void exportExcel(HttpServletRequest request, HttpServletResponse response) { + // 当前方法 + Method method = ReflectUtil.getMethodByName(this.getClass(), "exportExcel"); + QueryBuilder queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap()); + super.excelExport(GenTemplateRestApi.SUB_TITLE, queryBuilder.build(), response, method); + } + + /** + * 代码模板 Excel 导入 + * 注:这里 RequiresPermissions 引入的是 Shiro原生鉴权注解 + * @param request 文件流 request + * @return ResultVo + */ + @ApiOperation(value = "导入Excel", notes = "导入Excel") + @RequiresPermissions("generator_template_import") + @EnableLog + @Override + public ResultVo importExcel(MultipartHttpServletRequest request) { + return super.importExcel(request); + } + + /** + * 代码模板 Excel 下载导入模版 + * 注:这里 RequiresPermissionsCus 引入的是 自定义鉴权注解 + * @param response response + */ + @ApiOperation(value = "导出Excel模版", notes = "导出Excel模版") + @RequiresPermissionsCus("generator_template_import") + @Override + public void importTemplate(HttpServletResponse response) { + // 当前方法 + Method method = ReflectUtil.getMethodByName(this.getClass(), "importTemplate"); + super.importTemplate(GenTemplateRestApi.SUB_TITLE, response, method); + } + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateAndDetailModel.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateAndDetailModel.java new file mode 100644 index 0000000..ee05223 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateAndDetailModel.java @@ -0,0 +1,78 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.wrapper; + + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validator.Validator; +import org.opsli.common.annotation.validator.ValidatorLenMax; +import org.opsli.common.enums.ValidatorType; +import org.opsli.plugins.excel.annotation.ExcelInfo; + +import java.util.List; + +/** +* 代码模板 Model +* +* @author 周鹏程 +* @date 2021-05-27 14:33:49 +*/ +@Data +@EqualsAndHashCode(callSuper = false) +public class GenTemplateAndDetailModel extends ApiWrapper { + + + /** 模板名称 */ + @ApiModelProperty(value = "模板名称") + @ExcelProperty(value = "模板名称", order = 1) + @ExcelInfo + @Validator({ + ValidatorType.IS_GENERAL_WITH_CHINESE, + ValidatorType.IS_NOT_NULL + }) + @ValidatorLenMax(100) + private String tempName; + + /** 表类型 */ + @ApiModelProperty(value = "表类型") + @ExcelProperty(value = "表类型", order = 2) + @ExcelInfo( dictType = "table_type" ) + @Validator({ + ValidatorType.IS_NOT_NULL + }) + @ValidatorLenMax(30) + private String tableType; + + + /** 备注信息 */ + @ApiModelProperty(value = "备注信息") + @ExcelProperty(value = "备注信息", order = 3) + @ExcelInfo + @ValidatorLenMax(255) + private String remark; + + /** 模板信息 */ + @ApiModelProperty(value = "模板信息") + @ExcelProperty(value = "模板信息", order = 4) + @ExcelInfo + private List detailList; + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateDetailModel.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateDetailModel.java new file mode 100644 index 0000000..8ed5a91 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateDetailModel.java @@ -0,0 +1,89 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.wrapper; + + + +import java.math.BigDecimal; + +import java.util.Date; + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validator.Validator; +import org.opsli.common.annotation.validator.ValidatorLenMax; +import org.opsli.common.annotation.validator.ValidatorLenMin; +import org.opsli.common.enums.ValidatorType; +import org.opsli.plugins.excel.annotation.ExcelInfo; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; + +/** +* 代码模板详情 Model +* +* @author 周鹏程 +* @date 2021-05-28 17:12:38 +*/ +@Data +@EqualsAndHashCode(callSuper = false) +public class GenTemplateDetailModel extends ApiWrapper { + + + /** 父级ID */ + @ApiModelProperty(value = "父级ID") + @ExcelProperty(value = "父级ID", order = 1) + @ExcelInfo + @Validator({ + ValidatorType.IS_NOT_NULL + }) + @ValidatorLenMax(19) + private String parentId; + + /** 路径 */ + @ApiModelProperty(value = "路径") + @ExcelProperty(value = "路径", order = 2) + @ExcelInfo + @Validator({ + ValidatorType.IS_NOT_NULL + }) + @ValidatorLenMax(255) + private String path; + + /** 文件名 */ + @ApiModelProperty(value = "文件名") + @ExcelProperty(value = "文件名", order = 3) + @ExcelInfo + @Validator({ + ValidatorType.IS_NOT_NULL + }) + @ValidatorLenMax(100) + private String fileName; + + /** 文件内容 */ + @ApiModelProperty(value = "文件内容") + @ExcelProperty(value = "文件内容", order = 4) + @ExcelInfo + @Validator({ + ValidatorType.IS_NOT_NULL + }) + @ValidatorLenMax(20000) + private String fileContent; + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateModel.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateModel.java new file mode 100644 index 0000000..1179718 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/template/wrapper/GenTemplateModel.java @@ -0,0 +1,77 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opsli.modulars.generator.template.wrapper; + + +import java.math.BigDecimal; + +import java.util.Date; + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validator.Validator; +import org.opsli.common.annotation.validator.ValidatorLenMax; +import org.opsli.common.annotation.validator.ValidatorLenMin; +import org.opsli.common.enums.ValidatorType; +import org.opsli.plugins.excel.annotation.ExcelInfo; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; + +/** +* 代码模板 Model +* +* @author 周鹏程 +* @date 2021-05-27 14:33:49 +*/ +@Data +@EqualsAndHashCode(callSuper = false) +public class GenTemplateModel extends ApiWrapper { + + + /** 模板名称 */ + @ApiModelProperty(value = "模板名称") + @ExcelProperty(value = "模板名称", order = 1) + @ExcelInfo + @Validator({ + ValidatorType.IS_GENERAL_WITH_CHINESE, + ValidatorType.IS_NOT_NULL + }) + @ValidatorLenMax(100) + private String tempName; + + /** 表类型 */ + @ApiModelProperty(value = "表类型") + @ExcelProperty(value = "表类型", order = 2) + @ExcelInfo( dictType = "table_type" ) + @Validator({ + ValidatorType.IS_NOT_NULL + }) + @ValidatorLenMax(30) + private String tableType; + + + /** 备注信息 */ + @ApiModelProperty(value = "备注信息") + @ExcelProperty(value = "备注信息", order = 3) + @ExcelInfo + @ValidatorLenMax(255) + private String remark; + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/plugins/generator/utils/GenTemplateUtil.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/plugins/generator/utils/GenTemplateUtil.java new file mode 100644 index 0000000..4e54857 --- /dev/null +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/plugins/generator/utils/GenTemplateUtil.java @@ -0,0 +1,294 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.plugins.generator.utils; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.comparator.CompareUtil; +import cn.hutool.core.convert.Convert; +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.web.system.dict.DictDetailApi; +import org.opsli.api.wrapper.system.dict.DictDetailModel; +import org.opsli.api.wrapper.system.dict.DictWrapper; +import org.opsli.common.constants.DictConstants; +import org.opsli.core.cache.local.CacheUtil; +import org.opsli.core.msg.CoreMsg; +import org.opsli.core.utils.DictUtil; +import org.opsli.core.utils.DistributedLockUtil; +import org.opsli.core.utils.ThrowExceptionUtil; +import org.opsli.modulars.generator.template.service.IGenTemplateDetailService; +import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; + +import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; + +/** + * 代码模板 + * + * @author parker + * @date 2020-09-22 11:17 + */ +@Slf4j +@Order(UTIL_ORDER) +@Component +@Lazy(false) +public class GenTemplateUtil { + + /** 增加初始状态开关 防止异常使用 */ + private static boolean IS_INIT; + + /** 缓存前缀 NAME */ + private static final String CACHE_PREFIX_NAME = "gen:template:"; + + /** 代码模板明细 Service */ + private static IGenTemplateDetailService genTemplateDetailService; + + /** + * 根据模板ID 模板明细列表 + * @param parentId 模板ID + * @return List + */ + public static List getTemplateDetailList(String parentId){ + // 判断 工具类是否初始化完成 + ThrowExceptionUtil.isThrowException(!IS_INIT, + CoreMsg.OTHER_EXCEPTION_UTILS_INIT); + + // 缓存Key + String cacheKey = CACHE_PREFIX_NAME + parentId; + + // 处理集合数据 + List wrapperModels = handleDictList( + CacheUtil.getHashAll(cacheKey), parentId); + if(CollUtil.isNotEmpty(wrapperModels)){ + return sortWrappers(wrapperModels); + } + + // 防止缓存穿透判断 + boolean hasNilFlag = CacheUtil.hasNilFlag(cacheKey); + if(hasNilFlag){ + return sortWrappers(wrapperModels); + } + + try { + // 分布式加锁 + if(!DistributedLockUtil.lock(cacheKey)){ + // 无法申领分布式锁 + log.error(CoreMsg.REDIS_EXCEPTION_LOCK.getMessage()); + return sortWrappers(wrapperModels); + } + + // 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求 + // 处理集合数据 + wrapperModels = handleDictList( + CacheUtil.getHashAll(cacheKey), parentId); + if(CollUtil.isNotEmpty(wrapperModels)){ + return sortWrappers(wrapperModels); + } + + + List listByParent = genTemplateDetailService.findListByParent(parentId); + // 处理数据库查询数据 + if(CollUtil.isNotEmpty(listByParent)){ + wrapperModels = listByParent; + // 计数器 + int count = wrapperModels.size(); + for (GenTemplateDetailModel model : wrapperModels) { + // 保存至缓存 + boolean ret = GenTemplateUtil.put(model); + if(ret){ + count--; + } + } + + // 回滚 清空缓存 + if(count != 0){ + for (GenTemplateDetailModel model : wrapperModels) { + GenTemplateUtil.del(model); + } + } + + return sortWrappers(wrapperModels); + } + + }catch (Exception e){ + log.error(e.getMessage(),e); + }finally { + // 释放锁 + DistributedLockUtil.unlock(cacheKey); + } + + // 如果值还是 为空 则赋默认值 + if(CollUtil.isEmpty(wrapperModels)){ + // 加入缓存防穿透 + // 设置空变量 用于防止穿透判断 + CacheUtil.putNilFlag(cacheKey); + } + + // 排序 + return sortWrappers(wrapperModels); + } + + /** + * 模板排序 + * @param wrapperModels 字典Model + * @return List + */ + private static List sortWrappers(List wrapperModels) { + // 非法判读 + if(wrapperModels == null){ + return null; + } + + return ListUtil.sort(wrapperModels, + (o1, o2) -> CompareUtil.compare(o1.getFileName(), o2.getFileName())); + } + + + // =============== + + + /** + * 删除 字典 + * @param model 字典模型 + */ + private static boolean put(GenTemplateDetailModel model){ + // 判断 工具类是否初始化完成 + ThrowExceptionUtil.isThrowException(!IS_INIT, + CoreMsg.OTHER_EXCEPTION_UTILS_INIT); + + // 清除缓存 + GenTemplateUtil.del(model); + + return CacheUtil.putHash(CACHE_PREFIX_NAME + model.getParentId(), + model.getId(), model); + } + + /** + * 删除 字典 + * @param model 字典模型 + * @return boolean + */ + public static boolean del(GenTemplateDetailModel model){ + // 判断 工具类是否初始化完成 + ThrowExceptionUtil.isThrowException(!IS_INIT, + CoreMsg.OTHER_EXCEPTION_UTILS_INIT); + + if(model == null){ + return true; + } + + boolean hasNilFlag = CacheUtil.hasNilFlag(CACHE_PREFIX_NAME + + model.getParentId() + ":" + model.getId()); + + GenTemplateDetailModel templateDetailModel = CacheUtil.getHash(GenTemplateDetailModel.class, + CACHE_PREFIX_NAME + model.getParentId(), + model.getId()); + + // 计数器 + int count = 0; + if (hasNilFlag){ + count++; + // 清除空拦截 + boolean tmp = CacheUtil.delNilFlag(CACHE_PREFIX_NAME + + model.getParentId() + ":" + model.getId()); + if(tmp){ + count--; + } + } + + if (templateDetailModel != null){ + count++; + // 清除空拦截 + boolean tmp = CacheUtil.delHash(CACHE_PREFIX_NAME + + model.getParentId(), model.getId()); + if(tmp){ + count--; + } + } + + return count == 0; + } + + /** + * 删除 parentId 下所有模板 + * @param parentId 模板ID + * @return boolean + */ + public static boolean delAll(String parentId){ + // 判断 工具类是否初始化完成 + ThrowExceptionUtil.isThrowException(!IS_INIT, + CoreMsg.OTHER_EXCEPTION_UTILS_INIT); + + List wrapperList = GenTemplateUtil.getTemplateDetailList(parentId); + if(CollUtil.isEmpty(wrapperList)){ + return true; + } + + // 计数器 + int count = wrapperList.size(); + for (GenTemplateDetailModel wrapperModel : wrapperList) { + boolean tmp = GenTemplateUtil.del(wrapperModel); + if(tmp){ + count--; + } + } + return count == 0; + } + + /*** + * 处理返回模板明细集合 + * @param tempMap Map + * @param id 模板ID + * @return List + */ + public static List handleDictList(Map tempMap, String id){ + List wrapperModels = Lists.newArrayList(); + if(CollUtil.isNotEmpty(tempMap)){ + for (Map.Entry entry : tempMap.entrySet()) { + // 赋值 + Object data = entry.getValue(); + GenTemplateDetailModel templateDetailModel = Convert.convert(GenTemplateDetailModel.class, data); + wrapperModels.add(templateDetailModel); + } + } + + // 返回排序后 list + return CollUtil.isNotEmpty(wrapperModels)?sortWrappers(wrapperModels):wrapperModels; + } + + + // =================================== + + /** + * 初始化 + */ + @Autowired + public void init(IGenTemplateDetailService genTemplateDetailService) { + GenTemplateUtil.genTemplateDetailService = genTemplateDetailService; + + IS_INIT = true; + } + +} diff --git a/opsli-modulars/opsli-modulars-generator/src/main/resources/generator.yaml b/opsli-modulars/opsli-modulars-generator/src/main/resources/generator.yaml index 87c9faf..f890104 100644 --- a/opsli-modulars/opsli-modulars-generator/src/main/resources/generator.yaml +++ b/opsli-modulars/opsli-modulars-generator/src/main/resources/generator.yaml @@ -5,6 +5,8 @@ opsli: - gen_table - gen_table_column - gen_logs + - gen_template + - gen_template_detail - sys_dict - sys_dict_detail - sys_logs diff --git a/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/backend/api/TemplateRestApi.html b/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/backend/api/TemplateRestApi.html index 3be317f..4b5b6cb 100644 --- a/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/backend/api/TemplateRestApi.html +++ b/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/backend/api/TemplateRestApi.html @@ -126,6 +126,7 @@ public interface #(data.model.tableHumpName)RestApi { /** * #(data.codeTitle) Excel 导入 * @param request 文件流 request + * @return ResultVo */ @PostMapping("/importExcel") ResultVo importExcel(MultipartHttpServletRequest request); diff --git a/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/backend/web/TemplateRestController.html b/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/backend/web/TemplateRestController.html index 4672ce9..a7560a9 100644 --- a/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/backend/web/TemplateRestController.html +++ b/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/backend/web/TemplateRestController.html @@ -21,7 +21,6 @@ package #(data.packageName+"."+data.moduleName).web; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.convert.Convert; -import org.opsli.core.base.service.interfaces.CrudServiceInterface; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; diff --git a/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/foreend/index/TemplateIndex.html b/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/foreend/index/TemplateIndex.html index 7352817..7317fe9 100644 --- a/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/foreend/index/TemplateIndex.html +++ b/opsli-modulars/opsli-modulars-generator/src/main/resources/tpl/foreend/index/TemplateIndex.html @@ -213,7 +213,7 @@ 查询 - #if(data.model.moreQueryList.size() > 0) + #if(data.model.moreQueryList != null && data.model.moreQueryList.size() > 0) 更多