From 1d6e7763f4a30272cc0818ea12f83697b7375c45 Mon Sep 17 00:00:00 2001 From: shikeying <shikeying@163.com> Date: 星期五, 23 二月 2024 15:17:19 +0800 Subject: [PATCH] 测试了aws oss,另外 mybatis模块还未完成 --- iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java | 62 +++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-) diff --git a/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java b/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java index 1c557bc..425c2d2 100644 --- a/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java +++ b/iplatform-base-admin/src/main/java/com/iplatform/base/controller/GenController.java @@ -1,14 +1,22 @@ package com.iplatform.base.controller; import com.iplatform.base.SystemController; +import com.iplatform.core.util.CharsetKit; import com.iplatform.core.util.Convert; import com.iplatform.mybatis.domain.GenTable; import com.iplatform.mybatis.domain.GenTableColumn; import com.iplatform.mybatis.domain.TableDataInfo; import com.iplatform.mybatis.service.IGenTableColumnService; import com.iplatform.mybatis.service.IGenTableService; +import com.iplatform.mybatis.service.MetaDataServiceImpl; +import com.iplatform.mybatis.util.VelocityInitializer; +import com.iplatform.mybatis.util.VelocityUtils; +import com.walker.infrastructure.utils.StringUtils; import com.walker.web.ResponseValue; import org.apache.commons.io.IOUtils; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.validation.annotation.Validated; @@ -22,10 +30,14 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.StringWriter; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; /** * 浠g爜鐢熸垚 鎿嶄綔澶勭悊銆� @@ -48,6 +60,9 @@ @Autowired private IGenTableColumnService genTableColumnService; + + @Autowired + private MetaDataServiceImpl metaDataService; /** * 鏌ヨ浠g爜鐢熸垚鍒楄〃 @@ -233,4 +248,51 @@ rspData.setTotal(0); return rspData; } + + /** + * 鐢熸垚鎸囧畾琛ㄧ粨鏋勪唬鐮侊紝鏀寔澶氭暟鎹簱銆� + * @param response + * @param tableName 琛ㄥ悕锛屽彲浠ユ槸绮剧‘鐨勮〃鍚嶏紝濡傦細s_ment锛屼篃鍙互鏄墠缂�锛屽锛歴_ + * @param isPrecision 鏄惁绮剧‘鏌ヨ锛堝崟琛級 + * @param packageName + * @throws IOException + * @date 2024-02-20 + */ + @GetMapping("/batchDownloadGenCode") + public void batchDownloadGenCode(HttpServletResponse response, String tableName, boolean isPrecision, String packageName) throws IOException{ + List<GenTable> list = this.metaDataService.queryDatabaseTableInfo(tableName, isPrecision, packageName, null, null, null); + if(StringUtils.isEmptyList(list)){ + logger.error("鏈煡鎵惧埌浠讳綍琛ㄤ俊鎭紝鏃犳硶鐢熷瓨浠g爜锛宼ableName={}", tableName); + return; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ZipOutputStream zip = new ZipOutputStream(outputStream); + for(GenTable table : list){ + VelocityInitializer.initVelocity(); + VelocityContext context = VelocityUtils.prepareContext(table); + + // 鑾峰彇妯℃澘鍒楄〃 + List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); + for (String template : templates) { + // 娓叉煋妯℃澘 + StringWriter sw = new StringWriter(); + Template tpl = Velocity.getTemplate(template, CharsetKit.UTF_8); + tpl.merge(context, sw); + try { + // 娣诲姞鍒皕ip + zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); + IOUtils.write(sw.toString(), zip, CharsetKit.UTF_8); + IOUtils.closeQuietly(sw); + zip.flush(); + zip.closeEntry(); + } + catch (IOException e) { + logger.error("娓叉煋妯℃澘澶辫触锛岃〃鍚嶏細" + table.getTableName(), e); + } + } + } + IOUtils.closeQuietly(zip); + byte[] data = outputStream.toByteArray(); + genCode(response, data); + } } -- Gitblit v1.9.1