Commit 55216521 authored by 郝彦辉's avatar 郝彦辉

手动筛选需要报送的

parent a3929ab4
...@@ -305,4 +305,14 @@ public class ExZhuDaiBaiHangReSendController { ...@@ -305,4 +305,14 @@ public class ExZhuDaiBaiHangReSendController {
return "syn_plan_by_CreatedAt任务调度失败,参数错误"; return "syn_plan_by_CreatedAt任务调度失败,参数错误";
} }
} }
@RequestMapping("/manual/d3CheckToJson")
public String d3CheckToJson(String p3,String secretKey, String filePath){
if(manualToolService.checkSecretKey(p3,secretKey)){
baiHangZhuDaiService.d3CheckToJson(filePath);
return "d3CheckToJson任务调度完成";
}else{
return "d3CheckToJson任务调度失败,参数错误";
}
}
} }
...@@ -4,6 +4,7 @@ import lombok.Data; ...@@ -4,6 +4,7 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp;
/** /**
* 还款用户信息 * 还款用户信息
...@@ -40,8 +41,8 @@ public class RepaymentLoanInfoLog implements Serializable { ...@@ -40,8 +41,8 @@ public class RepaymentLoanInfoLog implements Serializable {
private Long id; private Long id;
private Integer enable; private Integer enable;
private String createdAt; private Timestamp createdAt;
private String updatedAt; private Timestamp updatedAt;
} }
...@@ -36,6 +36,8 @@ import org.slf4j.LoggerFactory; ...@@ -36,6 +36,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -43,6 +45,9 @@ import javax.annotation.PostConstruct; ...@@ -43,6 +45,9 @@ import javax.annotation.PostConstruct;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.security.PublicKey; import java.security.PublicKey;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
...@@ -122,6 +127,11 @@ public class BaiHangZhuDaiService { ...@@ -122,6 +127,11 @@ public class BaiHangZhuDaiService {
private static AtomicBoolean D2_Stop = new AtomicBoolean(false); private static AtomicBoolean D2_Stop = new AtomicBoolean(false);
private static AtomicBoolean D3_Stop = new AtomicBoolean(false); private static AtomicBoolean D3_Stop = new AtomicBoolean(false);
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
@Autowired
private JdbcTemplate riskDatasourceJdbcTemplate;
@PostConstruct @PostConstruct
public void init(){ public void init(){
...@@ -1838,4 +1848,284 @@ public class BaiHangZhuDaiService { ...@@ -1838,4 +1848,284 @@ public class BaiHangZhuDaiService {
} }
log.info("处理A1结束"); log.info("处理A1结束");
} }
private void wirteFile(String fileName, String jsonStr){
try {
FileUtils.write(new File(fileName), jsonStr, "UTF-8", true);
} catch (IOException e) {
log.error("文件写入数据异常, fileName: {} , jsonStr: {} ", fileName, jsonStr, e);
}
}
@Async
public String d3CheckToJson(String filePath) {
//写入文件的路径和前缀
String writeFilePath = "/home/quant_group/baihang-report/data/tmp";
String file_= "result";
if(filePath.lastIndexOf("/")!=-1){//linux
writeFilePath = filePath.substring(0,filePath.lastIndexOf("/")) + "/check";
file_ = filePath.substring(filePath.lastIndexOf("/"), filePath.lastIndexOf("."));
}else{//windows
writeFilePath = filePath.substring(0,filePath.lastIndexOf("\\")) + "\\check";
file_ = filePath.substring(filePath.lastIndexOf("\\"), filePath.lastIndexOf("."));
}
long starUtc = System.currentTimeMillis();
List<String> d3InfosList = null;
try {
d3InfosList = FileUtils.readLines(new File(filePath), "utf-8");
} catch (IOException e) {
e.printStackTrace();
}
log.info("读取文件: {} , 大小: {} , 耗时: {} ", filePath, d3InfosList.size(), (System.currentTimeMillis()-starUtc));
int fsize = d3InfosList.size();
String SQL_QUERYD3 = "SELECT * from repayment_loan_info_zhudai d3 where d3.loan_id=? and d3.term_no=? ;";
for(int i=0; i< fsize; i++){
String strJson = d3InfosList.get(i);
try{
if(strJson.length() < 30 ){//#singleLoanRepayInfo
log.warn("筛选文件内容时发现数据错误, 文件: {} , 内容: {} ", filePath, strJson);
continue;
}
RepaymentInfoZhuDai repaymentLoanInfo = new Gson().fromJson(strJson, new TypeToken<RepaymentInfoZhuDai>(){}.getType());
String loanId = repaymentLoanInfo.getLoanId();
int termNo = repaymentLoanInfo.getTermNo();
RepaymentLoanInfoLog logBean = null;
try{
List<RepaymentLoanInfoLog> logBeanList = riskDatasourceJdbcTemplate.query(SQL_QUERYD3, new Object[]{loanId, termNo}, new RowMapper<RepaymentLoanInfoLog>() {
@Override
public RepaymentLoanInfoLog mapRow(ResultSet rs, int rowNum) throws SQLException {
RepaymentLoanInfoLog bean = new RepaymentLoanInfoLog();
bean.setId(rs.getLong("id"));
bean.setRecordId(rs.getString("record_id"));
bean.setReqID(rs.getString("req_id"));
bean.setName(rs.getString("name"));
bean.setPid(rs.getString("pid"));
bean.setMobile(rs.getString("mobile"));
bean.setOpCode(rs.getString("op_code"));
bean.setUploadTs(rs.getString("upload_ts"));
bean.setLoanId(rs.getString("loan_id"));
bean.setTermNo(rs.getInt("term_no"));
bean.setTermStatus(rs.getString("term_status"));
bean.setTargetRepaymentDate(rs.getString("target_repayment_date"));
bean.setRealRepaymentDate(rs.getString("real_repayment_date"));
bean.setPlannedPayment(rs.getBigDecimal("planned_payment"));
bean.setTargetRepayment(rs.getBigDecimal("target_repayment"));
bean.setRealRepayment(rs.getBigDecimal("real_repayment"));
bean.setOverdueAmount(rs.getBigDecimal("overdue_amount"));
bean.setRemainingAmount(rs.getBigDecimal("remaining_amount"));
bean.setOverdueStatus(rs.getString("overdue_status"));
bean.setLoanStatus(rs.getInt("loan_status"));
bean.setStatusConfirmAt(rs.getString("status_confirm_at"));
bean.setEnable(rs.getInt("enable"));
bean.setCreatedAt(rs.getTimestamp("created_at"));
bean.setUpdatedAt(rs.getTimestamp("updated_at"));
return bean;
}
});
if(logBeanList!=null && logBeanList.size() >0){
if(logBeanList.size()==1){
logBean = logBeanList.get(0);
}else{
/* List<RepaymentLoanInfoLog> logBeanList_2 = new ArrayList<>();
for(RepaymentLoanInfoLog log : logBeanList){
if("M".equals(log.getOpCode())){
logBeanList_2.add(log);
}
}
if(logBeanList_2.size()==1){
logBean = logBeanList_2.get(0);
}else {
//M的方式
if(logBeanList_2.size()>1){
Collections.sort(logBeanList_2, new Comparator<RepaymentLoanInfoLog>() {
public int compare(RepaymentLoanInfoLog o1, RepaymentLoanInfoLog o2) {
//按时间进行降序排列
if (o1.getUpdatedAt().getTime() > o2.getUpdatedAt().getTime()) {
return -1;
}
if (o1.getUpdatedAt().getTime() == o2.getUpdatedAt().getTime()) {
return 0;
}
return 1;
}
});
logBean = logBeanList_2.get(0);
}
//A的方式
else{
Collections.sort(logBeanList, new Comparator<RepaymentLoanInfoLog>() {
public int compare(RepaymentLoanInfoLog o1, RepaymentLoanInfoLog o2) {
//按时间进行降序排列
if (o1.getUpdatedAt().getTime() > o2.getUpdatedAt().getTime()) {
return -1;
}
if (o1.getUpdatedAt().getTime() == o2.getUpdatedAt().getTime()) {
return 0;
}
return 1;
}
});
logBean = logBeanList.get(0);
}
}*/
Collections.sort(logBeanList, new Comparator<RepaymentLoanInfoLog>() {
public int compare(RepaymentLoanInfoLog o1, RepaymentLoanInfoLog o2) {
//按时间进行降序排列
if (o1.getUpdatedAt().getTime() > o2.getUpdatedAt().getTime()) {
return -1;
}
if (o1.getUpdatedAt().getTime() == o2.getUpdatedAt().getTime()) {
return 0;
}
return 1;
}
});
logBean = logBeanList.get(0);
}
}
}catch (Exception e){
log.error("根据参数查询报送日志表异常, loanId: {} , termNo: {} ", loanId, termNo, e);
}
if(logBean!=null){
StringBuffer hisStr = new StringBuffer();
hisStr.append(logBean.getLoanId()).append(",");
hisStr.append(logBean.getTermNo()).append(","); //当前还款期数
hisStr.append(logBean.getTermStatus()).append(",");//normal overdue
hisStr.append(logBean.getPlannedPayment()).append(",");
hisStr.append(logBean.getTargetRepayment()).append(",");
hisStr.append(logBean.getRealRepayment()).append(",");
hisStr.append(logBean.getOverdueAmount()).append(",");
hisStr.append(logBean.getRemainingAmount()).append(",");
hisStr.append(logBean.getLoanStatus());
StringBuffer newStr = new StringBuffer();
newStr.append(repaymentLoanInfo.getLoanId()).append(",");
newStr.append(repaymentLoanInfo.getTermNo()).append(","); //当前还款期数
newStr.append(repaymentLoanInfo.getTermStatus()).append(",");//normal overdue
newStr.append(repaymentLoanInfo.getPlannedPayment()).append(",");
newStr.append(repaymentLoanInfo.getTargetRepayment()).append(",");
newStr.append(repaymentLoanInfo.getRealRepayment()).append(",");
newStr.append(repaymentLoanInfo.getOverdueAmount()).append(",");
newStr.append(repaymentLoanInfo.getRemainingAmount()).append(",");
newStr.append(repaymentLoanInfo.getLoanStatus());
String run_lastTime = "";
if("normal".equals(repaymentLoanInfo.getTermStatus().trim()) ){
run_lastTime = repaymentLoanInfo.getRealRepaymentDate();//realRepaymentDate 实际还款时间
}else {
//overdue 逾期时 RealRepaymentDate为空
run_lastTime = repaymentLoanInfo.getStatusConfirmAt();//statusConfirmAt还款状态确认时间
}
LocalDateTime loca_log_uploadTs = LocalDateTime.parse(logBean.getUploadTs()).plusDays(1); //2016-08-23T00:00:00
String uploadTs_2 = loca_log_uploadTs.format(formatter);
if(StringUtils.isNotEmpty(run_lastTime)){
LocalDateTime loca_run_lastTime = LocalDateTime.parse(run_lastTime);
if (loca_run_lastTime.compareTo(loca_log_uploadTs) > 0) {
uploadTs_2 = loca_run_lastTime.format(formatter);
}
}
//相同不用报送
if(hisStr.toString().equals(newStr.toString())){
repaymentLoanInfo.setUploadTs(uploadTs_2);
this.wirteFile(writeFilePath + file_+ "_XT.txt", JSON.toJSONString(repaymentLoanInfo)+"\r\n");
}else {
//不同,需要报送
log.info("查询比较两次报送数据不相同, 修改以M报送, filePath: {} , loanId: {} , termNo: {} , logBean: {} , 数据log_run: {} , ", file_, loanId, termNo, JSON.toJSONString(logBean), hisStr.toString()+"|"+newStr.toString());
repaymentLoanInfo.setUploadTs(uploadTs_2);
repaymentLoanInfo.setOpCode("M");
String log_history_reqID = logBean.getRecordId();
if(log_history_reqID!=null && log_history_reqID.length()>1){
repaymentLoanInfo.setRecordId(log_history_reqID);
this.wirteFile(writeFilePath + file_+ "_M.txt", JSON.toJSONString(repaymentLoanInfo)+"\r\n");
}else{
this.wirteFile(writeFilePath + file_+ "_M_notfind_log_history_reqID.txt", JSON.toJSONString(repaymentLoanInfo)+"\r\n");
}
}
}else{
log.warn("根据参数查询报送日志筛选数据为空, 新增以A报送, filePath: {} , loanId: {} , termNo: {} ", filePath, loanId, termNo);
repaymentLoanInfo.setOpCode("A");
//repaymentLoanInfo.setRecordId(UUID.randomUUID().toString().replaceAll("-", ""));
LocalDateTime nowTime = LocalDateTime.now();
repaymentLoanInfo.setUploadTs(nowTime.format(formatter));
this.wirteFile(writeFilePath + file_+ "_A.txt", JSON.toJSONString(repaymentLoanInfo)+"\r\n");
}
}catch (Exception e){
log.error("筛选文件内容时出现异常, 文件: {} , 内容: {} , 第i: {} ", filePath, strJson, i, e);
}
log.info("内存处理结束, filePath: {} , 第i: {} <<<", filePath, i);
}
return "处理D3数据结束 ";
}
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
/*Timestamp timestamp = new Timestamp((new Date()).getTime());
LocalDateTime nowTime = LocalDateTime.now();
String format = nowTime.format(DateTimeFormatter.ISO_DATE_TIME);
format = nowTime.format(DateTimeFormatter.ISO_LOCAL_DATE);
format = nowTime.format(formatter);
format = nowTime.toString();
System.out.println(format);*/
LocalDateTime loca_log_uploadTs = LocalDateTime.parse("2016-08-23T00:00:00").plusDays(1); //
String uploadTs_2 = loca_log_uploadTs.format(formatter);
String run_lastTime = "2016-08-24T00:00:01";
if(StringUtils.isNotEmpty(run_lastTime)){
LocalDateTime loca_run_lastTime = LocalDateTime.parse(run_lastTime);
if (loca_run_lastTime.compareTo(loca_log_uploadTs) > 0) {
uploadTs_2 = loca_run_lastTime.format(formatter);
}
}
System.out.println(uploadTs_2);
List<RepaymentLoanInfoLog> logBeanList = new ArrayList();
RepaymentLoanInfoLog bean1 = new RepaymentLoanInfoLog();
bean1.setUpdatedAt(Timestamp.valueOf("2011-05-09 11:49:00"));
logBeanList.add(bean1);
RepaymentLoanInfoLog bean2 = new RepaymentLoanInfoLog();
bean2.setUpdatedAt(Timestamp.valueOf("2011-05-09 11:50:00"));
logBeanList.add(bean2);
RepaymentLoanInfoLog bean3 = new RepaymentLoanInfoLog();
bean3.setUpdatedAt(Timestamp.valueOf("2011-05-09 11:48:00"));
logBeanList.add(bean3);
Collections.sort(logBeanList, new Comparator<RepaymentLoanInfoLog>() {
public int compare(RepaymentLoanInfoLog o1, RepaymentLoanInfoLog o2) {
// 按照学生的年龄进行降序排列
if (o1.getUpdatedAt().getTime() > o2.getUpdatedAt().getTime()) {
return -1;
}
if (o1.getUpdatedAt().getTime() == o2.getUpdatedAt().getTime()) {
return 0;
}
return 1;
}
});
System.out.println(JSON.toJSONString(logBeanList));
}
} }
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