修改代码

master
bynt 2 years ago
parent 6896f83855
commit 3b51e44f8f

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
@Generated( @Generated(
value = "org.mapstruct.ap.MappingProcessor", value = "org.mapstruct.ap.MappingProcessor",
date = "2022-06-06T14:36:08+0800", date = "2023-02-24T17:22:00+0800",
comments = "version: 1.3.1.Final, compiler: javac, environment: Java 1.8.0_251 (Oracle Corporation)" comments = "version: 1.3.1.Final, compiler: javac, environment: Java 1.8.0_251 (Oracle Corporation)"
) )
@Component @Component

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
@Generated( @Generated(
value = "org.mapstruct.ap.MappingProcessor", value = "org.mapstruct.ap.MappingProcessor",
date = "2022-06-06T14:36:08+0800", date = "2023-02-24T17:22:00+0800",
comments = "version: 1.3.1.Final, compiler: javac, environment: Java 1.8.0_251 (Oracle Corporation)" comments = "version: 1.3.1.Final, compiler: javac, environment: Java 1.8.0_251 (Oracle Corporation)"
) )
@Component @Component

@ -0,0 +1,28 @@
package me.zhengjie.modules.uploadnew.consts;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Enzo
* @date : 2023/2/24
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DecryptionDTO {
@JSONField(name = "requestId")
private String requestId;
@JSONField(name = "cell_phone")
private String cellPhone;
@JSONField(name = "result")
private String result;
@JSONField(name = "reason")
private String reason;
}

@ -0,0 +1,35 @@
package me.zhengjie.modules.uploadnew.consts;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author Enzo
* @date 2023-2-24
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DecryptionJsonContent implements Serializable {
private static final long serialVersionUID = 4871071085514651672L;
@JSONField(name = "request_id")
private String requestId;
@JSONField(name = "cellphone_md5")
private String cellphoneMd5;
}

@ -77,9 +77,9 @@ public class TbUploadFileNew implements Serializable {
@ApiModelProperty(value = "上传日期") @ApiModelProperty(value = "上传日期")
private Timestamp uploadTime; private Timestamp uploadTime;
@Column(name = "is_encryption") @Column(name = "encryption_type")
@ApiModelProperty(value = "加密状态(0-未加密1-加密)") @ApiModelProperty(value = "加密状态(0-未加密1-加密 2-md5加密)")
private Integer isEncryption; private Integer encryptionType;
@Column(name = "file_format") @Column(name = "file_format")
@ApiModelProperty(value = "文件格式") @ApiModelProperty(value = "文件格式")

@ -59,8 +59,8 @@ public class TbUploadFileNewDto implements Serializable {
private Timestamp uploadTime; private Timestamp uploadTime;
/** 加密状态(0-未加密1-加密) */ /** 加密状态(0-未加密1-加密) */
private Integer isEncryption; private Integer encryptionType;
/** 文件格式 */ /** 文件格式 */
private String fileFormat; private String fileFormat;
} }

@ -139,7 +139,7 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
map.put("上传状态(0-失败 1-成功)", tbUploadFileNew.getUploadTag()); map.put("上传状态(0-失败 1-成功)", tbUploadFileNew.getUploadTag());
map.put("文件上传保存路径", tbUploadFileNew.getLocalSavePath()); map.put("文件上传保存路径", tbUploadFileNew.getLocalSavePath());
map.put("上传日期", tbUploadFileNew.getUploadTime()); map.put("上传日期", tbUploadFileNew.getUploadTime());
map.put("加密状态(0-未加密1-加密)", tbUploadFileNew.getIsEncryption()); map.put("加密状态(0-未加密1-加密 2-md5加密)", tbUploadFileNew.getEncryptionType());
map.put("文件格式", tbUploadFileNew.getFileFormat()); map.put("文件格式", tbUploadFileNew.getFileFormat());
list.add(map); list.add(map);
} }
@ -215,7 +215,7 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
/* update by enzo update file upload type date 2021-9-7*/ /* update by enzo update file upload type date 2021-9-7*/
tbUploadFileNew.setUploadType(uploadType); tbUploadFileNew.setUploadType(uploadType);
tbUploadFileNew.setFileFormat(fileFormat); tbUploadFileNew.setFileFormat(fileFormat);
tbUploadFileNew.setIsEncryption(isEcryption); tbUploadFileNew.setEncryptionType(isEcryption);
tbUploadFileNew.setFileCount(count); tbUploadFileNew.setFileCount(count);
tbUploadFileNew.setFileTransSuccessCount(0L); tbUploadFileNew.setFileTransSuccessCount(0L);
tbUploadFileNew.setUploadTag(DOING_TAG); tbUploadFileNew.setUploadTag(DOING_TAG);

@ -2,13 +2,17 @@ package me.zhengjie.modules.uploadnew.task;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.extra.ssh.JschUtil; import cn.hutool.extra.ssh.JschUtil;
import cn.hutool.extra.ssh.Sftp; import cn.hutool.extra.ssh.Sftp;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON; 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;
@ -16,12 +20,16 @@ import com.google.common.collect.Sets;
import com.jcraft.jsch.Session; import com.jcraft.jsch.Session;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.zhengjie.constant.SmsConstant;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.constant.DefaultConstant; import me.zhengjie.modules.constant.DefaultConstant;
import me.zhengjie.modules.constant.FileConstant; import me.zhengjie.modules.constant.FileConstant;
import me.zhengjie.modules.system.domain.sms.dto.ShortLinkUrlDto;
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;
import me.zhengjie.modules.uploadnew.consts.DecryptionDTO;
import me.zhengjie.modules.uploadnew.consts.DecryptionJsonContent;
import me.zhengjie.modules.uploadnew.domain.TbUploadFileNew; 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;
@ -46,10 +54,7 @@ import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static me.zhengjie.modules.upload.consts.SysConst.*; import static me.zhengjie.modules.upload.consts.SysConst.*;
@ -75,21 +80,30 @@ public class SaveToFileNewTask {
@Value(value = "${inter.address}") @Value(value = "${inter.address}")
private String encryptAddress; private String encryptAddress;
@Value(value = "${inter.decryptAddress}")
private String decryptAddress;
/** /**
* - * -
*/ */
private static final String SPLIT_TAG = ","; private static final String SPLIT_TAG = ",";
/**
*
*/
private static final int TEN_NUM = 10;
/** /**
* *
*/ */
private final static int SEND_ENCRYPT_LIMIT = 200; private static final int SEND_ENCRYPT_LIMIT = 200;
/** /**
* *
*/ */
private final static String FORMATE_TIMESTAMP = "yyyyMMddHHmmss"; private static final String FORMATE_TIMESTAMP = "yyyyMMddHHmmss";
/** /**
* *
@ -154,17 +168,29 @@ public class SaveToFileNewTask {
List<String> phoneList = Lists.newArrayList(); List<String> phoneList = Lists.newArrayList();
String fileFormat = tbUploadFileNewDto.getFileFormat(); String fileFormat = tbUploadFileNewDto.getFileFormat();
//根据文件类型进行解析 //根据文件类型进行解析
List<String> listT = fileFormat.contains(FileConstant.TXT_FILE_SUB_NAME) ? List<String> listT = fileFormat.contains(FileConstant.TXT_FILE_SUB_NAME)
TxtUtils.txtParseListVyUrl(filePath) : fileFormat.contains(FileConstant.CSV_FILE_SUB_NAME) ? TxtUtils.txtParseListVyUrl(filePath) :
? ToolExcelUtils.csvParseListByUrl(filePath) : ToolExcelUtils.excelParseListByUrl(filePath); fileFormat.contains(FileConstant.CSV_FILE_SUB_NAME)
? ToolExcelUtils.csvParseListByUrl(filePath)
: ToolExcelUtils.excelParseListByUrl(filePath);
Map<Integer, List<String>> preEncryptNumMap = listT.stream().filter Map<Integer, List<String>> preEncryptNumMap = listT.stream().filter
(phone -> phone.trim().getBytes(StandardCharsets.UTF_8).length == DefaultConstant.ELEVEN_NUMBER) (phone -> StringUtils.isNotBlank(phone.trim())).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);
phoneList = Lists.newArrayList(Sets.newHashSet(list)); if (tbUploadFileNewDto.getEncryptionType() == DefaultConstant.TWO_NUMBER) {
List<String> decryptionList = preEncryptNumMap.get(2 << 4);
List<String> stringList = decryptFile(decryptionList);
if (CollUtil.isNotEmpty(stringList)) {
// 替换集合
phoneList = stringList;
}
}
if (tbUploadFileNewDto.getEncryptionType() == DefaultConstant.ONE_NUMBER) {
List<String> list = preEncryptNumMap.get(PRE_SEND_NUM_LENGTH);
phoneList = Lists.newArrayList(Sets.newHashSet(list));
}
if (CollectionUtil.isNotEmpty(phoneList)) { if (CollectionUtil.isNotEmpty(phoneList)) {
batchSendToEncrypt(filePath, phoneList); batchSendToEncrypt(filePath, phoneList);
} }
@ -195,65 +221,89 @@ public class SaveToFileNewTask {
return DefaultConstant.ZERO_NUMBER; return DefaultConstant.ZERO_NUMBER;
} }
private List<String> decryptFile(List<String> phoneList) {
List<String> stringList = Lists.newArrayList();
List<List<String>> partition = Lists.partition(phoneList, SEND_ENCRYPT_LIMIT);
for (List<String> list : partition) {
// 转换
String decryptStr = StringUtils.listPrintWithSpecialSplit(list, null);
// 构造请求
DecryptionJsonContent build =
DecryptionJsonContent.builder().cellphoneMd5
(decryptStr).requestId(RandomUtil.randomString(TEN_NUM)).build();
// 调用HTTP请求发送数据
DecryptionDTO decryptionDTO = JSONUtil.toBean(HttpUtil.post(decryptAddress, JSON.toJSONString(build)), DecryptionDTO.class);
log.info("================ response as {} ================", JSONUtil.toJsonStr(decryptionDTO));
if (StringUtils.isNotBlank(decryptionDTO.getReason())
&& "success".equals(decryptionDTO.getReason())) {
if (StringUtils.isNotBlank(decryptionDTO.getCellPhone())) {
String[] split = decryptionDTO.getCellPhone().split(StrUtil.COMMA);
if (split.length > 0) {
stringList.addAll(Lists.newArrayList(Arrays.asList(split)));
}
}
}
}
log.info("================ send decryption info result size as {} ================", stringList.size());
return stringList;
}
private void batchSendToEncrypt(String filePath, List<String> fileAllLinesList) { private void batchSendToEncrypt(String filePath, List<String> fileAllLinesList) {
List<List<String>> partition = Lists.partition(fileAllLinesList, SEND_ENCRYPT_LIMIT); List<List<String>> partition = Lists.partition(fileAllLinesList, SEND_ENCRYPT_LIMIT);
partition.forEach( partition.forEach(list -> {
list -> { // 装配需要的Json参数
// 装配需要的Json参数 SendEncryptJsonContent sendEncryptJsonContent = new SendEncryptJsonContent();
SendEncryptJsonContent sendEncryptJsonContent = new SendEncryptJsonContent(); //fixme 还有一个过期时间参数为选填参数,暂时不做设置
//fixme 还有一个过期时间参数为选填参数,暂时不做设置 String tels = StringUtils.listPrintWithSpecialSplit(list, null);
String tels = StringUtils.listPrintWithSpecialSplit(list, null); sendEncryptJsonContent.setTels(Base64.encode(tels));
sendEncryptJsonContent.setTels(Base64.encode(tels)); sendEncryptJsonContent.setReqId(RandomUtil.randomString(10));
sendEncryptJsonContent.setReqId(RandomUtil.randomString(10)); sendEncryptJsonContent.setAppId(encryptAppId);
sendEncryptJsonContent.setAppId(encryptAppId); // 配置 sign
// 配置 sign String signStr = makeSign();
String signStr = makeSign(); if (StringUtils.isBlank(signStr)) {
if (StringUtils.isBlank(signStr)) { log.error("SaveToFileTask|makeSign fail!");
log.error("SaveToFileTask|makeSign fail!"); }
} sendEncryptJsonContent.setSig(signStr);
sendEncryptJsonContent.setSig(signStr); // 组装成JSON
// 组装成JSON String readSendJsonStr = JSON.toJSONString(sendEncryptJsonContent);
String readSendJsonStr = JSON.toJSONString(sendEncryptJsonContent); log.info("SaveToFileTask|batchSendToEncrypt ready send json is : {}", readSendJsonStr);
log.info("SaveToFileTask|batchSendToEncrypt ready send json is : {}", readSendJsonStr); int count = 0;
int count = 0; while (count < 3) {
while (count < 3) { // 调用HTTP请求发送数据
// 调用HTTP请求发送数据 HttpResponse httpResponse = sendPostReq(readSendJsonStr);
HttpResponse httpResponse = sendPostReq(readSendJsonStr); if (httpResponse.isOk() && httpResponse.body().contains("success")) {
if (httpResponse.isOk() && httpResponse.body().contains("success")) { log.info("========== [SaveToFileTask|batchSendToEncrypt request success, response is {} ] ==========", httpResponse.body());
log.info("========== [SaveToFileTask|batchSendToEncrypt request success, response is {} ] ==========", httpResponse.body()); String responseStr = httpResponse.body();
String responseStr = httpResponse.body(); // 解析返回的结果,并写回本地
// 解析返回的结果,并写回本地 if (!parseResponseStr(filePath, responseStr)) {
if (!parseResponseStr(filePath, responseStr)) { log.error("========== [ SaveToFileTask|batchSendToEncrpt parse fail ] ==========");
log.error("========== [ SaveToFileTask|batchSendToEncrpt parse fail ] =========="); booleanTag = false;
booleanTag = false;
}
break;
} else {
count++;
try {
// 重新发送前休眠3秒
Thread.sleep(3_0000);
} catch (InterruptedException e) {
log.error("SaveToFileTask|batchSendToEncrypt sleep ERROR. message is", e.getMessage(), e);
throw new BadRequestException("请求异常!!!");
}
log.error("========== [SaveToFileTask|batchSendToEncrypt request fail, response is {} ] ==========", httpResponse.body());
}
} }
if (count >= 3) { break;
log.error("========== [SaveToFileTask|batchSendToEncrypt update send status fail, url is {} ] ==========", encryptAddress); } else {
count++;
try {
// 重新发送前休眠3秒
Thread.sleep(3_0000);
} catch (InterruptedException e) {
log.error("SaveToFileTask|batchSendToEncrypt sleep ERROR. message is", e.getMessage(), e);
throw new BadRequestException("请求异常!!!");
} }
log.error("========== [SaveToFileTask|batchSendToEncrypt request fail, response is {} ] ==========", httpResponse.body());
} }
); }
if (count >= 3) {
log.error("========== [SaveToFileTask|batchSendToEncrypt update send status fail, url is {} ] ==========", encryptAddress);
}
});
} }
private String makeSign() { private String makeSign() {
String signBuilder = encryptAppId + String signBuilder = encryptAppId + encryptTK + DateUtil.localDateTimeFormat(LocalDateTime.now(), FORMATE_TIMESTAMP);
encryptTK +
DateUtil.localDateTimeFormat(LocalDateTime.now(), FORMATE_TIMESTAMP);
return SecureUtil.md5(signBuilder).toUpperCase(); return SecureUtil.md5(signBuilder).toUpperCase();
} }
@ -266,11 +316,7 @@ public class SaveToFileNewTask {
*/ */
private HttpResponse sendPostReq(String json) { private HttpResponse sendPostReq(String json) {
HttpResponse httpResponse = HttpRequest HttpResponse httpResponse = HttpRequest.post(encryptAddress).header("Content-Type", "application/json;charset=utf-8").body(json).execute();
.post(encryptAddress)
.header("Content-Type", "application/json;charset=utf-8")
.body(json)
.execute();
return httpResponse; return httpResponse;
} }

@ -6,7 +6,7 @@ spring:
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://localhost:3306/eladmin-plat2?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false url: jdbc:log4jdbc:mysql://localhost:3306/eladmin-plat2?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: root username: root
password: '012099' password: y7z7noq2
# 初始连接数 # 初始连接数
initial-size: 5 initial-size: 5
# 最小连接数 # 最小连接数

@ -54,6 +54,7 @@ remote:
file-base-path-mac: ~/file/eladmin/temp/ file-base-path-mac: ~/file/eladmin/temp/
# 发送加密家口需要的一些参数 # 发送加密家口需要的一些参数
inter: inter:
decryptAddress: http://39.174.66.136:8088/v2/Accounts/dabakeji/Calls/Getcellphone
address: https://bd.hzdaba.cn:8085/v3/Accounts/yuyoukeji/BigData/EncryptTel address: https://bd.hzdaba.cn:8085/v3/Accounts/yuyoukeji/BigData/EncryptTel
appid: yuyoukeji appid: yuyoukeji
tk: e3fb7090b4babe44a5113601487af433 tk: e3fb7090b4babe44a5113601487af433

@ -39,19 +39,11 @@ public class CategorizeTest {
return list; return list;
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
List<String> allFile = getAllFile("F:\\新建文件夹\\电销名单", true);
List<String> resultList = Lists.newArrayList(); List<String> strings = ToolExcelUtils.csvParseListByUrl("C:\\Users\\a\\Desktop\\7g4B95v23HQhQ58.csv");
for (String value : allFile) { List<String> stringList = Lists.newArrayList(Sets.newHashSet(strings));
if (value.endsWith("xls") || value.endsWith("xlsx") ){ int i = stringList.size() / 100000;
List<String> strings = ToolExcelUtils.excelParseListByUrl(value);
resultList.addAll(strings);
}
}
List<String> strings = Lists.newArrayList(Sets.newHashSet(resultList));
int i = strings.size() / 600000;
for (int j = 0; j < i + 1; j++) { for (int j = 0; j < i + 1; j++) {
// 通过工具类创建writer // 通过工具类创建writer
@ -60,7 +52,7 @@ public class CategorizeTest {
//todo 设置自动换行(时间) //todo 设置自动换行(时间)
chinaWriter.setColumnWidth(4, 25); chinaWriter.setColumnWidth(4, 25);
// 一次性写出内容,使用默认样式,强制输出标题 // 一次性写出内容,使用默认样式,强制输出标题
chinaWriter.write(strings.subList(j * 600000, Math.min((j + 1) * 600000, strings.size())), true); chinaWriter.write(stringList.subList(j * 100000, Math.min((j + 1) * 100000, strings.size())), true);
// 关闭writer释放内存 // 关闭writer释放内存
chinaWriter.close(); chinaWriter.close();
} }

Loading…
Cancel
Save