Commit 6d2bc8ad authored by liqin's avatar liqin 💬

bug fixed

parent e812104a
package cn.wisenergy.chnmuseum.party.common.util;
import java.util.Random;
public class RandomUtil {
/**
* 创建指定数量的随机字符串
*
* @param length
* @return
*/
public static String createRandom(int length) {
String retStr = null;
String strTable = "1234567890";
int len = strTable.length();
boolean bDone = true;
do {
retStr = "";
int count = 0;
for (int i = 0; i < length; i++) {
double dblR = Math.random() * len;
int intR = (int) Math.floor(dblR);
char c = strTable.charAt(intR);
if (('0' <= c) && (c <= '9')) {
count++;
}
retStr += strTable.charAt(intR);
}
if (count >= 2) {
bDone = false;
}
} while (bDone);
return retStr;
}
public static String createLetterRandom(int length) {
String retStr = null;
String strTable = "1234567890abcdefghijklmnopqrstuvwxyz";
int len = strTable.length();
boolean bDone = true;
do {
retStr = "";
int count = 0;
for (int i = 0; i < length; i++) {
double dblR = Math.random() * len;
int intR = (int) Math.floor(dblR);
char c = strTable.charAt(intR);
if (('0' <= c) && (c <= '9')) {
count++;
}
retStr += strTable.charAt(intR);
}
if (count >= 2) {
bDone = false;
}
} while (bDone);
return retStr;
}
public static String[] arr = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
};
/**
* 创建指定数量的随机字符串
*
* @param length
* @return
*/
public static String createRandom(int length) {
String retStr = null;
String strTable = "1234567890";
int len = strTable.length();
boolean bDone = true;
do {
retStr = "";
int count = 0;
for (int i = 0; i < length; i++) {
double dblR = Math.random() * len;
int intR = (int) Math.floor(dblR);
char c = strTable.charAt(intR);
if (('0' <= c) && (c <= '9')) {
count++;
}
retStr += strTable.charAt(intR);
}
if (count >= 2) {
bDone = false;
}
} while (bDone);
return retStr;
}
public static String createLetterRandom(int length) {
StringBuilder retStr;
String strTable = "1234567890abcdef";
int len = strTable.length();
boolean bDone = true;
do {
retStr = new StringBuilder();
int count = 0;
for (int i = 0; i < length; i++) {
double dblR = Math.random() * len;
int intR = (int) Math.floor(dblR);
char c = strTable.charAt(intR);
if (('0' <= c) && (c <= '9')) {
count++;
}
retStr.append(strTable.charAt(intR));
}
if (count >= 2) {
bDone = false;
}
} while (bDone);
return retStr.toString();
}
public static String createCipher(int length) {
StringBuilder retStr;
String strTable = "1234567890abcdef";
int len = strTable.length();
boolean bDone = true;
do {
retStr = new StringBuilder();
int count = 0;
for (int i = 0; i < length; i++) {
double dblR = Math.random() * len;
int intR = (int) Math.floor(dblR);
char c = strTable.charAt(intR);
if (('0' <= c) && (c <= '9')) {
count++;
}
retStr.append(strTable.charAt(intR));
}
if (count >= 2) {
bDone = false;
}
} while (bDone);
return retStr.toString();
}
public static String getRandom(Integer len) {
String nums = "";
for (int i = 0; i < len; i++) {
Random r = new Random();
int index = r.nextInt(arr.length - 1);
String str = arr[index];
nums = nums + str;
}
return nums;
}
}
......@@ -115,12 +115,12 @@ public class Asset implements Serializable {
return false;
}
Asset asset = (Asset) o;
return md5.equals(asset.md5);
return Objects.equals(getMd5(), asset.getMd5());
}
@Override
public int hashCode() {
return Objects.hash(md5);
return Objects.hash(getMd5());
}
}
package cn.wisenergy.chnmuseum.party.web.controller;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.ZipUtil;
import cn.wisenergy.chnmuseum.party.common.dfs.FastDFSUtils;
import cn.wisenergy.chnmuseum.party.common.video.VideoEncryptUtil;
......@@ -46,6 +47,8 @@ import java.util.Set;
@Api(tags = {"文件资产操作接口"})
public class AssetController extends BaseController {
private static final String BASE_STRING = "1234567890abcdef";
@Resource
private AssetService assetService;
......@@ -153,14 +156,19 @@ public class AssetController extends BaseController {
final Map<String, InputStream> map = new LinkedHashMap<>(idList.size() + 1);
final List<Asset> assetList = assetService.listByIds(idList);
final String cipher = RandomUtil.randomString(BASE_STRING, 16);
for (final Asset asset : assetList) {
final String fileUrl = asset.getFileUrl();
ByteOutputStream byteOutputStream = new ByteOutputStream();
FastDFSUtils.downloadFile(fileUrl, byteOutputStream);
final Set<MetaData> fileMetaData = FastDFSUtils.getFileMetaData(fileUrl);
String fileName = fileMetaData.stream().filter(x -> "MD5".equals(x.getName())).map(MetaData::getValue).findFirst().get() + ".chnmuseum";
map.put(fileName, byteOutputStream.newInputStream());
map.put(fileName, VideoEncryptUtil.encrypt(byteOutputStream.newInputStream(), cipher));
}
map.put("23432423432.key", null);
ServletOutputStream outputStream = response.getOutputStream();
String[] paths = map.keySet().toArray(new String[0]);
InputStream[] ins = map.values().toArray(new InputStream[0]);
......
......@@ -434,10 +434,10 @@ public class FileUploadController extends BaseController {
final FileInfo fileInfo = FastDFSUtils.getFileInfo(fileUrl);
final Set<MetaData> fileMetaData = FastDFSUtils.getFileMetaData(fileUrl);
String md5 = fileMetaData.stream().filter(x -> "MD5".equals(x.getName())).map(MetaData::getValue).findFirst().get();
final Asset one = this.assetService.getOne(Wrappers.<Asset>lambdaQuery().eq(Asset::getMd5, md5));
if (one != null) {
final List<Asset> list = this.assetService.list(Wrappers.<Asset>lambdaQuery().eq(Asset::getMd5, md5));
if (!list.isEmpty()) {
FastDFSUtils.deleteFile(fileUrl);
fileList.add(one);
fileList.add(list.get(0));
handleResult.setFileUrl(fileUrl);
handleResult.setFileName(originalFilename);
......
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