From fdd25afd776313119a8e50fcc13bb2f1be684f70 Mon Sep 17 00:00:00 2001
From: cheng <1821349743@qq.com>
Date: 星期六, 08 四月 2023 23:26:44 +0800
Subject: [PATCH] update pom
---
/dev/null | 274 ----------------------
pom.xml | 48 ---
src/main/java/com/product/file/service/FileManagerService.java | 200 ----------------
src/main/java/com/product/file/controller/FileManagerController.java | 165 -------------
4 files changed, 10 insertions(+), 677 deletions(-)
diff --git a/pom.xml b/pom.xml
index c6e4220..262c1fd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,52 +6,29 @@
<parent>
<groupId>com.lx</groupId>
<artifactId>product-server</artifactId>
- <version>2.0.0-SNAPSHOT</version>
+ <version>2.0.0-release</version>
</parent>
<artifactId>product-server-file</artifactId>
<name>product-server-file</name>
<description>product-server-file</description>
+ <version>2.0.0-release</version>
<dependencies>
<dependency>
<groupId>com.lx</groupId>
<artifactId>product-server-common</artifactId>
- <version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>com.lx</groupId>
- <artifactId>product-server-util</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>com.lx</groupId>
- <artifactId>product-server-lucene</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </dependency>
+ <groupId>com.lx</groupId>
+ <artifactId>product-server-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.lx</groupId>
+ <artifactId>product-server-lucene</artifactId>
+ </dependency>
<!--releases -->
<dependency>
<groupId>com.lx</groupId>
<artifactId>product-server-core</artifactId>
- <version>1.0.0-releases</version>
- </dependency>
- <dependency>
- <groupId>com.azure</groupId>
- <artifactId>azure-storage-blob</artifactId>
- <version>12.8.0</version>
- </dependency>
- <dependency>
- <groupId>com.azure</groupId>
- <artifactId>azure-storage-file-share</artifactId>
- <version>12.6.0</version>
- </dependency>
- <dependency>
- <groupId>com.microsoft.azure</groupId>
- <artifactId>azure-storage-blob</artifactId>
- <version>10.1.0</version>
- </dependency>
- <dependency>
- <groupId>com.microsoft.azure</groupId>
- <artifactId>azure-storage-queue</artifactId>
- <version>10.0.0-Preview</version>
</dependency>
<!--浣跨敤open office-->
<dependency>
@@ -104,11 +81,6 @@
<artifactId>pdfbox</artifactId>
<version>2.0.6</version>
</dependency>
- <dependency>
- <groupId>org.eclipse.birt.runtime.3_7_1</groupId>
- <artifactId>com.lowagie.text</artifactId>
- <version>2.1.7</version>
- </dependency>
</dependencies>
-
+
</project>
diff --git a/src/main/java/com/product/file/controller/FileManagerController.java b/src/main/java/com/product/file/controller/FileManagerController.java
index 5caf7b9..f04e481 100644
--- a/src/main/java/com/product/file/controller/FileManagerController.java
+++ b/src/main/java/com/product/file/controller/FileManagerController.java
@@ -1,7 +1,6 @@
package com.product.file.controller;
import com.alibaba.fastjson.JSONObject;
-import com.product.common.lang.StringUtils;
import com.product.core.config.CoreConst;
import com.product.core.controller.support.AbstractBaseController;
import com.product.core.entity.FieldSetEntity;
@@ -56,144 +55,6 @@
}
}
- /**
- * 鏂囦欢璁板綍-鏂板
- *
- * @param request 璇锋眰
- * @return 缁撴灉
- */
- @RequestMapping(value = "/add-file-record-plan/{version}", method = RequestMethod.POST)
- @ApiVersion(1)
- public String addFileRecordPlan(HttpServletRequest request) {
- try {
- FieldSetEntity fse = null;
- Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
- RequestParameterEntity rpe = (RequestParameterEntity) bean;
- if (null != rpe && null != rpe.getFormData()) {
- fse = rpe.getFormData();
- }
- if (fse == null) {
- SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText());
- return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText());
- }
- FieldSetEntity fs = fileManagerService.addFileRecordPlan(fse);
- return fs != null ? this.OK_List(fs) : this.error(FileCode.ADD_FILE_RECORD_FAIL.getValue(), FileCode.ADD_FILE_RECORD_FAIL.getText());
- } catch (BaseException e) {
- SpringMVCContextHolder.getSystemLogger().error(e);
- return this.error(e.getCode(), e.getMessageInfo());
- } catch (Exception e) {
- SpringMVCContextHolder.getSystemLogger().error(e);
- e.printStackTrace();
- return error(FileCode.ADD_FILE_RECORD_FAIL.getValue(), FileCode.ADD_FILE_RECORD_FAIL.getText());
- }
- }
-
- /**
- * 鏂囦欢璁板綍-鏂囦欢鏂板缁撴灉鍥炶皟
- *
- * @param request 璇锋眰
- * @return 缁撴灉
- */
- @RequestMapping(value = "/add-file-callback/{version}", method = RequestMethod.POST)
- @ApiVersion(1)
- public String addFileCallback(HttpServletRequest request) {
- try {
- FieldSetEntity fse = null;
- Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
- RequestParameterEntity rpe = (RequestParameterEntity) bean;
- if (null != rpe && null != rpe.getFormData()) {
- fse = rpe.getFormData();
- }
- if (fse == null) {
- SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText());
- return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText());
- }
- JSONObject data = fileManagerService.addFileCallback(fse);
- JSONObject result = new JSONObject();
- result.put("data", data);
- result.put("msg", FileCode.SUCCESS.getText());
- result.put("code", "200");
- result.put("status", "success");
- return result.toString();
- } catch (BaseException e) {
- SpringMVCContextHolder.getSystemLogger().error(e);
- return this.error(e.getCode(), e.getMessageInfo());
- } catch (Exception e) {
- SpringMVCContextHolder.getSystemLogger().error(e);
- e.printStackTrace();
- return error(FileCode.ADD_FILE_CALLBACK_FAIL.getValue(), FileCode.ADD_FILE_CALLBACK_FAIL.getText());
- }
- }
-
- /**
- * 鏂囦欢璁板綍-鍒犻櫎鍑嗗锛堢姸鎬佷慨鏀癸級
- *
- * @param request 璇锋眰
- * @return 缁撴灉
- */
- @RequestMapping(value = "/del-file-record-plan/{version}", method = RequestMethod.POST)
- @ApiVersion(1)
- public String delFileRecordPlan(HttpServletRequest request) {
- try {
- FieldSetEntity fse = null;
- Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
- RequestParameterEntity rpe = (RequestParameterEntity) bean;
- if (null != rpe && null != rpe.getFormData()) {
- fse = rpe.getFormData();
- }
- if (fse == null) {
- SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText());
- return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText());
- }
- FieldSetEntity fs = fileManagerService.delFileRecordPlan(fse);
-
- return fs != null ? this.OK_List(fs) : this.error(FileCode.DELETE_FILE_PLAN_FIAL.getValue(), FileCode.DELETE_FILE_PLAN_FIAL.getText());
- } catch (BaseException e) {
- SpringMVCContextHolder.getSystemLogger().error(e);
- return this.error(e.getCode(), e.getMessageInfo());
- } catch (Exception e) {
- SpringMVCContextHolder.getSystemLogger().error(e);
- e.printStackTrace();
- return error(FileCode.DELETE_FILE_PLAN_FIAL.getValue(), FileCode.DELETE_FILE_PLAN_FIAL.getText());
- }
- }
-
- /**
- * 鏂囦欢璁板綍-鏂囦欢鏂板缁撴灉鍥炶皟
- *
- * @param request 璇锋眰
- * @return 缁撴灉
- */
- @RequestMapping(value = "/del-file-callback/{version}", method = RequestMethod.POST)
- @ApiVersion(1)
- public String delFileCallback(HttpServletRequest request) {
- try {
- FieldSetEntity fse = null;
- Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
- RequestParameterEntity rpe = (RequestParameterEntity) bean;
- if (null != rpe && null != rpe.getFormData()) {
- fse = rpe.getFormData();
- }
- if (fse == null) {
- SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText());
- return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText());
- }
- JSONObject data = fileManagerService.delFileCallback(fse);
- JSONObject result = new JSONObject();
- result.put("data", data);
- result.put("msg", FileCode.SUCCESS.getText());
- result.put("code", "200");
- result.put("status", "success");
- return result.toString();
- } catch (BaseException e) {
- SpringMVCContextHolder.getSystemLogger().error(e);
- return this.error(e.getCode(), e.getMessageInfo());
- } catch (Exception e) {
- SpringMVCContextHolder.getSystemLogger().error(e);
- e.printStackTrace();
- return error(FileCode.DELETE_FILE_CALLBACK_FIAL.getValue(), FileCode.DELETE_FILE_CALLBACK_FIAL.getText());
- }
- }
/**
* 鑾峰彇瀹㈡埛涓婁紶鐨勬枃浠舵�诲ぇ灏�
@@ -357,32 +218,6 @@
}
}
- /**
- * 鑾峰彇鏂囦欢璁板綍淇℃伅
- *
- * @return 缁撴灉
- */
- @RequestMapping(value = "/get-file-info/{version}", method = RequestMethod.POST)
- @ApiVersion(1)
- public String getFileInfo(HttpServletRequest request) {
- try {
- FieldSetEntity fse = null;
- Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
- RequestParameterEntity rpe = (RequestParameterEntity) bean;
- if (null != rpe && null != rpe.getFormData()) {
- fse = rpe.getFormData();
- }
- if (fse == null) {
- SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText());
- return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText());
- }
- return BaseUtil.success(fileManagerService.getFileInfo(fse), null);
- } catch (Exception e) {
- SpringMVCContextHolder.getSystemLogger().error(e);
- e.printStackTrace();
- return error(FileCode.CLEAR_NO_USED_DATA_FAIL.getValue(), FileCode.CLEAR_NO_USED_DATA_FAIL.getText());
- }
- }
/**
* 鏂囦欢鍒櫎
diff --git a/src/main/java/com/product/file/service/FileManagerService.java b/src/main/java/com/product/file/service/FileManagerService.java
index 74cec90..e1fd43b 100644
--- a/src/main/java/com/product/file/service/FileManagerService.java
+++ b/src/main/java/com/product/file/service/FileManagerService.java
@@ -1,10 +1,6 @@
package com.product.file.service;
import com.alibaba.fastjson.JSONObject;
-import com.azure.storage.blob.BlobServiceClient;
-import com.azure.storage.blob.BlobServiceClientBuilder;
-import com.azure.storage.common.sas.AccountSasPermission;
-import com.azure.storage.common.sas.AccountSasSignatureValues;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.product.common.lang.StringUtils;
@@ -84,131 +80,6 @@
throw new BaseException(FileCode.GET_FILE_FAIL);
}
-
- /**
- * 鏂囦欢璁板綍-鏂板
- *
- * @param fse 鍙傛暟瀵硅薄
- * @return UUID
- * @throws BaseException 鍩烘湰寮傚父
- */
- public FieldSetEntity addFileRecordPlan(FieldSetEntity fse) throws BaseException {
-
- //璁剧疆涓存椂token
- String url = Global.getSystemConfig(CmnConst.UPLOAD_URL, "");
- String sostoken = Global.getSystemConfig(CmnConst.UPLOAD_KEY, "");
- String connection_string = Global.getSystemConfig("upload.connection_string", "");
- BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().endpoint(url).sasToken(sostoken).connectionString(connection_string)
- .buildClient();
- AccountSasSignatureValues values1 = new AccountSasSignatureValues();
- AccountSasPermission permission1 = new AccountSasPermission().setReadPermission(true).setAddPermission(true).setWritePermission(true).setCreatePermission(true).setDeletePermission(true).setDeleteVersionPermission(true)
- .setUpdatePermission(true).setListPermission(true);
- values1.setPermissions(permission1);
- values1.setServices("bfqt");
- values1.setResourceTypes("sco");
- values1.setStartTime(OffsetDateTime.now());
- OffsetDateTime expiryTime = OffsetDateTime.now().plusMinutes(5);
- values1.setExpiryTime(expiryTime);
- String sas = blobServiceClient.generateAccountSas(values1);
- String CLIENT_UUID = fse.getString(CmnConst.CLIENT_UUID);
- if (StringUtils.isEmpty(CLIENT_UUID)) {
- String[] split = SpringMVCContextHolder.getCurrentUser().getClientUuid().split(",");
- CLIENT_UUID = split[0];
- fse.setValue(CmnConst.CLIENT_UUID, split[0]);
- }
-
-
- if (!StringUtils.isEmpty(CLIENT_UUID)) {
- FieldSetEntity clientFse = baseDao.getFieldSetEntityByFilter("product_sysclients", "uuid = ?", new String[]{CLIENT_UUID}, false);
- if (clientFse != null) {
- String curClientDomain = clientFse.getString(CmnConst.ATTACHMENT_DOMAIN);
- fse.setValue(CmnConst.ATTACHMENT_DOMAIN, StringUtils.isEmpty(curClientDomain) ? Global.getSystemConfig("default_domain", "") : curClientDomain);
- fse.setValue(CmnConst.ATTACHMENT_CONTAINER, clientFse.getUUID());
- }
- }
-
- if (!StringUtils.isEmpty(fse.getString(CmnConst.PRODUCT_UUID))) {
- FieldSetEntity productFse = baseDao.getFieldSetEntity("product_sysproducts", fse.getString(CmnConst.PRODUCT_UUID), false);
- fse.setValue(CmnConst.ATTACHMENT_ACCOUNT, productFse.getString("product_shortcode") + "_Account");
- }
-
- if (!StringUtils.isEmpty(fse.getString(CmnConst.MODULE_UUID))) {
- fse.setValue(CmnConst.MODULE_UUID, fse.getString(CmnConst.MODULE_UUID));
- } else if (!StringUtils.isEmpty(fse.getString(CmnConst.FUNCTION_UUID))) {
- FieldSetEntity functionFse = baseDao.getFieldSetEntity("product_sysfunctions", fse.getString(CmnConst.FUNCTION_UUID), false);
- FieldSetEntity moduleFse = baseDao.getFieldSetEntity("product_sysmodules", functionFse.getString(CmnConst.MODULE_UUID), false);
- fse.setValue(CmnConst.MODULE_UUID, moduleFse.getUUID());
- fse.setValue("attachment_catalog", moduleFse.getString("module_shortcode") + "_Directory");
- } else {//鍔熻兘銆佹ā鍧楅兘涓虹┖鏃�,浼犲埌鎸囧畾浣嶇疆
- fse.setValue(CmnConst.MODULE_UUID, "public-module");
- }
- String attachmentTitle = fse.getString(CmnConst.ATTACHMENT_TITLE);
- double curFileSize = fse.getDouble(CmnConst.ATTACHMENT_SIZE) == null ? 0d : fse.getDouble(CmnConst.ATTACHMENT_SIZE);
- if (!StringUtils.isEmpty(CLIENT_UUID) && findClientFileResidueCapacity(CLIENT_UUID) < curFileSize) {
- throw new BaseException(FileCode.ADD_FILE_NO_CAPACITY.getValue(), FileCode.ADD_FILE_NO_CAPACITY.getText());
- }
- //楠岃瘉鏂囦欢鏍煎紡
- String type = attachmentTitle.substring(attachmentTitle.lastIndexOf(".") + 1);
- type = type.toLowerCase();
- FieldSetEntity typeFse = baseDao.getFieldSetEntityByFilter("product_sysdict", "dict_name='upload_file_format' and dict_value=? and is_used=1", new Object[]{type}, false);
- if (typeFse == null) {
- throw new BaseException(FileCode.ADD_FILE_NOT_ALLOWED.getValue(), FileCode.ADD_FILE_NOT_ALLOWED.getText() + ":attachment_type_uuid");
- }
- fse.setValue("attachment_type_uuid", typeFse.getString("uuid"));
-
- Calendar c = Calendar.getInstance();
- String timeCatalog = c.get(Calendar.YEAR) + "/" + (c.get(Calendar.MONTH) + 1) + "/" + c.get(Calendar.DATE);
- fse.setValue("attachment_time_catalog", timeCatalog);
-
- fse.setValue("opt_flat", 1);
- fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
- fse.setValue(CmnConst.CREATED_UTC_DATETIME, c.getTime());
- //璁剧疆閲嶅懡鍚嶆枃浠跺強婧愭枃浠跺悕
- fse.setValue(CmnConst.FILE_NAME, fse.getString(CmnConst.ATTACHMENT_TITLE));
- String field_name = UUID.randomUUID().toString() + "." + type;
- fse.setValue(CmnConst.ATTACHMENT_TITLE, field_name);
-
-
- fse.getMeta().setTableName(new Object[]{CmnConst.PRODUCT_SYS_ATTACHMENTS});
- fse.setValue(CmnConst.CLIENT_UUID, fse.getString("uuid"));
- fse.setValue("uuid", null);
- //淇敼----鎶婇檮浠剁殑url鍦板潃淇濆瓨鍒板簱----shicf-------------
- StringBuilder upload_url = new StringBuilder();
- upload_url.append(fse.getString(CmnConst.ATTACHMENT_DOMAIN)).append("/")
- .append(fse.getString(CmnConst.ATTACHMENT_CONTAINER)).append("/").append(
- fse.getString(CmnConst.MODULE_UUID)).append("/").append(fse.getString(CmnConst.ATTACHMENT_TITLE))
- .append("?").append(sas);
- fse.setValue("attachment_url", upload_url.toString());
- //淇敼-------end--------------------
- String uuid = baseDao.add(fse);
-
- FieldSetEntity upload = new FieldSetEntity();
- upload.setTableName(new String[]{CmnConst.PRODUCT_SYS_ATTACHMENTS});
- upload.setValue("sostoken", "?" + sas);
- upload.setValue("uuid", uuid);
-
- upload.setValue("upload_url", upload_url.toString());
- fse.setValue("sostoken", "?" + sas);
- fse.setValue("upload_url", upload_url.toString());
-
- //璁剧疆鍓╀綑绌洪棿澶у皬
- fse.setValue(CmnConst.SOURCE_DOMAIN, Global.getSystemConfig(CmnConst.SOURCE_DOMAIN, ""));
- FieldSetEntity fss = baseDao.getFieldSetEntityByFilter("product_sysclients", "uuid=?", new String[]{CLIENT_UUID}, false);
- if (fss != null) {
- DataTableEntity da = baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS, "client_uuid=?", new String[]{fss.getString("uuid")});
- if (da.getRows() > 0) {
- int size = 0;
- for (int i = 0; i < da.getRows(); i++) {
- FieldSetEntity fiel = da.getFieldSetEntity(i);
- size = size + fiel.getInteger(CmnConst.ATTACHMENT_SIZE);
- }
- fse.setValue("residue_capacity", fss.getInteger(CmnConst.ATTACHMENT_CAPACITY) - size);
- } else {
- fse.setValue("residue_capacity", fss.getInteger(CmnConst.ATTACHMENT_CAPACITY));
- }
- }
- return upload;
- }
/**
* 鏂囦欢璁板綍-鏂囦欢鏂板缁撴灉鍥炶皟锛�
@@ -362,77 +233,6 @@
return baseDao.executeUpdate(sql.toString());
}
- /**
- * 鑾峰彇鏂囦欢淇℃伅鍦板潃
- */
- public Map<Object, Object> getFileInfo(FieldSetEntity fse) throws BaseException {
- //璁剧疆涓存椂token
- String url = Global.getSystemConfig(CmnConst.UPLOAD_URL, "");
- String sostoken = Global.getSystemConfig(CmnConst.UPLOAD_KEY, "");
- String CONNECTION_STRING = Global.getSystemConfig("upload.connection_string", "");
- BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().endpoint(url).sasToken(sostoken).connectionString(CONNECTION_STRING)
- .buildClient();
- OffsetDateTime expiryTime = OffsetDateTime.now().plusMinutes(5);
- AccountSasSignatureValues values1 = new AccountSasSignatureValues();
- values1.setExpiryTime(expiryTime);
- values1.setStartTime(OffsetDateTime.now());
- values1.setServices("bfqt");
- values1.setResourceTypes("sco");
- AccountSasPermission permission1 = new AccountSasPermission().setReadPermission(true).setDeletePermission(true);
- values1.setPermissions(permission1);
- String sas = blobServiceClient.generateAccountSas(values1);
- Map<Object, Object> date = new HashMap<>();
- if (fse.getUUID() != null) {
- String[] split = fse.getUUID().split(",");
- List<Map<String, String>> urls = new ArrayList<>();
- if (split.length > 0) {
- for (int i = 0; i < split.length; i++) {
- FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, split[i], false);
- if (fieldSetEntity != null) {
- Map<String, String> file = new HashMap<String, String>();
- file.put("path", fieldSetEntity.getString(CmnConst.ATTACHMENT_DOMAIN) + "/"
- + fieldSetEntity.getString(CmnConst.ATTACHMENT_CONTAINER) + "/"
- + fieldSetEntity.getString(CmnConst.MODULE_UUID) + "/"
- + fieldSetEntity.getString(CmnConst.ATTACHMENT_TITLE) + "?" + sas);
- file.put("name", fieldSetEntity.getString(CmnConst.ATTACHMENT_TITLE));
- file.put("size", fieldSetEntity.getString(CmnConst.ATTACHMENT_SIZE));
- file.put("uuid", fieldSetEntity.getString("uuid"));
- file.put(CmnConst.FILE_NAME, fieldSetEntity.getString(CmnConst.FILE_NAME));
- urls.add(file);
- }
- }
- }
-
- date.put("files", urls);
- }
- date.put("sastoken", "?" + sas);
- //鐫$湢1S锛屼繚璇乼oken鍐欏叆寰蒋浜�
- try {
- TimeUnit.SECONDS.sleep(1);
- } catch (InterruptedException ie) {
- Thread.currentThread().interrupt();
- ie.printStackTrace();
- throw new BaseException(ie);
- }
- return date;
- }
-
- /***
- * 妫�楠宻astoken鏄惁姝g‘
- */
- private Boolean checkSas(String sas) throws BaseException {
- //璁剧疆涓存椂token
- try {
- String url = Global.getSystemConfig(CmnConst.UPLOAD_URL, "");
- BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().endpoint(url).sasToken(sas)
- .buildClient();
- blobServiceClient.getProperties();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
/**
* 涓婁紶鏂囦欢鍒版湰鍦版湇鍔″櫒
diff --git a/src/main/java/com/product/file/util/JavaFileAllTopdfUtil.java b/src/main/java/com/product/file/util/JavaFileAllTopdfUtil.java
deleted file mode 100644
index 143dfca..0000000
--- a/src/main/java/com/product/file/util/JavaFileAllTopdfUtil.java
+++ /dev/null
@@ -1,151 +0,0 @@
-package com.product.file.util;
-
-import com.lowagie.text.Document;
-import com.lowagie.text.Font;
-import com.lowagie.text.HeaderFooter;
-import com.lowagie.text.Paragraph;
-import com.lowagie.text.Phrase;
-import com.lowagie.text.Rectangle;
-import com.lowagie.text.pdf.BaseFont;
-import com.lowagie.text.pdf.PdfWriter;
-import com.product.common.lang.DateUtils;
-
-import java.io.*;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Pattern;
-
-/**
- * @Author cheng
- * @Description
- * @Date 2021/10/28 11:47
- * @Version 1.0
- */
-public class JavaFileAllTopdfUtil {
-
-
- /**
- * window 鑷甫鐨勫瓧浣撴枃浠�
- */
- private static final String FONT = "C:\\Windows\\Fonts\\msyh.ttf";
- /**
- * 杞崲鏂囦欢鐨勭洰褰� 鑾峰彇璇ョ洰褰曚笅鎵�鏈夌殑 .java 绫诲瀷鐨勬枃浠�
- */
- private static final String convertingFileDirectories = "D:\\product\\浜у搧杩愯惀\\浜у搧钁椾綔鏉僜\java";
-
- // 缁欏畾鐩綍鐨勭粷瀵硅矾寰勶紝鑾峰彇璇ョ洰褰曚笅鐨勬墍鏈夋枃浠讹紙瀛愮洰褰曠殑鏂囦欢涔熷彲閫掑綊寰楀埌锛�
- private static List<File> getFile(String path) {
- // File瀵硅薄 鍙互鏄枃浠舵垨鑰呯洰褰�
- File file = new File(path == null ? convertingFileDirectories : path);
- File[] array = file.listFiles();
- List<File> result = new ArrayList<>();
- for (int i = 0; i < array.length; i++) {
- if (array[i].isFile()) {
- File file1 = array[i];
- String name = file1.getName();
- String file_type = name.substring(name.lastIndexOf(".") + 1);
- if (file_type.equalsIgnoreCase("java")) {
- result.add(array[i]);
- }
- } else if (array[i].isDirectory()) {
- result.addAll(getFile(array[i].getPath()));
- }
- }
- return result;
- }
-
-
- public static StringBuilder readFileToString() {
- String pattern = "^[0-9]*[\\s]*$";
- // 瀹氫箟杩斿洖缁撴灉
- System.out.println("姝e湪鏌ユ壘java鏂囦欢....");
- List<File> fileList = getFile(null);
- StringBuilder sb = new StringBuilder(256);
- System.out.println("姝e湪璇诲彇鏂囦欢......");
- for (int i = 0; i < fileList.size(); i++) {
- if(fileList.get(i).getName().indexOf("鍓�")>=0
- || fileList.get(i).getName().indexOf("鍚�")>=0
- ) {
- try (FileInputStream in = new FileInputStream(fileList.get(i));) {
- int len;
- byte[] bytes = new byte[1024];
- while ((len = in.read(bytes)) != -1) {
- sb.append(new String(bytes, 0, len));
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- System.out.println("鏂囦欢璇诲彇瀹屾垚锛屽叡璇诲彇鍒�" + fileList.size() + "涓枃浠�");
- // 杩斿洖鎷兼帴濂界殑JSON String
-
- try (OutputStream os = new FileOutputStream(new File(convertingFileDirectories + "\\javaCode.pdf"));) {
- Document document = new Document();
- InputStream streamReader = new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8));
- Reader reader = new InputStreamReader(streamReader);
- BufferedReader bufferedReader = new BufferedReader(reader);
- PdfWriter.getInstance(document, os);
-
- //鏂规硶涓�锛氫娇鐢╓indows绯荤粺瀛椾綋(TrueType)
- BaseFont baseFont = BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
- Font font = new Font(baseFont);
- font.setSize(8);
- HeaderFooter header=new HeaderFooter(new Phrase("浼佷笟杩愯惀绠$悊骞冲彴",font),false);
- header.setBorder(Rectangle.BOTTOM);
- header.setAlignment(1);
- HeaderFooter footer=new HeaderFooter(new Phrase("-",font),new Phrase("-",font));
- footer.setAlignment(1);
- footer.setBorder(Rectangle.TOP);
- document.setFooter(footer);
- document.setHeader(header);
-
- document.open();
-
-
- String str = "";
- System.out.println("姝e湪鍐欏叆pdf,璇风◢绛�....");
- while ((str = bufferedReader.readLine()) != null) {
- boolean isMatch = Pattern.matches(pattern, str);
- if(!isMatch) {
- String x="";
- for(int i=0;i<str.length();i++) {
- if((int)str.charAt(i)==9) {
- x+=" ";
- }else if((int)str.charAt(i)==32) {
- x+=" ";
- }else {
- break;
- }
- }
- document.add(new Paragraph(x+str, font));
- }
- }
- document.close();
- bufferedReader.close();
- System.out.println("鍐欏叆瀹屾垚,鏂囦欢淇濆瓨璺緞:" + convertingFileDirectories + "\\javaCode.pdf");
- } catch (Exception e) {
- System.out.println("鍐欏叆鍑洪敊");
- new File(convertingFileDirectories + "\\javaCode.pdf").delete();
- e.printStackTrace();
- }
- return sb;
- }
-
-
- public static void main(String[] args) {
- readFileToString();
-
-
-// String str=
-//// "import java.util.TreeMap;\r\n"
-// "*\r\n"
-// //+ "import org.springframework.beans.factory.annotation.Autowired;"
-// ;
-// String pattern = "^[0-9]*[\\s]*$";
-// boolean isMatch = Pattern.matches(pattern, str);
-//
-// System.out.println(isMatch);
- }
-}
diff --git a/src/main/java/com/product/file/util/JavaFileToPdfUtil.java b/src/main/java/com/product/file/util/JavaFileToPdfUtil.java
deleted file mode 100644
index 2edb776..0000000
--- a/src/main/java/com/product/file/util/JavaFileToPdfUtil.java
+++ /dev/null
@@ -1,274 +0,0 @@
-package com.product.file.util;
-
-
-import com.lowagie.text.Document;
-import com.lowagie.text.DocumentException;
-import com.lowagie.text.Font;
-import com.lowagie.text.Paragraph;
-import com.lowagie.text.pdf.BaseFont;
-import com.lowagie.text.pdf.PdfWriter;
-
-import java.io.*;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * java 鏂囦欢杞琾df
- *
- * @author cheng
- * @Date 2021骞�10鏈�19鏃�
- */
-public class JavaFileToPdfUtil {
- /**
- * window 鑷甫鐨勫瓧浣撴枃浠�
- */
- private static final String FONT = "C:\\Windows\\Fonts\\msyh.ttf";
-
- /**
- * 淇濆瓨pdf鐨勬枃浠跺す 锛堥渶瑕佹彁鍓嶅垱寤哄ソ锛�
- */
- private static final String savePdfFolder = "E:\\Desktop\\pdf\\";
- /**
- * 杞崲鏂囦欢鐨勭洰褰� 鑾峰彇璇ョ洰褰曚笅鎵�鏈夌殑 .java 绫诲瀷鐨勬枃浠�
- */
- private static final String convertingFileDirectories = "D:\\product\\浜у搧杩愯惀\\浜у搧钁椾綔鏉僜\java";
- /**
- * 鏄惁寮�鍚嚎绋嬭浆鎹�
- */
- private static final boolean EnableThread = true;
- /**
- * 姣忎釜绾跨▼澶勭悊java鏂囦欢鏁伴噺
- */
- private static final int ThreadCount = 10;
-
- /**
- * 鏄惁鍒涘缓鐩綍
- *
- * @param path
- * @return
- */
- public static boolean isexitsPath(String path) throws InterruptedException {
- String[] paths = path.split("\\\\");
- StringBuffer fullPath = new StringBuffer();
- for (int i = 0; i < paths.length; i++) {
- fullPath.append(paths[i]).append("\\\\");
- File file = new File(fullPath.toString());
- if (!file.exists()) {
- file.mkdir();
-// System.out.println("鍒涘缓鐩綍涓猴細" + fullPath.toString());
- }
- }
- File file = new File(fullPath.toString());
- if (!file.exists()) {
- return true;
- } else {
- return false;
- }
- }
-
-
-
- public static void text2pdf() throws DocumentException, IOException, InterruptedException {
- File savePdfFolder = new File(JavaFileToPdfUtil.savePdfFolder);
- if (!savePdfFolder.exists()) {
- System.out.println("閿欒锛氫繚瀛樿浆鎹㈠悗PDF鐩綍涓嶅瓨鍦ㄨ鍒涘缓," + savePdfFolder);
- return;
- }
- File convertingFileDirectories = new File(JavaFileToPdfUtil.convertingFileDirectories);
- if (!convertingFileDirectories.exists()) {
- System.out.println("閿欒锛氶渶瑕佽浆鎹㈢殑鏂囦欢鐩綍涓嶅瓨鍦�," + convertingFileDirectories);
- return;
- }
- List<File> file = getFile(null);
- for (int i = 0; i < file.size(); i++) {
- String parent1 = convertingFileDirectories.getParent();
- String savePath = file.get(i).getParent().replace(parent1, savePdfFolder.getPath());
- isexitsPath(savePath);
-
- }
- ThreadPoolTool<File> threadPoolTool = new ThreadPoolTool<>(EnableThread ? ThreadCount : file.size(), file);
- threadPoolTool.setCallBack((files) -> {
- try {
- new FileOut().run(files);
- } catch (Exception e) {
- e.printStackTrace();
- }
- });
- threadPoolTool.excute(false);
- System.out.println("杞崲瀹屾垚锛屽叡" + file.size() + "涓猨ava鏂囦欢");
- }
-
- static class FileOut {
- public void run(List<File> files) throws Exception {
- File savePdfFolder = new File(JavaFileToPdfUtil.savePdfFolder);
- File convertingFileDirectories = new File(JavaFileToPdfUtil.convertingFileDirectories);
- for (int i = 0; i < files.size(); i++) {
- Document document = new Document();
- String parent1 = convertingFileDirectories.getParent();
- System.out.println("姝e湪澶勭悊锛�" + files.get(i).getPath());
- String savePath = files.get(i).getParent().replace(parent1, savePdfFolder.getPath());
- String fileName = files.get(i).getName();
- OutputStream os = new FileOutputStream(new File(savePath + "\\" + fileName.substring(0, fileName.lastIndexOf(".")) + ".pdf"));
- PdfWriter.getInstance(document, os);
- document.open();
- //鏂规硶涓�锛氫娇鐢╓indows绯荤粺瀛椾綋(TrueType)
- BaseFont baseFont = BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
- Font font = new Font(baseFont);
- InputStreamReader isr = new InputStreamReader(new FileInputStream(files.get(i)), "UTF-8");
- BufferedReader bufferedReader = new BufferedReader(isr);
- String str = "";
- while ((str = bufferedReader.readLine()) != null) {
- document.add(new Paragraph(str, font));
- }
-
- document.close();
- os.flush();
- os.close();
- isr.close();
- bufferedReader.close();
- }
- }
- }
-
- // 缁欏畾鐩綍鐨勭粷瀵硅矾寰勶紝鑾峰彇璇ョ洰褰曚笅鐨勬墍鏈夋枃浠讹紙瀛愮洰褰曠殑鏂囦欢涔熷彲閫掑綊寰楀埌锛�
- private static List<File> getFile(String path) {
- // File瀵硅薄 鍙互鏄枃浠舵垨鑰呯洰褰�
- File file = new File(path == null ? convertingFileDirectories : path);
- File[] array = file.listFiles();
- List<File> result = new ArrayList<>();
- for (int i = 0; i < array.length; i++) {
- if (array[i].isFile()) {
- File file1 = array[i];
- String name = file1.getName();
- String file_type = name.substring(name.lastIndexOf(".") + 1);
- if (file_type.equalsIgnoreCase("java")) {
- result.add(array[i]);
- }
- } else if (array[i].isDirectory()) {
- result.addAll(getFile(array[i].getPath()));
- }
- }
- return result;
- }
-
- public static void main(String[] args) throws IOException, DocumentException, InterruptedException {
- text2pdf();
-// System.out.println(new File(convertingFileDirectories).getParent());
- }
-
-
- static class ThreadPoolTool<File> {
-
- //鍗曚釜绾跨▼澶勭悊鐨勬暟鎹噺
- private int singleCount;
- //澶勭悊鐨勬�绘暟鎹噺
- private int listSize;
- //寮�鍚殑绾跨▼鏁�
- private int runSize;
- //鎿嶄綔鐨勬暟鎹泦
- private List<java.io.File> list;
- //璁℃暟鍣�
- private CountDownLatch begin, end;
- //绾跨▼姹�
- private ExecutorService executorService;
- //鍥炶皟
- private CallBack callBack;
-
- public void setCallBack(CallBack callBack) {
- this.callBack = callBack;
- }
-
- public ThreadPoolTool(int singleCount, List<java.io.File> list) {
- this.singleCount = singleCount;
- this.list = list;
- if (list != null) {
- this.listSize = list.size();
- this.runSize = (this.listSize / this.singleCount) + 1;
- if (singleCount == 1) {
- this.runSize -= 1;
- }
- }
- }
-
- public void excute(boolean async) throws InterruptedException {
- executorService = Executors.newFixedThreadPool(runSize);
- begin = new CountDownLatch(1);
- end = new CountDownLatch(runSize);
- //鍒涘缓绾跨▼
- int startIndex = 0;
- int endIndex = 0;
- List<java.io.File> newList = null;
- for (int i = 0; i < runSize; i++) {
- //璁$畻姣忎釜绾跨▼瀵瑰簲鐨勬暟鎹�
- if (i < (runSize - 1)) {
- startIndex = i * singleCount;
- endIndex = (i + 1) * singleCount;
- newList = list.subList(startIndex, endIndex);
- } else {
- startIndex = i * singleCount;
- endIndex = listSize;
- newList = list.subList(startIndex, endIndex);
- }
- //鍒涘缓绾跨▼绫诲鐞嗘暟鎹�
- MyThread myThread = new MyThread(newList, begin, end) {
- @Override
- public void method(List<java.io.File> list) {
- callBack.method(list);
- }
- };
- //鎵ц绾跨▼
- if (!async) {
- executorService.submit(myThread);
- } else {
- executorService.execute(myThread);
- }
- }
- //璁℃暟鍣ㄥ噺涓�
- begin.countDown();
- end.await();
- //鍏抽棴绾跨▼姹�
- executorService.shutdown();
- }
-
- //鎶借薄绾跨▼绫�
- public abstract class MyThread implements Runnable {
-
- private List<java.io.File> list;
- private CountDownLatch begin, end;
-
- public MyThread(List<java.io.File> list, CountDownLatch begin, CountDownLatch end) {
- this.list = list;
- this.begin = begin;
- this.end = end;
- }
-
- @Override
- public void run() {
- try {
- //鎵ц绋嬪簭
- method(list);
- begin.await();
- } catch (InterruptedException e) {
- e.printStackTrace();
- throw new RuntimeException(e.getMessage());
- } finally {
- //璁℃暟鍣ㄥ噺涓�
- end.countDown();
- }
- }
-
- public abstract void method(List<java.io.File> list);
- }
-
- //鍥炶皟鎺ュ彛瀹氫箟
- public interface CallBack {
- public void method(List<java.io.File> list);
- }
-
-
- }
-
-}
\ No newline at end of file
--
Gitblit v1.9.2