修改代码

master
bynt 2 years ago
parent 6896f83855
commit 3b51e44f8f

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
@Generated(
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)"
)
@Component

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
@Generated(
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)"
)
@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 = "上传日期")
private Timestamp uploadTime;
@Column(name = "is_encryption")
@ApiModelProperty(value = "加密状态(0-未加密1-加密)")
private Integer isEncryption;
@Column(name = "encryption_type")
@ApiModelProperty(value = "加密状态(0-未加密1-加密 2-md5加密)")
private Integer encryptionType;
@Column(name = "file_format")
@ApiModelProperty(value = "文件格式")

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

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

@ -2,13 +2,17 @@ package me.zhengjie.modules.uploadnew.task;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.extra.ssh.JschUtil;
import cn.hutool.extra.ssh.Sftp;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists;
@ -16,12 +20,16 @@ import com.google.common.collect.Sets;
import com.jcraft.jsch.Session;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.constant.SmsConstant;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.constant.DefaultConstant;
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.SendEncryptJsonContent;
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.service.TbUploadFileNewService;
import me.zhengjie.modules.uploadnew.service.dto.TbUploadFileNewDto;
@ -46,10 +54,7 @@ import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import static me.zhengjie.modules.upload.consts.SysConst.*;
@ -75,21 +80,30 @@ public class SaveToFileNewTask {
@Value(value = "${inter.address}")
private String encryptAddress;
@Value(value = "${inter.decryptAddress}")
private String decryptAddress;
/**
* -
*/
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();
String fileFormat = tbUploadFileNewDto.getFileFormat();
//根据文件类型进行解析
List<String> listT = fileFormat.contains(FileConstant.TXT_FILE_SUB_NAME) ?
TxtUtils.txtParseListVyUrl(filePath) : fileFormat.contains(FileConstant.CSV_FILE_SUB_NAME)
? ToolExcelUtils.csvParseListByUrl(filePath) : ToolExcelUtils.excelParseListByUrl(filePath);
List<String> listT = fileFormat.contains(FileConstant.TXT_FILE_SUB_NAME)
? TxtUtils.txtParseListVyUrl(filePath) :
fileFormat.contains(FileConstant.CSV_FILE_SUB_NAME)
? ToolExcelUtils.csvParseListByUrl(filePath)
: ToolExcelUtils.excelParseListByUrl(filePath);
Map<Integer, List<String>> preEncryptNumMap = listT.stream().filter
(phone -> phone.trim().getBytes(StandardCharsets.UTF_8).length == DefaultConstant.ELEVEN_NUMBER)
.collect(Collectors.groupingBy(String::length));
(phone -> StringUtils.isNotBlank(phone.trim())).collect(Collectors.groupingBy(String::length));
if (CollectionUtil.isNotEmpty(preEncryptNumMap)) {
// 分批调用接口进行加密
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)) {
batchSendToEncrypt(filePath, phoneList);
}
@ -195,11 +221,38 @@ public class SaveToFileNewTask {
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) {
List<List<String>> partition = Lists.partition(fileAllLinesList, SEND_ENCRYPT_LIMIT);
partition.forEach(
list -> {
partition.forEach(list -> {
// 装配需要的Json参数
SendEncryptJsonContent sendEncryptJsonContent = new SendEncryptJsonContent();
//fixme 还有一个过期时间参数为选填参数,暂时不做设置
@ -245,15 +298,12 @@ public class SaveToFileNewTask {
log.error("========== [SaveToFileTask|batchSendToEncrypt update send status fail, url is {} ] ==========", encryptAddress);
}
}
);
});
}
private String makeSign() {
String signBuilder = encryptAppId +
encryptTK +
DateUtil.localDateTimeFormat(LocalDateTime.now(), FORMATE_TIMESTAMP);
String signBuilder = encryptAppId + encryptTK + DateUtil.localDateTimeFormat(LocalDateTime.now(), FORMATE_TIMESTAMP);
return SecureUtil.md5(signBuilder).toUpperCase();
}
@ -266,11 +316,7 @@ public class SaveToFileNewTask {
*/
private HttpResponse sendPostReq(String json) {
HttpResponse httpResponse = HttpRequest
.post(encryptAddress)
.header("Content-Type", "application/json;charset=utf-8")
.body(json)
.execute();
HttpResponse httpResponse = HttpRequest.post(encryptAddress).header("Content-Type", "application/json;charset=utf-8").body(json).execute();
return httpResponse;
}

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

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

@ -39,19 +39,11 @@ public class CategorizeTest {
return list;
}
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) {
if (value.endsWith("xls") || value.endsWith("xlsx") ){
List<String> strings = ToolExcelUtils.excelParseListByUrl(value);
resultList.addAll(strings);
}
}
List<String> strings = Lists.newArrayList(Sets.newHashSet(resultList));
int i = strings.size() / 600000;
List<String> stringList = Lists.newArrayList(Sets.newHashSet(strings));
int i = stringList.size() / 100000;
for (int j = 0; j < i + 1; j++) {
// 通过工具类创建writer
@ -60,7 +52,7 @@ public class CategorizeTest {
//todo 设置自动换行(时间)
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释放内存
chinaWriter.close();
}

Loading…
Cancel
Save