package com.cku.checker; import java.io.IOException; import java.math.BigDecimal; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.apache.commons.lang3.StringUtils; import com.cku.oa.finance.entity.PaymentRecord; import com.cku.oa.statistics.entity.SaPaymentDetail; import com.mysql.jdbc.Connection; import com.mysql.jdbc.PreparedStatement; import com.thinkgem.jeesite.common.utils.DateUtils; import com.thinkgem.jeesite.common.utils.IdGen; /** * 2015年的数据创建 * @author fanhuibin * */ public class CsvChaizhang { /** * @throws SQLException */ public void chipPayment() throws SQLException{ List records = new ArrayList(); Connection conn = getConn(); String sql = "select id,member,catalogId,catalogName,money,createTime from CsvAccountDetail where changeType = 0 and createTime>'2017-01-01 00:00:00' and createTime<'2017-04-30 23:59:59'"; PreparedStatement pstmt = (PreparedStatement)conn.prepareStatement(sql); ResultSet rs = pstmt.executeQuery(); while(rs.next()){ String id = rs.getString(1); String member = rs.getString(2); String catalogId = rs.getString(3); String catalogName = rs.getString(4); String money = rs.getString(5); Date createDate = rs.getDate(6); Map map = new HashMap(); map.put("id", id); map.put("member", member); map.put("catalogId", catalogId); map.put("catalogName", catalogName); map.put("money", money); map.put("createDate", createDate); records.add(map); } Map relations = new HashMap();//所有的收费项的表 String querySql = "select id,CAB,CSV from sa_csv_relation_ship "; PreparedStatement pstmt1 = (PreparedStatement)conn.prepareStatement(querySql); ResultSet rs1 = pstmt1.executeQuery(); while(rs1.next()){ String id = rs1.getString(1); String CAB = rs1.getString(2); String CSV = rs1.getString(3); Map map = new HashMap(); map.put("id", id); map.put("CAB", CAB); map.put("CSV", CSV); relations.put(id,map); } Map cabCharges = new HashMap(); String cabChargeSql = "select id,charging_item_name,price from sa_csv_cab_payment_item "; PreparedStatement pstmt2 = (PreparedStatement)conn.prepareStatement(cabChargeSql); ResultSet rs2 = pstmt2.executeQuery(); while(rs2.next()){ String id = rs2.getString(1); String charging_item_name = rs2.getString(2); String price = rs2.getString(3); Map map = new HashMap(); map.put("id", id); map.put("charging_item_name", charging_item_name); map.put("price", price); cabCharges.put(id,map); } Map csvCharges = new HashMap(); String csvChargeSql = "select id,charging_item_name,price from sa_csv_payment_item "; PreparedStatement pstmt3 = (PreparedStatement)conn.prepareStatement(csvChargeSql); ResultSet rs3 = pstmt3.executeQuery(); while(rs3.next()){ String id = rs3.getString(1); String charging_item_name = rs3.getString(2); String price = rs3.getString(3); Map map = new HashMap(); map.put("id", id); map.put("charging_item_name", charging_item_name); map.put("price", price); csvCharges.put(id,map); } conn.setAutoCommit(false); Statement state = (Statement) conn.createStatement(); //开始做数据 for(Map map:records){ String id = (String) map.get("id"); String member = (String) map.get("member"); String catalogId = (String) map.get("catalogId"); String catalogName = (String) map.get("catelogName"); String money = (String) map.get("money"); Date createDate = (Date) map.get("createDate"); Map relation = relations.get(catalogId); String CAB = ""; String CSV = ""; if(relations.containsKey(catalogId)){ CAB = (String) relation.get("CAB"); CSV = (String) relation.get("CSV"); //建档费 42,43,44,45,70 //A类会员 72,47 //E类会员 49,50,51,52,73 //A类永久犬舍 48,74 if(catalogId.equals("42") ||catalogId.equals("43") ||catalogId.equals("44") ||catalogId.equals("45") ||catalogId.equals("47") ||catalogId.equals("48") ||catalogId.equals("49") ||catalogId.equals("50") ||catalogId.equals("51") ||catalogId.equals("52") ||catalogId.equals("70") ||catalogId.equals("72") ||catalogId.equals("73") ||catalogId.equals("74") ){ continue; } chaizhang(state, member,new BigDecimal(money),createDate,CSV,CAB,csvCharges,cabCharges); }else{ System.out.println(catalogId+"不支持"); } } state.executeBatch(); conn.commit(); } private void chaizhang(Statement state,String member,BigDecimal countFee,Date createDate,String csv,String cab,Map csvCharges,Map cabCharges) throws SQLException{ List list = new ArrayList(); //将CSV的收费结果整理出来 if(StringUtils.isNotEmpty(csv)){ if(csv.contains(",")){ String[] ckuArray = csv.split(","); for(String ckuCharge : ckuArray){ Map map = new HashMap(); map.put("type","csv" ); map.put("id", ckuCharge); list.add(map); } }else{ Map map = new HashMap(); map.put("type", "csv"); map.put("id", csv); list.add(map); } } //将CAB的收费结果整理出来 if(StringUtils.isNotEmpty(cab)){ if(cab.contains(",")){ String[] csvArray = cab.split(","); for(String csvCharge : csvArray){ Map map = new HashMap(); map.put("type", "cab"); map.put("id", csvCharge); list.add(map); } }else{ Map map = new HashMap(); map.put("type", "cab"); map.put("id", cab); list.add(map); } } BigDecimal allItemMoney = new BigDecimal(0); BigDecimal num = new BigDecimal(0); for(int i=0;i0){ num = countFee.divide(allItemMoney,0,BigDecimal.ROUND_UP); }else{ num = new BigDecimal(1); } //分账功能 BigDecimal totalMoney = new BigDecimal(0); for(int i=0;i= 0){ moneyPerMonth = money.divide(new BigDecimal(month),2,BigDecimal.ROUND_HALF_UP); moneyLastMonth = money.subtract(new BigDecimal(month-1).multiply(moneyPerMonth)); pricePerMonth = moneyPerMonth; priceLastMonth = moneyLastMonth; }else{ moneyPerMonth = realMoney.divide(new BigDecimal(month),2,BigDecimal.ROUND_HALF_UP); moneyLastMonth = realMoney.subtract(new BigDecimal(month-1).multiply(moneyPerMonth)); pricePerMonth = money.divide(new BigDecimal(month),2,BigDecimal.ROUND_HALF_UP); priceLastMonth = money.subtract(new BigDecimal(month-1).multiply(pricePerMonth)); } beginDate.setHours(23); beginDate.setMinutes(0); beginDate.setSeconds(0); Calendar ca = Calendar.getInstance(); ca.setTime(beginDate); //存入12个月中 for(int i=0;i