Commit e6c20717 authored by 陈宏杰's avatar 陈宏杰

老数据脱敏

parent d665b8dc
...@@ -25,4 +25,14 @@ public class BaiHangDataDisposeController { ...@@ -25,4 +25,14 @@ public class BaiHangDataDisposeController {
} }
} }
@PostMapping("/encryptFieldAndCreateFile")
public String encryptFieldAndCreateFile(String sourceCollectFileName, String sourceFilePath, String targetFilePath){
try {
baiHangDataDisposeService.encryptFieldAndCreateFile(sourceCollectFileName, sourceFilePath, targetFilePath);
return "SUCCESS";
} catch (Exception e){
return e.getMessage();
}
}
} }
...@@ -3,8 +3,11 @@ package cn.quantgroup.report.service.baihang; ...@@ -3,8 +3,11 @@ package cn.quantgroup.report.service.baihang;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import cn.quantgroup.report.domain.baihang.ApplyLoanInfoZhuDai; import cn.quantgroup.report.domain.baihang.ApplyLoanInfoZhuDai;
import cn.quantgroup.report.domain.baihang.LoanInfoZhuDaiVo;
import cn.quantgroup.report.domain.baihang.RepaymentInfoZhuDai;
import cn.quantgroup.report.mapper.master.ApplyLoanInfoZhuDaiMapper; import cn.quantgroup.report.mapper.master.ApplyLoanInfoZhuDaiMapper;
import cn.quantgroup.report.utils.DateUtils; import cn.quantgroup.report.utils.DateUtils;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
...@@ -29,6 +32,8 @@ public class BaiHangDataDisposeService { ...@@ -29,6 +32,8 @@ public class BaiHangDataDisposeService {
private static final String HOST_PATH = "/home/quant_group/reportFile/"; private static final String HOST_PATH = "/home/quant_group/reportFile/";
private static final Integer INITIAL_CAPACITY = 5000;
@Autowired @Autowired
private BaiHangFileReportService baiHangFileReportService; private BaiHangFileReportService baiHangFileReportService;
@Autowired @Autowired
...@@ -74,4 +79,54 @@ public class BaiHangDataDisposeService { ...@@ -74,4 +79,54 @@ public class BaiHangDataDisposeService {
} }
} }
@Async
public void encryptFieldAndCreateFile(String sourceCollectFileName, String sourceFilePath, String targetFilePath) throws Exception{
File collectFile = new File(sourceFilePath + sourceCollectFileName);
File subFile = null;
String dataStr = null,contentStr = null;
BufferedReader bis = null;
LoanInfoZhuDaiVo loanInfoZhuDaiVo = null;
RepaymentInfoZhuDai repaymentInfoZhuDai = null;
List<String> reportList = null;
List<String> fileNameList = FileUtils.readLines(collectFile, "utf-8");
for (String fileName : fileNameList) {
if (StringUtils.isNotBlank(fileName)) {
reportList = new ArrayList<>(INITIAL_CAPACITY);
subFile = new File(sourceFilePath + fileName.replace("-R.cry",".txt"));
bis = new BufferedReader(new FileReader(subFile));
while(null != (dataStr = bis.readLine())) {
if (StringUtils.isNotBlank(dataStr)) {
if (StringUtils.equalsAny(dataStr,"#applyInfo","#singleLoanAccountInfo","#singleLoanRepayInfo")) {
contentStr = dataStr;
} else {
if (dataStr.equals("#applyInfo")) {
} else if(dataStr.equals("#singleLoanAccountInfo")) {
loanInfoZhuDaiVo = JSONUtil.toBean(dataStr, LoanInfoZhuDaiVo.class);
loanInfoZhuDaiVo.setName(baiHangFileReportService.sensitiveFilter(loanInfoZhuDaiVo.getName()));
loanInfoZhuDaiVo.setPid(baiHangFileReportService.sensitiveFilter(loanInfoZhuDaiVo.getPid()));
loanInfoZhuDaiVo.setMobile(baiHangFileReportService.sensitiveFilter(loanInfoZhuDaiVo.getMobile()));
contentStr = JSON.toJSONString(loanInfoZhuDaiVo);
} else if(dataStr.equals("#singleLoanRepayInfo")) {
repaymentInfoZhuDai = JSONUtil.toBean(dataStr, RepaymentInfoZhuDai.class);
repaymentInfoZhuDai.setName(baiHangFileReportService.sensitiveFilter(repaymentInfoZhuDai.getName()));
repaymentInfoZhuDai.setPid(baiHangFileReportService.sensitiveFilter(repaymentInfoZhuDai.getPid()));
repaymentInfoZhuDai.setMobile(baiHangFileReportService.sensitiveFilter(repaymentInfoZhuDai.getMobile()));
contentStr = JSON.toJSONString(repaymentInfoZhuDai);
}
}
reportList.add(contentStr);
}
}
File file = new File(targetFilePath + fileName.replace("-R.cry",".txt"));
FileUtils.writeLines(file,reportList);
if (reportList.size()>1) {
baiHangFileReportService.createFile(file.getAbsolutePath());
}
}
}
IoUtil.close(bis);
log.info("encryptFieldAndCreateFile数据处理完成,集合文件名 {}",sourceCollectFileName);
}
} }
...@@ -502,7 +502,7 @@ public class BaiHangFileReportService { ...@@ -502,7 +502,7 @@ public class BaiHangFileReportService {
* 根据传入的文件路径将加密后的文件生成到 {@link BaiHangFileReportService#HOST_PATH}中 * 根据传入的文件路径将加密后的文件生成到 {@link BaiHangFileReportService#HOST_PATH}中
* @param filePath 需要加密的文件路径 * @param filePath 需要加密的文件路径
*/ */
private static String createFile(String filePath){ public String createFile(String filePath){
String encryptFileName = null; String encryptFileName = null;
log.info("创建加密文件,明文文件路径 {}",filePath); log.info("创建加密文件,明文文件路径 {}",filePath);
File host = new File(HOST_PATH); File host = new File(HOST_PATH);
...@@ -531,7 +531,7 @@ public class BaiHangFileReportService { ...@@ -531,7 +531,7 @@ public class BaiHangFileReportService {
return encryptFileName; return encryptFileName;
} }
private String sensitiveFilter(String s){ public String sensitiveFilter(String s){
if (isDebug){ if (isDebug){
if (StringUtils.isNumeric(s) || s.contains("X") || s.contains("x")){ if (StringUtils.isNumeric(s) || s.contains("X") || s.contains("x")){
return s.substring(0,s.length()-4)+"0000"; return s.substring(0,s.length()-4)+"0000";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment