@ -13,8 +13,10 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONArray ;
import com.google.common.collect.Lists ;
import com.google.common.collect.Lists ;
import com.jcraft.jsch.Session ;
import com.jcraft.jsch.Session ;
import lombok.SneakyThrows ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import me.zhengjie.exception.BadRequestException ;
import me.zhengjie.exception.BadRequestException ;
import me.zhengjie.modules.constant.FileConstant ;
import me.zhengjie.modules.upload.task.model.ResponseEncryptJsonContent ;
import me.zhengjie.modules.upload.task.model.ResponseEncryptJsonContent ;
import me.zhengjie.modules.upload.task.model.SendEncryptJsonContent ;
import me.zhengjie.modules.upload.task.model.SendEncryptJsonContent ;
import me.zhengjie.modules.upload.task.model.SendRemoteUpdateJsonContent ;
import me.zhengjie.modules.upload.task.model.SendRemoteUpdateJsonContent ;
@ -22,6 +24,7 @@ import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew;
import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService ;
import me.zhengjie.modules.uploadnew.service.TbUploadFileNewService ;
import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto ;
import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto ;
import me.zhengjie.modules.uploadnew.util.ExcelUtils ;
import me.zhengjie.modules.uploadnew.util.ExcelUtils ;
import me.zhengjie.modules.uploadnew.util.ToolExcelUtils ;
import me.zhengjie.modules.uploadnew.util.TxtUtils ;
import me.zhengjie.modules.uploadnew.util.TxtUtils ;
import me.zhengjie.utils.ConvertUtil ;
import me.zhengjie.utils.ConvertUtil ;
import me.zhengjie.utils.DateUtil ;
import me.zhengjie.utils.DateUtil ;
@ -105,6 +108,7 @@ public class SaveToFileNewTask {
Long endMilliSecond = LocalDateTime . now ( ) . toInstant ( ZoneOffset . of ( "+8" ) ) . toEpochMilli ( ) ;
Long endMilliSecond = LocalDateTime . now ( ) . toInstant ( ZoneOffset . of ( "+8" ) ) . toEpochMilli ( ) ;
log . info ( "====== [ task start end, task name is {},cost milliSecond is {} ] ======" , "SendBigDataTask" , ConvertUtil . secondToTime ( endMilliSecond - satrtMilliSecond ) ) ;
log . info ( "====== [ task start end, task name is {},cost milliSecond is {} ] ======" , "SendBigDataTask" , ConvertUtil . secondToTime ( endMilliSecond - satrtMilliSecond ) ) ;
}
}
/ * *
/ * *
* 执 行 异 步 任 务
* 执 行 异 步 任 务
*
*
@ -140,39 +144,30 @@ public class SaveToFileNewTask {
*
*
* @param filePath 进 行 操 作 的 每 一 个 文 件 的 路 径
* @param filePath 进 行 操 作 的 每 一 个 文 件 的 路 径
* /
* /
@SneakyThrows
private boolean handleEachFileContent ( String filePath , TbUploadFileNewDto tbUploadFileNewDto ) {
private boolean handleEachFileContent ( String filePath , TbUploadFileNewDto tbUploadFileNewDto ) {
//根据文件类型进行解析
//根据文件类型进行解析
List < String > listT = null ;
List < String > listT = tbUploadFileNewDto . getFileFormat ( ) . contains ( FileConstant . TXT_FILE_SUB_NAME ) ?
try {
TxtUtils . txtParseListVyUrl ( filePath ) :
if ( "excel文件" . equals ( tbUploadFileNewDto . getFileFormat ( ) ) ) {
ToolExcelUtils . excelParseListByUrl ( filePath ) ;
ExcelUtils excelUtils = new ExcelUtils ( ) ;
listT = excelUtils . excelParseListByUrl ( filePath ) ;
} else if ( "txt文件" . equals ( tbUploadFileNewDto . getFileFormat ( ) ) ) {
listT = TxtUtils . txtParseListVyUrl ( filePath ) ;
} else if ( "csv文件" . equals ( tbUploadFileNewDto . getFileFormat ( ) ) ) {
listT = TxtUtils . csvParseListByUrl ( filePath ) ;
}
} catch ( Exception e ) {
log . error ( "SaveToFileTaskNew|batchSendToEncrypt ready send json is : {}" , "" ) ;
throw new BadRequestException ( "解析文件异常" ) ;
}
Map < Integer , List < String > > preEncryptNumMap = listT . stream ( )
Map < Integer , List < String > > preEncryptNumMap = listT . stream ( )
. collect ( Collectors . groupingBy ( String : : length ) ) ;
. collect ( Collectors . groupingBy ( String : : length ) ) ;
if ( CollectionUtil . isNotEmpty ( preEncryptNumMap ) ) {
if ( CollectionUtil . isNotEmpty ( preEncryptNumMap ) ) {
// 分批调用接口进行加密
// 分批调用接口进行加密
List < String > list = preEncryptNumMap . get ( PRE_SEND_NUM_LENGTH ) ;
List < String > list = preEncryptNumMap . get ( PRE_SEND_NUM_LENGTH ) ;
if ( CollectionUtil . isNotEmpty ( list ) ) {
if ( CollectionUtil . isNotEmpty ( list ) ) {
batchSendToEncrypt ( filePath , list ) ;
batchSendToEncrypt ( filePath , list ) ;
}
}
}
}
// modify by q 把剩下不需要加密的内容也写到文件中
// modify by q 把剩下不需要加密的内容也写到文件中
List < String > list = preEncryptNumMap . get ( SEND_NUM_LENGTH ) ;
List < String > list = preEncryptNumMap . get ( SEND_NUM_LENGTH ) ;
if ( CollectionUtil . isNotEmpty ( list ) ) {
if ( CollectionUtil . isNotEmpty ( list ) ) {
writeToFile ( list , filePath + TEMP_FILE_END_STR ) ;
writeToFile ( list , filePath + TEMP_FILE_END_STR ) ;
}
}
// 加入一个全局控制开关
// 加入一个全局控制开关
if ( ! booleanTag ) {
if ( ! booleanTag ) {
return Boolean . FALSE ;
return Boolean . FALSE ;
}
}
@ -183,7 +178,7 @@ public class SaveToFileNewTask {
transFileToOtherServer ( filePath + TEMP_FILE_END_STR ) ;
transFileToOtherServer ( filePath + TEMP_FILE_END_STR ) ;
// 调用远程接口完成一条记录更新
// 调用远程接口完成一条记录更新
boolean sendUpdatePostReqTag = sendUpdatePostReq ( filePath + TEMP_FILE_END_STR , tbUploadFileNewDto ) ;
boolean sendUpdatePostReqTag = sendUpdatePostReq ( filePath + TEMP_FILE_END_STR , tbUploadFileNewDto ) ;
// fixme 这里要修改之前的平台给一个更新接口,然后这边可以用rpc调用,也可以用http,也可以考虑直接消息中间件进行解耦
// fixme 这里要修改之前的平台给一个更新接口,然后这边可以用rpc调用,也可以用http,也可以考虑直接消息中间件进行解耦
if ( delFileTag & & sendUpdatePostReqTag ) {
if ( delFileTag & & sendUpdatePostReqTag ) {
return Boolean . TRUE ;
return Boolean . TRUE ;
@ -288,6 +283,7 @@ public class SaveToFileNewTask {
}
}
return Boolean . FALSE ;
return Boolean . FALSE ;
}
}
private void writeToFile ( List < String > collect , String fullPath ) {
private void writeToFile ( List < String > collect , String fullPath ) {
// 构建存储文件
// 构建存储文件
try {
try {
@ -330,7 +326,7 @@ public class SaveToFileNewTask {
* @param path 单 个 存 储 在 本 地 的 路 径 地 址
* @param path 单 个 存 储 在 本 地 的 路 径 地 址
* @return 返 回 请 求 结 果
* @return 返 回 请 求 结 果
* /
* /
private boolean sendUpdatePostReq ( String path , TbUploadFileNewDto tbUploadFileNewDto ) {
private boolean sendUpdatePostReq ( String path , TbUploadFileNewDto tbUploadFileNewDto ) {
// 构建发送参数
// 构建发送参数
SendRemoteUpdateJsonContent sendRemoteUpdateJsonContent = new SendRemoteUpdateJsonContent ( ) ;
SendRemoteUpdateJsonContent sendRemoteUpdateJsonContent = new SendRemoteUpdateJsonContent ( ) ;