Compare commits
No commits in common. "95a82bb69c231a30b2d35933e430381289dd4960" and "bee0344340a69527277759db873430e3937add4f" have entirely different histories.
95a82bb69c
...
bee0344340
|
|
@ -18,6 +18,7 @@ import com.electromagnetic.industry.software.common.enums.*;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||||
|
import com.electromagnetic.industry.software.common.util.EleLog;
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||||
|
|
@ -30,7 +31,6 @@ import com.electromagnetic.industry.software.manage.service.FileFormatService;
|
||||||
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
@ -43,12 +43,12 @@ import java.util.stream.Collectors;
|
||||||
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
||||||
import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.*;
|
import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.*;
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
@Component
|
||||||
public class CommonService {
|
public class CommonService {
|
||||||
|
|
||||||
private static final Map<Integer, String> PATH_MAP = new HashMap<>();
|
private static final Map<Integer, String> PATH_MAP = new HashMap<>();
|
||||||
|
|
||||||
|
private final EleLog log = new EleLog(CommonService.class);
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ElePropertyConfig elePropertyConfig;
|
private ElePropertyConfig elePropertyConfig;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,10 @@ import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.text.StrFormatter;
|
import cn.hutool.core.text.StrFormatter;
|
||||||
import cn.hutool.core.util.*;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.core.util.ZipUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import cn.hutool.crypto.symmetric.AES;
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
|
@ -39,7 +42,6 @@ import com.electromagnetic.industry.software.manage.pojo.resp.UploadRecordVO;
|
||||||
import com.electromagnetic.industry.software.manage.service.*;
|
import com.electromagnetic.industry.software.manage.service.*;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
|
@ -62,10 +64,10 @@ import static com.electromagnetic.industry.software.common.cons.ElectromagneticC
|
||||||
import static com.electromagnetic.industry.software.common.enums.DataOwnEnum.USER_FILE;
|
import static com.electromagnetic.industry.software.common.enums.DataOwnEnum.USER_FILE;
|
||||||
import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.*;
|
import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.*;
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
@Service
|
||||||
public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdFileInfoService {
|
public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdFileInfoService {
|
||||||
|
|
||||||
|
private final EleLog log = new EleLog(EdFileInfoServiceImpl.class);
|
||||||
@Resource
|
@Resource
|
||||||
private CommonService commonService;
|
private CommonService commonService;
|
||||||
@Resource
|
@Resource
|
||||||
|
|
@ -1310,7 +1312,11 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
}
|
}
|
||||||
|
|
||||||
String mimeType = Files.probeContentType(Paths.get(fileSaveTmpPath));
|
String mimeType = Files.probeContentType(Paths.get(fileSaveTmpPath));
|
||||||
mimeType = EleCommonUtil.simpleTrueFalse(ObjectUtil.isNull(mimeType), "application/octet-stream", mimeType);
|
if (mimeType == null) {
|
||||||
|
// 如果无法探测到MIME类型,则使用默认值 application/octet-stream
|
||||||
|
mimeType = "application/octet-stream";
|
||||||
|
}
|
||||||
|
|
||||||
FileSystemResource fileSystemResource = new FileSystemResource(fileSaveTmpPath);
|
FileSystemResource fileSystemResource = new FileSystemResource(fileSaveTmpPath);
|
||||||
String fileName = fileSystemResource.getFilename();
|
String fileName = fileSystemResource.getFilename();
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
|
@ -1565,79 +1571,69 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateImportPrj2FileSystem(MultipartFile file, String prjId) throws IOException {
|
private void updateImportPrj2FileSystem(MultipartFile file, String prjId) throws IOException {
|
||||||
String tmpZipFile = null;
|
String orgName = file.getOriginalFilename();
|
||||||
String destDir = null;
|
String tmpZipFile = elePropertyConfig.getEleTmpPath() + File.separator + orgName;
|
||||||
|
String mainName = FileUtil.mainName(orgName);
|
||||||
|
FileUtil.del(tmpZipFile);
|
||||||
|
FileUtil.writeFromStream(file.getInputStream(), tmpZipFile);
|
||||||
|
String destDir = elePropertyConfig.getEleTmpPath() + File.separator + IdUtil.fastSimpleUUID();
|
||||||
try {
|
try {
|
||||||
String orgName = file.getOriginalFilename();
|
ZipUtil.unzip(tmpZipFile, destDir, StandardCharsets.UTF_8);
|
||||||
tmpZipFile = elePropertyConfig.getEleTmpPath() + File.separator + orgName;
|
|
||||||
String mainName = FileUtil.mainName(orgName);
|
|
||||||
FileUtil.del(tmpZipFile);
|
|
||||||
FileUtil.writeFromStream(file.getInputStream(), tmpZipFile);
|
|
||||||
destDir = elePropertyConfig.getEleTmpPath() + File.separator + IdUtil.fastSimpleUUID();
|
|
||||||
try {
|
|
||||||
ZipUtil.unzip(tmpZipFile, destDir, StandardCharsets.UTF_8);
|
|
||||||
} catch (Exception e) {
|
|
||||||
ZipUtil.unzip(tmpZipFile, destDir, Charset.forName("GBK"));
|
|
||||||
}
|
|
||||||
|
|
||||||
File file1 = Objects.requireNonNull(new File(destDir).listFiles())[0];
|
|
||||||
FileUtil.rename(file1, mainName, true);
|
|
||||||
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
||||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
|
||||||
.likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT)
|
|
||||||
.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code));
|
|
||||||
Map<String, String> idNameMap = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, EdFileInfo::getFileName));
|
|
||||||
idNameMap.put(prjId, mainName);
|
|
||||||
Map<String, EdFileInfo> filePathMap = new HashMap<>();
|
|
||||||
for (EdFileInfo edFileInfo : edFileInfos) {
|
|
||||||
StringBuilder names = new StringBuilder();
|
|
||||||
for (String id : edFileInfo.getFilePath().split(MYSQL_FILE_PATH_SPLIT)) {
|
|
||||||
String name = idNameMap.get(id);
|
|
||||||
names.append(MYSQL_FILE_PATH_SPLIT).append(name);
|
|
||||||
}
|
|
||||||
filePathMap.put(names.substring(1), edFileInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<File> files = FileUtil.loopFiles(destDir);
|
|
||||||
String tmpPath = FileUtil.normalize(destDir);
|
|
||||||
for (File importFile : files) {
|
|
||||||
Assert.isTrue(EleCommonUtil.isFileNameValid(importFile.getName()), "文件名称不符合规范");
|
|
||||||
String parentDir = FileUtil.normalize(importFile.getParent());
|
|
||||||
String relativeFilePath = parentDir.replace(tmpPath, "");
|
|
||||||
String fileType = FileUtil.getSuffix(importFile.getName());
|
|
||||||
relativeFilePath = relativeFilePath.startsWith("/") ? relativeFilePath.substring(1) : relativeFilePath;
|
|
||||||
relativeFilePath = relativeFilePath.replace("/", MYSQL_FILE_PATH_SPLIT);
|
|
||||||
EdFileInfo edFileInfo = filePathMap.get(relativeFilePath);
|
|
||||||
Assert.notNull(edFileInfo, "导入的工程与定义的层级结构不一致");
|
|
||||||
String id = edFileInfo.getId();
|
|
||||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
|
||||||
newEdFileInfo.newInit();
|
|
||||||
String fileCode = commonService.createFileCode(id, fileType, FILE_START_VERSION, newEdFileInfo.getFileTime());
|
|
||||||
newEdFileInfo.setParentId(id)
|
|
||||||
.setFileCode(fileCode)
|
|
||||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
|
||||||
.setDataOwn(DataOwnEnum.SYS_FILE.code)
|
|
||||||
.setFileName(FileUtil.mainName(importFile))
|
|
||||||
.setFileContent(EleCommonUtil.parse(FileUtil.getInputStream(importFile), fileType))
|
|
||||||
.setFileType(fileType)
|
|
||||||
.setFileVersion(FILE_START_VERSION)
|
|
||||||
.setFileSize(importFile.length())
|
|
||||||
.setFilePath(edFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId())
|
|
||||||
.setDataType(EleDataTypeEnum.FILE.code)
|
|
||||||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
|
||||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
|
||||||
this.baseMapper.insert(newEdFileInfo);
|
|
||||||
String destPath = commonService.getPrjRootPath1(DataOwnEnum.SYS_FILE.code) + File.separator + newEdFileInfo.getId();
|
|
||||||
FileUtil.move(importFile, new File(destPath), false);
|
|
||||||
EleCommonUtil.encryptFile(destPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
|
||||||
UserThreadLocal.setSuccessInfo(newEdFileInfo.getParentId(), newEdFileInfo.getId(), "解析导入的工程文件成功,导入的工程名为 {},文件名为 {}", orgName, importFile.getName());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String info = "上传失败,原因 " + e.getMessage();
|
ZipUtil.unzip(tmpZipFile, destDir, Charset.forName("GBK"));
|
||||||
throw new BizException(info, e);
|
}
|
||||||
} finally {
|
|
||||||
FileUtil.del(destDir);
|
File file1 = Objects.requireNonNull(new File(destDir).listFiles())[0];
|
||||||
FileUtil.del(tmpZipFile);
|
FileUtil.rename(file1, mainName, true);
|
||||||
|
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
|
.likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT)
|
||||||
|
.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code));
|
||||||
|
Map<String, String> idNameMap = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, EdFileInfo::getFileName));
|
||||||
|
idNameMap.put(prjId, mainName);
|
||||||
|
Map<String, EdFileInfo> filePathMap = new HashMap<>();
|
||||||
|
for (EdFileInfo edFileInfo : edFileInfos) {
|
||||||
|
StringBuilder names = new StringBuilder();
|
||||||
|
for (String id : edFileInfo.getFilePath().split(MYSQL_FILE_PATH_SPLIT)) {
|
||||||
|
String name = idNameMap.get(id);
|
||||||
|
names.append(MYSQL_FILE_PATH_SPLIT).append(name);
|
||||||
|
}
|
||||||
|
filePathMap.put(names.substring(1), edFileInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<File> files = FileUtil.loopFiles(destDir);
|
||||||
|
String tmpPath = FileUtil.normalize(destDir);
|
||||||
|
for (File importFile : files) {
|
||||||
|
Assert.isTrue(EleCommonUtil.isFileNameValid(importFile.getName()), "文件名称不符合规范");
|
||||||
|
String parentDir = FileUtil.normalize(importFile.getParent());
|
||||||
|
String relativeFilePath = parentDir.replace(tmpPath, "");
|
||||||
|
String fileType = FileUtil.getSuffix(importFile.getName());
|
||||||
|
relativeFilePath = relativeFilePath.startsWith("/") ? relativeFilePath.substring(1) : relativeFilePath;
|
||||||
|
relativeFilePath = relativeFilePath.replace("/", MYSQL_FILE_PATH_SPLIT);
|
||||||
|
EdFileInfo edFileInfo = filePathMap.get(relativeFilePath);
|
||||||
|
Assert.notNull(edFileInfo, "导入的工程与定义的层级结构不一致");
|
||||||
|
String id = edFileInfo.getId();
|
||||||
|
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||||
|
newEdFileInfo.newInit();
|
||||||
|
String fileCode = commonService.createFileCode(id, fileType, FILE_START_VERSION, newEdFileInfo.getFileTime());
|
||||||
|
newEdFileInfo.setParentId(id)
|
||||||
|
.setFileCode(fileCode)
|
||||||
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||||
|
.setDataOwn(DataOwnEnum.SYS_FILE.code)
|
||||||
|
.setFileName(FileUtil.mainName(importFile))
|
||||||
|
.setFileContent(EleCommonUtil.parse(FileUtil.getInputStream(importFile), fileType))
|
||||||
|
.setFileType(fileType)
|
||||||
|
.setFileVersion(FILE_START_VERSION)
|
||||||
|
.setFileSize(importFile.length())
|
||||||
|
.setFilePath(edFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId())
|
||||||
|
.setDataType(EleDataTypeEnum.FILE.code)
|
||||||
|
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||||
|
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||||
|
this.baseMapper.insert(newEdFileInfo);
|
||||||
|
String destPath = commonService.getPrjRootPath1(DataOwnEnum.SYS_FILE.code) + File.separator + newEdFileInfo.getId();
|
||||||
|
FileUtil.move(importFile, new File(destPath), false);
|
||||||
|
EleCommonUtil.encryptFile(destPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||||
|
UserThreadLocal.setSuccessInfo(newEdFileInfo.getParentId(), newEdFileInfo.getId(), "解析导入的工程文件成功,导入的工程名为 {},文件名为 {}", orgName, importFile.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import com.electromagnetic.industry.software.common.enums.*;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||||
|
import com.electromagnetic.industry.software.common.util.EleLog;
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||||
|
|
@ -24,7 +25,6 @@ import com.electromagnetic.industry.software.manage.pojo.resp.ProjectVO;
|
||||||
import com.electromagnetic.industry.software.manage.service.EdPrjService;
|
import com.electromagnetic.industry.software.manage.service.EdPrjService;
|
||||||
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
@ -33,10 +33,11 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
@Service
|
||||||
public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdPrjService {
|
public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdPrjService {
|
||||||
|
|
||||||
|
private final EleLog log = new EleLog(EdPrjServiceImpl.class);
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FileSystemService fileSystemService;
|
private FileSystemService fileSystemService;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,10 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||||
|
|
||||||
import javax.crypto.*;
|
import javax.crypto.*;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -19,6 +21,56 @@ import java.security.Security;
|
||||||
*/
|
*/
|
||||||
public class AESUtils {
|
public class AESUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Discription:[加密]</p>
|
||||||
|
* Created on 2022/07/06 10:52
|
||||||
|
*
|
||||||
|
* @param content 明文 用JSON.toJSONString(Map<String, String> map)转换的json字符串
|
||||||
|
* @param key 加解密规则 访客系统提供key
|
||||||
|
* @return String 密文
|
||||||
|
*/
|
||||||
|
public static String ecodes(String content, String key) {
|
||||||
|
if (content == null || content.length() < 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
KeyGenerator kgen = KeyGenerator.getInstance("AES");
|
||||||
|
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
|
||||||
|
random.setSeed(key.getBytes());
|
||||||
|
kgen.init(128, random);
|
||||||
|
SecretKey secretKey = kgen.generateKey();
|
||||||
|
byte[] enCodeFormat = secretKey.getEncoded();
|
||||||
|
SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES");
|
||||||
|
Cipher cipher = Cipher.getInstance("AES");
|
||||||
|
byte[] byteContent = content.getBytes("utf-8");
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
|
||||||
|
byte[] byteRresult = cipher.doFinal(byteContent);
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
for (int i = 0; i < byteRresult.length; i++) {
|
||||||
|
String hex = Integer.toHexString(byteRresult[i] & 0xFF);
|
||||||
|
if (hex.length() == 1) {
|
||||||
|
hex = '0' + hex;
|
||||||
|
}
|
||||||
|
sb.append(hex.toUpperCase());
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (NoSuchPaddingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (InvalidKeyException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalBlockSizeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (BadPaddingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 前端使用ECB,后端解密方法
|
* 前端使用ECB,后端解密方法
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.symmetric.AES;
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.parse.*;
|
import com.electromagnetic.industry.software.common.parse.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
@ -18,7 +17,6 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public final class EleCommonUtil {
|
public final class EleCommonUtil {
|
||||||
|
|
||||||
private static final Map<String, FileParse> PARSE_MAP = new HashMap<>();
|
private static final Map<String, FileParse> PARSE_MAP = new HashMap<>();
|
||||||
|
|
@ -26,7 +24,8 @@ public final class EleCommonUtil {
|
||||||
private static final String PATTERN = "^[\\u4e00-\\u9fa5a-zA-Z0-9._\\-+]+$";
|
private static final String PATTERN = "^[\\u4e00-\\u9fa5a-zA-Z0-9._\\-+]+$";
|
||||||
private static final String TIME_FORMAT1 = "yyMMddHHmmssSSS";
|
private static final String TIME_FORMAT1 = "yyMMddHHmmssSSS";
|
||||||
// 编译正则表达式
|
// 编译正则表达式
|
||||||
private static final Pattern NAME_PATTERN = Pattern.compile(PATTERN);
|
private static final Pattern pattern = Pattern.compile(PATTERN);
|
||||||
|
private static final EleLog log = new EleLog(EleCommonUtil.class);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
PARSE_MAP.put("doc", new WordParse());
|
PARSE_MAP.put("doc", new WordParse());
|
||||||
|
|
@ -52,7 +51,7 @@ public final class EleCommonUtil {
|
||||||
if (StrUtil.isEmpty(fileFullName) || fileFullName.length() > 32) {
|
if (StrUtil.isEmpty(fileFullName) || fileFullName.length() > 32) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return NAME_PATTERN.matcher(fileFullName).matches();
|
return pattern.matcher(fileFullName).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getNowTimeStr() {
|
public static String getNowTimeStr() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.electromagnetic.industry.software.common.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class EleLog {
|
||||||
|
|
||||||
|
private static final String PLACE_HOLDER = "{}";
|
||||||
|
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
|
public EleLog(Class clazz) {
|
||||||
|
this.logger = LoggerFactory.getLogger(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format(String strPattern, Object... argArray) {
|
||||||
|
if (!StrUtil.isBlank(strPattern) && !StrUtil.isBlank(PLACE_HOLDER) && !ArrayUtil.isEmpty(argArray)) {
|
||||||
|
int strPatternLength = strPattern.length();
|
||||||
|
int placeHolderLength = PLACE_HOLDER.length();
|
||||||
|
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
|
||||||
|
int handledPosition = 0;
|
||||||
|
|
||||||
|
for (int argIndex = 0; argIndex < argArray.length; ++argIndex) {
|
||||||
|
int delimIndex = strPattern.indexOf(PLACE_HOLDER, handledPosition);
|
||||||
|
if (delimIndex == -1) {
|
||||||
|
if (handledPosition == 0) {
|
||||||
|
return strPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
sbuf.append(strPattern, handledPosition, strPatternLength);
|
||||||
|
return sbuf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == '\\') {
|
||||||
|
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == '\\') {
|
||||||
|
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||||
|
sbuf.append(StrUtil.utf8Str(argArray[argIndex]));
|
||||||
|
handledPosition = delimIndex + placeHolderLength;
|
||||||
|
} else {
|
||||||
|
--argIndex;
|
||||||
|
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||||
|
sbuf.append(PLACE_HOLDER.charAt(0));
|
||||||
|
handledPosition = delimIndex + 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sbuf.append(strPattern, handledPosition, delimIndex);
|
||||||
|
sbuf.append(StrUtil.utf8Str(argArray[argIndex]));
|
||||||
|
handledPosition = delimIndex + placeHolderLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sbuf.append(strPattern, handledPosition, strPatternLength);
|
||||||
|
return sbuf.toString();
|
||||||
|
} else {
|
||||||
|
return strPattern;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void info(String msg, Object... args) {
|
||||||
|
logger.info(format(msg, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void debug(String msg, Object... args) {
|
||||||
|
logger.debug(format(msg, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warn(String msg, Object... args) {
|
||||||
|
logger.warn(format(msg, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(String msg, Object... args) {
|
||||||
|
logger.error(format(msg, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(String msg, Throwable e, Object... args) {
|
||||||
|
String info = format(msg, args);
|
||||||
|
logger.error(info, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue