From 8279e4cbd418df51fd312bd21a10eef700a676af Mon Sep 17 00:00:00 2001 From: pengren Date: Thu, 9 May 2024 09:55:16 +0800 Subject: [PATCH] =?UTF-8?q?H5=E7=A6=BB=E7=BA=BF=E5=8C=85=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sf/common/utils/openssl/AES256Util.java | 109 ++++++++++++++++++ .../DeploymentModuleListController.java | 57 +++++---- .../domain/rqs/ModuleListByCoreRequest.java | 3 + 3 files changed, 149 insertions(+), 20 deletions(-) create mode 100644 sf-common/src/main/java/com/sf/common/utils/openssl/AES256Util.java diff --git a/sf-common/src/main/java/com/sf/common/utils/openssl/AES256Util.java b/sf-common/src/main/java/com/sf/common/utils/openssl/AES256Util.java new file mode 100644 index 0000000..0058a2c --- /dev/null +++ b/sf-common/src/main/java/com/sf/common/utils/openssl/AES256Util.java @@ -0,0 +1,109 @@ +package com.sf.common.utils.openssl; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; + +import javax.crypto.Cipher; +import javax.crypto.CipherInputStream; +import javax.crypto.CipherOutputStream; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +public class AES256Util { + private static final String ALGORITHM = "AES/ECB/PKCS5Padding"; + + public static Cipher initAESCipher(String key, int cipherMode) throws Exception { + Cipher cipher = Cipher.getInstance(ALGORITHM); + SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES"); + cipher.init(cipherMode, secretKeySpec); + + return cipher; + } + + /** + * 加密文件 + * + * @return + */ + public static InputStream encryptFile(String key, InputStream inputStream) throws Exception { + Cipher cipher = initAESCipher(key, Cipher.ENCRYPT_MODE); + CipherInputStream cipherInputStream = new CipherInputStream(inputStream, cipher); + + return cipherInputStream; + } + + /** + * 解密文件 + * + * @param encryptedFile + * @param sourceFile + */ + public static String decryptFile(String key, File encryptedFile, File sourceFile) { + InputStream inputStream = null; + OutputStream outputStream = null; + CipherOutputStream cipherOutputStream = null; + try { + inputStream = new FileInputStream(encryptedFile); + outputStream = new FileOutputStream(sourceFile); + Cipher cipher = initAESCipher(key, Cipher.DECRYPT_MODE); + cipherOutputStream = new CipherOutputStream(outputStream, cipher); + byte[] buffer = new byte[1024]; + int n = -1; + int count = 0; + while ((n = inputStream.read(buffer)) != -1) { + count += n; + cipherOutputStream.write(buffer, 0, n); + cipherOutputStream.flush(); + } + + } catch (Exception e) { + return e.getLocalizedMessage(); + } + if (cipherOutputStream != null) { + try { + cipherOutputStream.close(); + } catch (IOException e) { + return e.getLocalizedMessage(); + } + } + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + return e.getLocalizedMessage(); + } + } + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + return e.getLocalizedMessage(); + } + } + + return ""; + } + +// public static void main(String[] args) throws Exception { +// File sourceFile = new File("/Users/a1234/Downloads/dist.zip"); +// InputStream encryptInputStream = encryptFile("efghijklmnopqrstuvwxyz0123456789", new FileInputStream(sourceFile)); +// OutputStream outputStream = new FileOutputStream(new File("/Users/a1234/Downloads/x.zip")); +// byte[] buffer = new byte[1024]; +// int n = -1; +// int count = 0; +// while ((n = encryptInputStream.read(buffer)) != -1) { +// count += n; +// outputStream.write(buffer, 0, n); +// } +// outputStream.flush(); +// System.out.println(count); +// +// decryptFile("efghijklmnopqrstuvwxyz0123456789", new File("/Users/a1234/Downloads/x.zip"), new File("/Users/a1234/Downloads/y.zip")); +// } +} + diff --git a/sf-system/src/main/java/com/sf/system/deployment/controller/DeploymentModuleListController.java b/sf-system/src/main/java/com/sf/system/deployment/controller/DeploymentModuleListController.java index 32ad186..e1846bb 100644 --- a/sf-system/src/main/java/com/sf/system/deployment/controller/DeploymentModuleListController.java +++ b/sf-system/src/main/java/com/sf/system/deployment/controller/DeploymentModuleListController.java @@ -1,14 +1,15 @@ package com.sf.system.deployment.controller; +import java.io.InputStream; +import java.net.URL; import java.util.List; import javax.servlet.http.HttpServletResponse; - import com.sf.common.enums.RequestHeaderEnums; -import com.sf.common.utils.StringUtils; import com.sf.common.utils.http.RequestUtils; import com.sf.system.deployment.domain.rqs.ModuleListByCoreRequest; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.FileCopyUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -28,14 +29,13 @@ import com.sf.common.core.page.TableDataInfo; /** * H5模块包Controller - * + * * @author ztzh * @date 2024-04-22 */ @RestController @RequestMapping("/deployment/module") -public class DeploymentModuleListController extends BaseController -{ +public class DeploymentModuleListController extends BaseController { @Autowired private IDeploymentModuleListService deploymentModuleListService; @@ -44,19 +44,18 @@ public class DeploymentModuleListController extends BaseController */ @PreAuthorize("@ss.hasPermi('deployment:module:list')") @GetMapping("/list") - public TableDataInfo list(DeploymentModuleList deploymentModuleList) - { + public TableDataInfo list(DeploymentModuleList deploymentModuleList) { deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode())); startPage(); List list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList); return getDataTable(list); } + /** * 查询H5模块包列表 */ @GetMapping("/qurey/list") - public AjaxResult queryByCore(ModuleListByCoreRequest request) - { + public AjaxResult queryByCore(ModuleListByCoreRequest request) { DeploymentModuleList deploymentModuleList = new DeploymentModuleList(); deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode())); deploymentModuleList.setSysType(request.getSysType()); @@ -64,14 +63,36 @@ public class DeploymentModuleListController extends BaseController return success(list); } + /** + * 查询模块包列表 + */ + @GetMapping("/qurey/file") + public AjaxResult queryByCore(ModuleListByCoreRequest request, HttpServletResponse response) { + DeploymentModuleList deploymentModuleList = new DeploymentModuleList(); + deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode())); + deploymentModuleList.setSysType(request.getSysType()); + deploymentModuleList.setModuleType(request.getModuleType()); + List list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList); + if (list.isEmpty() && null == list.get(0)) { + throw new SecurityException("无可用模块包"); + } + + try { + InputStream inputStream = new URL(list.get(0).getModuleUrl()).openStream(); + FileCopyUtils.copy(inputStream, response.getOutputStream()); + } catch (Exception e) { + throw new RuntimeException(e); + } + return success(null); + } + /** * 导出H5模块包列表 */ @PreAuthorize("@ss.hasPermi('deployment:module:export')") @Log(title = "H5模块包", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, DeploymentModuleList deploymentModuleList) - { + public void export(HttpServletResponse response, DeploymentModuleList deploymentModuleList) { List list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList); ExcelUtil util = new ExcelUtil(DeploymentModuleList.class); util.exportExcel(response, list, "H5模块包数据"); @@ -82,8 +103,7 @@ public class DeploymentModuleListController extends BaseController */ @PreAuthorize("@ss.hasPermi('deployment:module:query')") @GetMapping(value = "/{id}") - public AjaxResult getInfo(@PathVariable("id") Long id) - { + public AjaxResult getInfo(@PathVariable("id") Long id) { return success(deploymentModuleListService.selectDeploymentModuleListById(id)); } @@ -93,8 +113,7 @@ public class DeploymentModuleListController extends BaseController @PreAuthorize("@ss.hasPermi('deployment:module:add')") @Log(title = "H5模块包", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody DeploymentModuleList deploymentModuleList) - { + public AjaxResult add(@RequestBody DeploymentModuleList deploymentModuleList) { deploymentModuleList.setAppCode(RequestUtils.getHeader(RequestHeaderEnums.APP_CODE.getCode())); return toAjax(deploymentModuleListService.insertDeploymentModuleList(deploymentModuleList)); } @@ -105,8 +124,7 @@ public class DeploymentModuleListController extends BaseController @PreAuthorize("@ss.hasPermi('deployment:module:edit')") @Log(title = "H5模块包", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody DeploymentModuleList deploymentModuleList) - { + public AjaxResult edit(@RequestBody DeploymentModuleList deploymentModuleList) { return toAjax(deploymentModuleListService.updateDeploymentModuleList(deploymentModuleList)); } @@ -115,9 +133,8 @@ public class DeploymentModuleListController extends BaseController */ @PreAuthorize("@ss.hasPermi('deployment:module:remove')") @Log(title = "H5模块包", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable Long[] ids) - { + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(deploymentModuleListService.deleteDeploymentModuleListByIds(ids)); } } diff --git a/sf-system/src/main/java/com/sf/system/deployment/domain/rqs/ModuleListByCoreRequest.java b/sf-system/src/main/java/com/sf/system/deployment/domain/rqs/ModuleListByCoreRequest.java index 998f1f2..30adbdb 100755 --- a/sf-system/src/main/java/com/sf/system/deployment/domain/rqs/ModuleListByCoreRequest.java +++ b/sf-system/src/main/java/com/sf/system/deployment/domain/rqs/ModuleListByCoreRequest.java @@ -13,4 +13,7 @@ public class ModuleListByCoreRequest { @NotBlank private String sysType; + + @NotBlank + private String moduleType; }