public void saveFile() { // 标旧id,标题,借款本金,年化利率,加息利率,还款方式,期数类型,借款期数,标新id,借款人姓名,借款人旧uid,借款人新uid,还款期号,旧本金,新本金,本金差额,旧利息,新利息,利息差额,总差额 StringBuffer fileDispatch = new StringBuffer(); fileDispatch.append( "标旧id,标题,借款本金,年化利率,加息利率,还款方式,期数类型,借款期数,标新id,借款人姓名,借款人旧uid,借款人新uid,还款期号,旧本金,新本金,本金差额,旧利息,新利息,利息差额,总差额"); fileDispatch.append("\n"); StringBuffer sumFileDispatch = new StringBuffer(); sumFileDispatch.append("借款人姓名,借款人旧uid,借款人新uid,总差额"); sumFileDispatch.append("\n"); StringBuffer fileFixPrincipalSqls = new StringBuffer(); StringBuffer fileFixInterestSqls = new StringBuffer(); Map<String, DispatchInfo> sumDispatch = new HashMap<String, DispatchInfo>(); for (DispatchInfo dispatch : dispatchs) { if (dispatch.diffPrincipal > 0) { String fixSql = String.format( "update product.t_repayments set expect_principal=%d+%d where asset_id=%d and borrower_uid=%d and phase=%d and state=0 and expect_principal=%d;", Tool.getMoney(dispatch.oldPrincipal), dispatch.diffPrincipal, dispatch.newAssetId, dispatch.newBorrowerUid, dispatch.phase, Tool.getMoney(dispatch.oldPrincipal)); fileFixPrincipalSqls.append(fixSql); fileFixPrincipalSqls.append("\n"); fixSql = String.format( "update product.t_repayment_%02d set expect_principal=%d+%d where asset_id=%s and borrower_uid=%s and phase=%d and state=0 and expect_principal=%d;", dispatch.newBorrowerUid % 100, Tool.getMoney(dispatch.oldPrincipal), dispatch.diffPrincipal, dispatch.newAssetId, dispatch.newBorrowerUid, dispatch.phase, Tool.getMoney(dispatch.oldPrincipal)); fileFixPrincipalSqls.append(fixSql); fileFixPrincipalSqls.append("\n"); } if (dispatch.diffInterest > 0) { String fixSql = String.format( "update product.t_repayments set expect_interest=%d+%d where asset_id=%d and borrower_uid=%d and phase=%d and state=0 and expect_interest=%d;", Tool.getMoney(dispatch.oldInterest), dispatch.diffInterest, dispatch.newAssetId, dispatch.newBorrowerUid, dispatch.phase, Tool.getMoney(dispatch.oldInterest)); fileFixInterestSqls.append(fixSql); fileFixInterestSqls.append("\n"); fixSql = String.format( "update product.t_repayment_%02d set expect_interest=%d+%d where asset_id=%s and borrower_uid=%s and phase=%d and state=0 and expect_interest=%d;", dispatch.newBorrowerUid % 100, Tool.getMoney(dispatch.oldInterest), dispatch.diffInterest, dispatch.newAssetId, dispatch.newBorrowerUid, dispatch.phase, Tool.getMoney(dispatch.oldInterest)); fileFixInterestSqls.append(fixSql); fileFixInterestSqls.append("\n"); } if (dispatch.diffTotal > 0) { fileDispatch.append(dispatch.getOut()); fileDispatch.append("\n"); DispatchInfo dispatchInfo = sumDispatch.get(String.valueOf(dispatch.newBorrowerUid)); if (null == dispatchInfo) { dispatchInfo = dispatch; sumDispatch.put(String.valueOf(dispatch.newBorrowerUid), dispatch); } else { dispatchInfo.diffTotal += dispatch.diffTotal; } } } try { if (fileDispatch.length() > 0) { File w = new File("D:\\job_projects\\python\\asset_dispatch_money.dat"); FileWriter fw = new FileWriter(w.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(fileDispatch.toString()); bw.close(); } } catch (Exception e) { e.printStackTrace(); System.out.println("保存文件失败-散标还款修复,D:\\job_projects\\python\\asset_dispatch_money.dat"); Tool.exitSystem(); } Iterator<Map.Entry<String, DispatchInfo>> iterator2 = sumDispatch.entrySet().iterator(); while (iterator2.hasNext()) { Map.Entry<String, DispatchInfo> entry = iterator2.next(); DispatchInfo dispatchInfo = entry.getValue(); sumFileDispatch.append(dispatchInfo.getSumOut()); sumFileDispatch.append("\n"); } try { if (sumFileDispatch.length() > 0) { File w = new File("D:\\job_projects\\python\\asset_sum_dispatch_money.dat"); FileWriter fw = new FileWriter(w.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(sumFileDispatch.toString()); bw.close(); } } catch (Exception e) { e.printStackTrace(); System.out.println("保存文件失败-散标还款修复,D:\\job_projects\\python\\asset_sum_dispatch_money.dat"); Tool.exitSystem(); } try { if (fileFixPrincipalSqls.length() > 0) { File w = new File("D:\\job_projects\\python\\asset_fix_principal_sqls.dat"); FileWriter fw = new FileWriter(w.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(fileFixPrincipalSqls.toString()); bw.close(); } } catch (Exception e) { e.printStackTrace(); System.out.println("保存文件失败-散标还款修复,D:\\job_projects\\python\\asset_fix_principal_sqls.dat"); Tool.exitSystem(); } try { if (fileFixInterestSqls.length() > 0) { File w = new File("D:\\job_projects\\python\\asset_fix_interest_sqls.dat"); FileWriter fw = new FileWriter(w.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(fileFixInterestSqls.toString()); bw.close(); } } catch (Exception e) { e.printStackTrace(); System.out.println("保存文件失败-散标还款修复,D:\\job_projects\\python\\asset_fix_interest_sqls.dat"); Tool.exitSystem(); } }