|
|
@@ -12,6 +12,7 @@ import com.zsjz.ai.common.exception.ServerException;
|
|
|
import com.zsjz.ai.common.utils.Z7;
|
|
|
import com.zsjz.ai.module.eds.anno.EdsFields;
|
|
|
import com.zsjz.ai.module.eds.po.*;
|
|
|
+import com.zsjz.ai.module.eds.po.base.EdsBaseAccountCommon;
|
|
|
import com.zsjz.ai.module.eds.po.base.EdsBaseWmChatCommon;
|
|
|
import com.zsjz.ai.module.eds.po.base.EdsBaseWmCommerceCommon;
|
|
|
import com.zsjz.ai.module.eds.po.base.EdsBaseWmEmailCommon;
|
|
|
@@ -36,12 +37,12 @@ import java.util.stream.Collectors;
|
|
|
import static java.util.stream.Collectors.*;
|
|
|
|
|
|
/**
|
|
|
- * bcp 数据包解析与入库工具。
|
|
|
+ * Eds 数据包解析与入库工具。
|
|
|
*
|
|
|
* @author zsjz
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-public class Bcp {
|
|
|
+public class Eds {
|
|
|
|
|
|
/**
|
|
|
* 按类缓存的列名到字段映射
|
|
|
@@ -66,7 +67,7 @@ public class Bcp {
|
|
|
public static final String HEAD_DN = "WA_COMMON_010017";
|
|
|
|
|
|
/**
|
|
|
- * bcp 格式节点标识
|
|
|
+ * Eds 格式节点标识
|
|
|
*/
|
|
|
public static final String FORMAT_BCP_DN = "WA_COMMON_010013";
|
|
|
|
|
|
@@ -132,12 +133,12 @@ public class Bcp {
|
|
|
public static final String CHARSET_IK = "I010039";
|
|
|
|
|
|
/**
|
|
|
- * bcp 数据文件描述节点标识
|
|
|
+ * Eds 数据文件描述节点标识
|
|
|
*/
|
|
|
public static final String BCP_FILE_DN = "WA_COMMON_010014";
|
|
|
|
|
|
/**
|
|
|
- * bcp 文件相对路径键名
|
|
|
+ * Eds 文件相对路径键名
|
|
|
*/
|
|
|
public static final String BCP_FILE_PATH_IK = "H040003";
|
|
|
|
|
|
@@ -147,12 +148,12 @@ public class Bcp {
|
|
|
public static final String BCP_FILE_NAME_IK = "H010020";
|
|
|
|
|
|
/**
|
|
|
- * bcp 文件记录数键名
|
|
|
+ * Eds 文件记录数键名
|
|
|
*/
|
|
|
public static final String BCP_FILE_DATA_SIZE_IK = "I010034";
|
|
|
|
|
|
/**
|
|
|
- * bcp 字段结构节点标识
|
|
|
+ * Eds 字段结构节点标识
|
|
|
*/
|
|
|
public static final String BCP_FIELD_DN = "WA_COMMON_010015";
|
|
|
|
|
|
@@ -187,18 +188,9 @@ public class Bcp {
|
|
|
//private static final List<String> NOT_FIELD = Lists.newArrayList("id", "md5", "caseId");
|
|
|
|
|
|
public static LocalDateTime timestampToLocalDateTime(String timestampStr) {
|
|
|
- LocalDateTime result;
|
|
|
try {
|
|
|
String str = com.zsjz.ai.common.utils.DateUtil.dateStrToLocalDateTime(timestampStr);
|
|
|
return LocalDateTimeUtil.parse(str, "yyyy-MM-dd HH:mm:ss");
|
|
|
- /* if (timestampStr.length() <= 10) {
|
|
|
- result = Instant.ofEpochSecond(Long.parseLong(timestampStr)).atZone(DEFAULT_ZONE).toLocalDateTime();
|
|
|
- } else {
|
|
|
- result = Instant.ofEpochMilli(Long.parseLong(timestampStr)).atZone(DEFAULT_ZONE).toLocalDateTime();
|
|
|
- }
|
|
|
- if (result.isBefore(MIN_DATE) || result.isAfter(MAX_DATE)) {
|
|
|
- result = DEFAULT_DATE;
|
|
|
- }*/
|
|
|
} catch (Exception e) {
|
|
|
log.error("日期{}转换错误", timestampStr, e);
|
|
|
}
|
|
|
@@ -215,7 +207,7 @@ public class Bcp {
|
|
|
* 获取类对应的字段映射,键为数据字段名。
|
|
|
*/
|
|
|
public static Map<String, Field> getFieldMap(Class<?> cls) {
|
|
|
- return Bcp.CACHE_FIELD_MAP.computeIfAbsent(cls, clsKey -> {
|
|
|
+ return Eds.CACHE_FIELD_MAP.computeIfAbsent(cls, clsKey -> {
|
|
|
Field[] declaredFields = ReflectUtil.getFields(clsKey);
|
|
|
Map<String, Field> result = new HashMap<>();
|
|
|
for (Field field : declaredFields) {
|
|
|
@@ -241,16 +233,16 @@ public class Bcp {
|
|
|
* 获取类对应的字段信息(带缓存)
|
|
|
*/
|
|
|
public static EdsEntityFieldInfo getPojoFieldInfo(Class<?> cls) {
|
|
|
- return Bcp.CACHE_POJO_FIELD_INFO_MAP.computeIfAbsent(cls, clsKey -> {
|
|
|
+ return Eds.CACHE_POJO_FIELD_INFO_MAP.computeIfAbsent(cls, clsKey -> {
|
|
|
//取全部字段
|
|
|
- Collection<Field> fields = Bcp.getFieldMap(clsKey).values();
|
|
|
+ Collection<Field> fields = Eds.getFieldMap(clsKey).values();
|
|
|
List<Field> timeArray = new ArrayList<>();
|
|
|
Field deleteStatusField = null;
|
|
|
for (Field field : fields) {
|
|
|
String fieldType = field.getType().getName();
|
|
|
if (fieldType.endsWith(Cnst.LOCAL_DATE_TIME)) {
|
|
|
timeArray.add(field);
|
|
|
- } else if (Bcp.DELETE_STATUS_STR.equals(field.getName())) {
|
|
|
+ } else if (Eds.DELETE_STATUS_STR.equals(field.getName())) {
|
|
|
deleteStatusField = field;
|
|
|
}
|
|
|
}
|
|
|
@@ -278,91 +270,9 @@ public class Bcp {
|
|
|
* @return 是否解压成功
|
|
|
*/
|
|
|
public static boolean unBcpZip(Path zipPath, String destPath, String filename) {
|
|
|
-// String testFileCmd = OsUtils.get7z() + " t " + zipPath.toString();
|
|
|
-// String a = RuntimeUtil.execForStr(testFileCmd);
|
|
|
-// if (a.contains("ERROR")) {
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-//
|
|
|
-// //long unzipBegin = System.currentTimeMillis();
|
|
|
-// String execCmd = OsUtils.get7z() + " x " + zipPath + " -o" + destPath + " -aoa";
|
|
|
-// String b = RuntimeUtil.execForStr(execCmd);
|
|
|
-// return !b.contains("ERROR");
|
|
|
-
|
|
|
return Z7.unZip(zipPath, destPath, "");
|
|
|
-
|
|
|
- /*try (ZipFile zipFile = new ZipFile(zipPath.toFile())) {
|
|
|
- //校验文件是否损坏
|
|
|
- if (!zipFile.isValidZipFile()) {
|
|
|
- //移动清除错误包,并更新错误信息
|
|
|
- moveAndClearErrorZip(zipPath, null, filename, "zip文件已损坏,请重新上传!", "errorDir");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- //校验是否加密
|
|
|
- if (zipFile.isEncrypted()) {
|
|
|
- try {
|
|
|
- // WA压缩包 密码规则同HLHT文档
|
|
|
- String passwordWa = DigestUtil.md5Hex(filename).substring(1, 7).toLowerCase();
|
|
|
- //zipFile = new ZipFile(zipPath.toFile(), passwordWa.toCharArray());
|
|
|
- zipFile.setPassword(passwordWa.toCharArray());
|
|
|
- //执行解压
|
|
|
- zipFile.extractAll(destPath);
|
|
|
- } catch (ZipException e) {
|
|
|
- // JW压缩包 密码规则同pdf文档 互联互通为.zip文件无法解析 todo
|
|
|
- filename = filename.split("\\.")[0] + ".ZIP";
|
|
|
- String passwordJW = DigestUtil.md5Hex(filename).substring(0, 4) + DigestUtil.md5Hex(filename)
|
|
|
- .substring(DigestUtil.md5Hex(filename).length() - 4);
|
|
|
- //zipFile = new ZipFile(zipPath.toFile(), passwordJW.toCharArray());
|
|
|
- zipFile.setPassword(passwordJW.toCharArray());
|
|
|
- //执行解压
|
|
|
- try {
|
|
|
- zipFile.extractAll(destPath);
|
|
|
- } catch (ZipException e1) {
|
|
|
- moveAndClearErrorZip(zipPath, null, filename, "ZIP文件解压失败,请重新上传!", "errorDir");
|
|
|
- log.warn("包:{},解压失败,无法解析", filename);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.info("包:{},无密码解压", filename);
|
|
|
- //执行解压
|
|
|
- ZipUtil.unzip(zipPath.toString(), destPath, Charset.forName("GBK"));
|
|
|
- }
|
|
|
- long unzipEnd = System.currentTimeMillis();
|
|
|
- log.info("包:{},解压完成,耗时(ms):{}.", filename, unzipEnd - unzipBegin);
|
|
|
- } catch (Exception e) {
|
|
|
- moveAndClearErrorZip(zipPath, null, filename, "zip文件解压失败,请重新上传!", "errorDir");
|
|
|
- log.warn("包:{},解压失败,无法解析", filename, e);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- //更新解析进度为6%
|
|
|
- return true;*/
|
|
|
}
|
|
|
|
|
|
- public static void createZip(Path path, String password) {
|
|
|
- Path filePath = path.getParent();
|
|
|
- Path zipFilePath = filePath.resolve(path.getFileName() + DateUtil.today() + ".zip");
|
|
|
- try (ZipFile zipFile = new ZipFile(zipFilePath.toFile(), password.toCharArray())) {
|
|
|
- ZipParameters zipParameters = new ZipParameters();
|
|
|
- zipParameters.setEncryptFiles(true);
|
|
|
- zipParameters.setEncryptionMethod(EncryptionMethod.AES);
|
|
|
- List<File> files = FileUtil.loopFiles(path, 1, null);
|
|
|
- for (File file : files) {
|
|
|
- if (file.isDirectory()) {
|
|
|
- zipFile.addFolder(file, zipParameters);
|
|
|
- } else {
|
|
|
- zipFile.addFile(file, zipParameters);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception ignored) {
|
|
|
-
|
|
|
- }
|
|
|
- //生成加密压缩包
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
public static boolean isExistXml(Path indexXmlPathWa) {
|
|
|
return !Files.exists(indexXmlPathWa);
|
|
|
}
|
|
|
@@ -377,10 +287,6 @@ public class Bcp {
|
|
|
*/
|
|
|
public static void moveAndClearErrorZip(Path zipPath, String extractDir, String filename, String errorMessage, String errorDir) {
|
|
|
try {
|
|
|
- //更新错误信息
|
|
|
- //updateErrorMessage(importList, errorMessage);
|
|
|
- //将异常zip包移动到异常目录
|
|
|
- // moveErrorZip(zipPath, filename, errorDir);
|
|
|
if (extractDir != null) {
|
|
|
//删除解压产物
|
|
|
FileUtil.del(extractDir);
|
|
|
@@ -408,12 +314,7 @@ public class Bcp {
|
|
|
.map(data -> (EdsBaseWmChatCommon) data)
|
|
|
.filter(data -> data.getContactAccountType() != null && data.getAccount() != null)
|
|
|
.collect(groupingBy(EdsBaseWmChatCommon::getContactAccountType,
|
|
|
- groupingBy((e) -> {
|
|
|
-// if (e.getAccount().equals("未知内容") && e.getAccountId() != null && !e.getAccountId().isEmpty()) {
|
|
|
-// return e.getAccountId();
|
|
|
-// }
|
|
|
- return e.getAccount();
|
|
|
- }, mapping(data -> (Object) data, toList()))));
|
|
|
+ groupingBy(EdsBaseAccountCommon::getAccount, mapping(data -> (Object) data, toList()))));
|
|
|
}
|
|
|
|
|
|
//电子邮件类按工具类型与账号分组
|
|
|
@@ -438,12 +339,7 @@ public class Bcp {
|
|
|
return dataList.stream()
|
|
|
.map(data -> (EdsBaseWmCommerceCommon) data)
|
|
|
.filter(data -> data.getNetworkApp() != null && (data.getAccount() != null || data.getAccountId() != null))
|
|
|
- .collect(groupingBy(EdsBaseWmCommerceCommon::getNetworkApp, groupingBy((e) -> {
|
|
|
-// if (e.getAccount().equals("未知内容") && e.getAccountId() != null && !e.getAccountId().isEmpty()) {
|
|
|
-// return e.getAccountId();
|
|
|
-// }
|
|
|
- return e.getAccount();
|
|
|
- }, mapping(data -> (Object) data, toList()))));
|
|
|
+ .collect(groupingBy(EdsBaseWmCommerceCommon::getNetworkApp, groupingBy(EdsBaseAccountCommon::getAccount, mapping(data -> (Object) data, toList()))));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -473,10 +369,7 @@ public class Bcp {
|
|
|
Map<String, Map<String, List<Object>>> groupByAppTypeAccount) {
|
|
|
return groupByAppTypeAccount.entrySet().stream()
|
|
|
.flatMap(appTypeEntry ->
|
|
|
- appTypeEntry.getValue().entrySet().stream().map(accountEntry -> {
|
|
|
- EdsDirTreeCount edsDirTreeCount = new EdsDirTreeCount(cid, dirTree, null, null, appTypeEntry.getKey(), accountEntry.getKey());
|
|
|
- return edsDirTreeCount;
|
|
|
- }))
|
|
|
+ appTypeEntry.getValue().keySet().stream().map(s -> new EdsDirTreeCount(cid, dirTree, null, null, appTypeEntry.getKey(), s)))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|