Commit d5f7ebc4 by songxiang

错题本2.75期相关代码

parent 56de0445
/*
* 武汉理工数字传播工程有限公司源代码,版权归武汉理工数字传播工程有限公司所有.
* 项目名称 : pcloud-common
* 创建日期 : 2017年3月3日
* 修改历史 :
* 1. [2017年3月3日]创建文件 by xnxqs
*/
package com.pcloud.common.constant;
/**
*
*
* @Author: songx
* @Date: 2019/7/29,14:11
*/
public class FilePathConstant {
/**
* 视频剪切文件夹
*/
public final static String CUT = getFolder("cut");
/**
* 下载文件夹
*/
public final static String DOWNLOAD = getFolder("download");
/**
* 生成图片地址
*/
public final static String IMAGE = getFolder("image");
/**
* 生成带水印文件夹
*/
public final static String IMAGE_WATERMARK = getFolder("image/watermark");
/**
* 生成音频文件夹
*/
public final static String AUDIO = getFolder("audio");
/**
* 生成PDF文件夹
*/
public final static String PDF = getFolder("pdf");
/**
* 生成WORD文件夹
*/
public final static String WORD = getFolder("word");
/**
* 生成TEXT文件夹
*/
public final static String TEXT = getFolder("text");
/**
* 组装文件夹路径
*
* @param folderName
* @return
*/
private static String getFolder(String folderName) {
return OSConstant.USERDIR + OSConstant.SEPARATOR + "files" + folderName + OSConstant.SEPARATOR;
}
}
package com.pcloud.common.dto;
import com.pcloud.common.dto.BaseDto;
import java.math.BigDecimal;
/**
* @Describe: TODO
* @Author: zhangdongwei
* @Date: Create on 11:35 2019/7/24 0024
*/
public class StoreFlowInfoDto extends BaseDto {
/**
* 标识(appId/productId/bookGroupId)
*/
private Long originId;
/**
* 类型(APP/PRODUCT/BOOK_GROUP)
*/
private String originType;
/**
*具体类型
*/
private String typeCode;
/**
* 标题
*/
private String title;
/**
* 封面图片
*/
private String coverImg;
/**
* 价格
*/
private BigDecimal price;
/**
* 开始时间(MM-dd)
*/
private String startDate;
/**
* 结束时间(MM-dd)
*/
private String endDate;
/**
* 数量(应用、作品下的资源数量, 社群书的群数量,等)
*/
private Integer resourceNum;
/**
* 数量(资源的item数量,群的成员数量,等)
*/
private Integer resourceItemNum;
public Long getOriginId() {
return originId;
}
public void setOriginId(Long originId) {
this.originId = originId;
}
public String getOriginType() {
return originType;
}
public void setOriginType(String originType) {
this.originType = originType;
}
public String getTypeCode() {
return typeCode;
}
public void setTypeCode(String typeCode) {
this.typeCode = typeCode;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCoverImg() {
return coverImg;
}
public void setCoverImg(String coverImg) {
this.coverImg = coverImg;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public Integer getResourceNum() {
return resourceNum;
}
public void setResourceNum(Integer resourceNum) {
this.resourceNum = resourceNum;
}
public Integer getResourceItemNum() {
return resourceItemNum;
}
public void setResourceItemNum(Integer resourceItemNum) {
this.resourceItemNum = resourceItemNum;
}
@Override
public String toString() {
return "StoreFlowInfoDto{" +
"originId=" + originId +
", originType='" + originType + '\'' +
", typeCode='" + typeCode + '\'' +
", title='" + title + '\'' +
", coverImg='" + coverImg + '\'' +
", price=" + price +
", startDate='" + startDate + '\'' +
", endDate='" + endDate + '\'' +
", resourceNum=" + resourceNum +
", resourceItemNum=" + resourceItemNum +
"} " + super.toString();
}
}
......@@ -29,7 +29,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.pcloud.common.constant.AliyunConstant;
import com.pcloud.common.constant.FilePathConst;
import com.pcloud.common.constant.FilePathConstant;
import com.pcloud.common.constant.OSConstant;
import com.pcloud.common.entity.UploadResultInfo;
import com.pcloud.common.exceptions.BizException;
......@@ -215,7 +215,7 @@ public class FileUtils {
/**
* 传入文件夹路径,该方法能够实现创建整个路径
*
* @param path
* @param filePath
* 文件夹路径,不包含文件名称及后缀名
*/
public static boolean isDir(String filePath) {
......@@ -882,7 +882,7 @@ public class FileUtils {
String fileType = getFileType(url);
String localFilePath = url;
if (url.startsWith("http")) {
localFilePath = FilePathConst.TEXT_PATH + UUIDUitl.taskName() + "." + fileType;
localFilePath = FilePathConstant.TEXT + UUIDUitl.taskName() + "." + fileType;
downloadFileFromUrl(url, localFilePath);
}
try {
......@@ -919,7 +919,7 @@ public class FileUtils {
return null;
}
// 下载文件
String downloadPath = FilePathConst.DOWNLOAD_PATH + UUIDUitl.generateString(32) + "." + fileType;
String downloadPath = FilePathConstant.DOWNLOAD + UUIDUitl.generateString(32) + "." + fileType;
FileUtils.downloadFileFromUrl(url, downloadPath);
// 剪切文件
String cutPath = clipByPercent(new File(downloadPath), percent);
......@@ -969,7 +969,7 @@ public class FileUtils {
throw new FileException(FileException.FILE_READ_FAILURE, "剪切的文件必须大于1KB");
}
// 输出文件路径
String outFilePath = FilePathConst.CUT_PATH + UUIDUitl.generateString(12) + "_" + inputFile.getName();
String outFilePath = FilePathConstant.CUT + UUIDUitl.generateString(12) + "_" + inputFile.getName();
creatFiles(outFilePath);
// 剪切长度
cutLength = cutLength > inputFile.length() ? inputFile.length() : cutLength;
......
......@@ -11,16 +11,12 @@ import java.math.BigDecimal;
import javax.imageio.ImageIO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.itextpdf.text.Image;
import com.pcloud.common.constant.AliyunConstant;
import com.pcloud.common.constant.FilePathConst;
import com.pcloud.common.constant.ImageConstant;
import com.pcloud.common.entity.UploadResultInfo;
import com.pcloud.common.enums.ImageEnum;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.exceptions.FileException;
......@@ -738,37 +734,32 @@ public class ImageUtils {
* @param fileUrl
* @return
*/
// public static UploadResultInfo transcodeToWebp(String fileUrl, int quality) {
// LOGGER.info("【IMAGE API】image transcode to webp.<START>.[fileUrl]=" + fileUrl
// + ",[quality]=" + quality);
// String fileNameAll = FileUtils.getFileNameAll(fileUrl);
// String localFilePath = FilePathConst.DOWNLOAD_PATH + fileNameAll;
// FileUtils.downloadFileFromUrl(fileUrl, localFilePath);
// String outputFilePath = FilePathConst.IMAGE_PATH + "webp/" + fileNameAll +
// ".webp";
// FileUtils.creatFiles(outputFilePath);
// UploadResultInfo uploadResultInfo = null;
// try {
// String os = System.getProperty("os.name");
// if (os.toLowerCase().startsWith("win")) {
// executeCwebp4Win(localFilePath, outputFilePath, quality);
// } else {
// executeCwebp4Linux(localFilePath, outputFilePath, quality);
// }
// uploadResultInfo = OssUtils.uploadLocalFile4Child(outputFilePath, fileUrl);
// } catch (Exception e) {
// LOGGER.error("An error happend when convert to webp. Img is: " +
// e.getMessage(), e);
// throw new FileException(FileException.FILE_CONVERT_FAIL, "transcode to webp
// is fail!");
// } finally {
// FileUtils.deleteFile(localFilePath);
// FileUtils.deleteFile(outputFilePath);
// }
// LOGGER.info("【IMAGE API】image transcode to webp.<START>.[uploadResultInfo]="
// + uploadResultInfo);
// return uploadResultInfo;
// }
// public static UploadResultInfo transcodeToWebp(String fileUrl, int quality) {
// LOGGER.info("【IMAGE API】image transcode to webp.<START>.[fileUrl]=" + fileUrl + ",[quality]=" + quality);
// String fileNameAll = FileUtils.getFileNameAll(fileUrl);
// String localFilePath = FilePathConstant.DOWNLOAD_PATH + fileNameAll;
// FileUtils.downloadFileFromUrl(fileUrl, localFilePath);
// String outputFilePath = FilePathConstant.IMAGE_PATH + "webp/" + fileNameAll + ".webp";
// FileUtils.creatFiles(outputFilePath);
// UploadResultInfo uploadResultInfo = null;
// try {
// String os = System.getProperty("os.name");
// if (os.toLowerCase().startsWith("win")) {
// executeCwebp4Win(localFilePath, outputFilePath, quality);
// } else {
// executeCwebp4Linux(localFilePath, outputFilePath, quality);
// }
// uploadResultInfo = OssUtils.uploadLocalFile4Child(outputFilePath, fileUrl);
// } catch (Exception e) {
// LOGGER.error("An error happend when convert to webp. Img is: " + e.getMessage(), e);
// throw new FileException(FileException.FILE_CONVERT_FAIL, "transcode to webp is fail!");
// } finally {
// FileUtils.deleteFile(localFilePath);
// FileUtils.deleteFile(outputFilePath);
// }
// LOGGER.info("【IMAGE API】image transcode to webp.<START>.[uploadResultInfo]=" + uploadResultInfo);
// return uploadResultInfo;
// }
/**
* execute cwebp command:cwebp [options] input_file -o output_file.webp
......@@ -778,15 +769,13 @@ public class ImageUtils {
* @param quality
* @throws Exception
*/
// private static void executeCwebp4Win(String inputFilePath, String
// outputFilePath, int quality) throws Exception {
// Process process = new ProcessBuilder("cwebp", "-q", (quality == 0 ? 80 :
// quality) + "", inputFilePath, "-o",
// outputFilePath).redirectErrorStream(true).start();
// if (0 != process.waitFor()) {
// throw new Exception("process wait for fail!");
// }
// }
// private static void executeCwebp4Win(String inputFilePath, String outputFilePath, int quality) throws Exception {
// Process process = new ProcessBuilder("cwebp", "-q", (quality == 0 ? 80 : quality) + "", inputFilePath, "-o",
// outputFilePath).redirectErrorStream(true).start();
// if (0 != process.waitFor()) {
// throw new Exception("process wait for fail!");
// }
// }
/**
* execute cwebp command:cwebp [options] input_file -o output_file.webp
......@@ -796,47 +785,12 @@ public class ImageUtils {
* @param quality
* @throws Exception
*/
// private static void executeCwebp4Linux(String inputFilePath, String
// outputFilePath, int quality) throws Exception {
// Process process = new ProcessBuilder("/usr/local/bin/cwebp", "-q", (quality
// == 0 ? 80 : quality) + "",
// inputFilePath, "-o", outputFilePath).redirectErrorStream(true).start();
// if (0 != process.waitFor()) {
// throw new Exception("process wait for fail!");
// }
// }
/**
* 上传的图片转换成webpO
*
* @param localFilePath
* 源文件的本地路径
* @param httpUrl
* 源文件上传后的路径,主要用于子文件上传时对应http文件路径
*/
public static UploadResultInfo toWebp(String fileUrl) {
// String fileNameAll = FileUtils.getFileNameAll(fileUrl);
// String localFilePath = FilePathConst.DOWNLOAD_PATH + fileNameAll;
// FileUtils.downloadFileFromUrl(fileUrl, localFilePath);
// String tragetPath = null;
// try {
// tragetPath = com.dcg.util.ImageUtils.transcodeToWebp(localFilePath, 80);
// } catch (Exception e) {
// LOGGER.error("【IMAGE】图片转换成webp失败:" + e.getMessage(), e);
// return null;
// }
// if (StringUtils.isEmpty(tragetPath)) {
// return null;
// private static void executeCwebp4Linux(String inputFilePath, String outputFilePath, int quality) throws Exception {
// Process process = new ProcessBuilder("/usr/local/bin/cwebp", "-q", (quality == 0 ? 80 : quality) + "",
// inputFilePath, "-o", outputFilePath).redirectErrorStream(true).start();
// if (0 != process.waitFor()) {
// throw new Exception("process wait for fail!");
// }
// try {
// return OssUtils.uploadLocalFile4Child(tragetPath, fileUrl);
// } catch (Exception e) {
// LOGGER.error("【IMAGE】图片转换成webp,上传失败:" + e.getMessage(), e);
// } finally {
// FileUtils.deleteFile(localFilePath);
// FileUtils.deleteFile(tragetPath);
// }
return null;
}
// }
}
......@@ -40,7 +40,7 @@ import com.aliyuncs.mts.model.v20140618.SubmitSnapshotJobRequest;
import com.aliyuncs.mts.model.v20140618.SubmitSnapshotJobResponse.SnapshotJob;
import com.aliyuncs.profile.DefaultProfile;
import com.pcloud.common.constant.AliyunConstant;
import com.pcloud.common.constant.FilePathConst;
import com.pcloud.common.constant.FilePathConstant;
import com.pcloud.common.constant.UrlConstant;
import com.pcloud.common.dto.OssImageCropDTO;
import com.pcloud.common.dto.OssImageDTO;
......@@ -1600,7 +1600,7 @@ public class OssUtils {
// 创建OSSClient实例
OSSClient ossClient = getOSSClient(bucketName);
// 生成新的图片地址
String localPath = FilePathConst.IMAGE_PATH + UUIDUitl.generateString(32) + "." + fileType;
String localPath = FilePathConstant.IMAGE + UUIDUitl.generateString(32) + "." + fileType;
FileUtils.creatFiles(localPath);
try {
ossClient.getObject(request, new File(localPath));
......@@ -1720,7 +1720,7 @@ public class OssUtils {
// 创建OSSClient实例
OSSClient ossClient = getOSSClient(bucketName);
// 生成带水印的本地图片地址
String localPath = FilePathConst.IMAGE_WATERMARK_PATH + fileName + "_" + LocalDateUtils.getYmdhmss() + "."
String localPath = FilePathConstant.IMAGE_WATERMARK + fileName + "_" + LocalDateUtils.getYmdhmss() + "."
+ fileType;
FileUtils.creatFiles(localPath);
ossClient.getObject(request, new File(localPath));
......
......@@ -14,7 +14,6 @@ import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.pcloud.common.utils.rsa.MD5;
import com.pcloud.common.utils.string.StringUtil;
......@@ -25,17 +24,9 @@ import com.pcloud.common.utils.string.StringUtil;
*/
public class UrlUtils {
/**
*
*/
private static final Logger LOGGER = LoggerFactory.getLogger(UrlUtils.class);
/**
* 请求地址(新郎接口)
*/
private static final String REQUEST_URL = "https://api.weibo.com/2/short_url/shorten.json?source=1681459862&url_long=";
/**
* 请求地址(OWN)
*/
private static final String REQUEST_URL2 = "https://rays.5rs.me/convert/v1.0/url/shorten";
......@@ -51,20 +42,13 @@ public class UrlUtils {
public static final String PRIVATE_KEY = "lgsc1205";
/**
* 获取短链接(新浪)
* 获取短链接
*
* @param long_url
* @return
*/
public static String getShortUrl(String long_url) {
String result = callHttp(REQUEST_URL + long_url);
if (StringUtil.isEmpty(result)) {
return null;
}
JSONObject resultObject = JSONObject.parseObject(result);
JSONArray array = resultObject.getJSONArray("urls");
JSONObject object = array.getJSONObject(0);
return object.getString("url_short");
return getShortUrl4Own(long_url);
}
/**
......
......@@ -29,7 +29,7 @@ import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
import com.pcloud.common.constant.FilePathConst;
import com.pcloud.common.constant.FilePathConstant;
import com.pcloud.common.entity.UploadResultInfo;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.exceptions.FileException;
......@@ -105,7 +105,7 @@ public class PdfUtils {
*/
private static String pdfConvert(byte[] b, String fileName, String prefix, String format) throws FileException {
// 解析PDF文件
String outPath = FilePathConst.PDF_PATH + fileName + "_" + UUIDUitl.generateString(12);
String outPath = FilePathConstant.PDF + fileName + "_" + UUIDUitl.generateString(12);
File fi = new File(outPath);
if (!fi.exists()) {
fi.mkdirs();
......@@ -161,7 +161,7 @@ public class PdfUtils {
/**
* 创建PDF
*
* @param pdfChunkDOs
* @param pdfPOs
* @return
* @throws Exception
*/
......@@ -176,7 +176,7 @@ public class PdfUtils {
OutputStream os = null;
try {
// 输出路径
outPath = FilePathConst.PDF_PATH + UUIDUitl.taskName() + ".pdf";
outPath = FilePathConstant.PDF + UUIDUitl.taskName() + ".pdf";
FileUtils.creatFiles(outPath);
// 创建输出流
os = new FileOutputStream(new File(outPath));
......@@ -358,10 +358,8 @@ public class PdfUtils {
/**
* 加水印(字符串)
*
* @param inputFile
* @param filePath
* 需要加水印的PDF路径
* @param outputFile
* 输出生成PDF的路径
* @param waterMarkName
* 水印字符
*/
......
......@@ -590,5 +590,20 @@ public class StringUtil extends StringUtilParent {
}
return false;
}
/**
* 过滤HTML标签
*
* @param str
* @return
*/
public static String replaceHtml(String str) {
if (StringUtil.isEmpty(str)) {
return "";
}
Pattern p_html = Pattern.compile("<[^>]+>", Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(str);
return m_html.replaceAll("").replaceAll("&nbsp;", "");
}
}
......@@ -41,7 +41,7 @@ import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Table;
import com.lowagie.text.rtf.RtfWriter2;
import com.pcloud.common.constant.FilePathConst;
import com.pcloud.common.constant.FilePathConstant;
import com.pcloud.common.constant.WordConstant;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.exceptions.FileException;
......@@ -84,7 +84,7 @@ public class WordUtils {
RtfWriter2 rtfWriter2 = null;
try {
// 输出路径
outPath = FilePathConst.WORD_PATH + UUIDUitl.taskName() + ".doc";
outPath = FilePathConstant.WORD + UUIDUitl.taskName() + ".doc";
FileUtils.creatFiles(outPath);
// 创建输出流
os = new FileOutputStream(new File(outPath));
......@@ -302,14 +302,14 @@ public class WordUtils {
CustomXWPFDocument document = null;
FileOutputStream fos = null;
try {
wordTemplate = FilePathConst.WORD_PATH + UUIDUitl.taskName() + ".docx";
wordTemplate = FilePathConstant.WORD + UUIDUitl.taskName() + ".docx";
FileUtils.downloadFileFromUrl(WordConstant.TEMPLATE_URL, wordTemplate);
OPCPackage pack = POIXMLDocument.openPackage(wordTemplate);
document = new CustomXWPFDocument(pack);
// 添加内容到文档中
addChunks(wordPOs, document);
// 生成目标word
outPath = FilePathConst.WORD_PATH + UUIDUitl.taskName() + ".docx";
outPath = FilePathConstant.WORD + UUIDUitl.taskName() + ".docx";
fos = new FileOutputStream(outPath);
document.write(fos);
fos.flush();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment