diff --git a/src_core/com/tenwa/voucher/CreateVoucherProcess/InsertCustomerHistoryInfo.java b/src_core/com/tenwa/voucher/CreateVoucherProcess/InsertCustomerHistoryInfo.java index abd388245..8f8a79bae 100644 --- a/src_core/com/tenwa/voucher/CreateVoucherProcess/InsertCustomerHistoryInfo.java +++ b/src_core/com/tenwa/voucher/CreateVoucherProcess/InsertCustomerHistoryInfo.java @@ -59,257 +59,286 @@ public class InsertCustomerHistoryInfo { for (int i = 0; i < customerinfo.size(); i++) { Conn con = new Conn(tx); - - customerid = customerinfo.get(i).get("customerid"); certid = customerinfo.get(i).get("certid"); - //获取客户为主承租人订单总数 - String gm_nu = "select count(lul.id) as num from customer_person cp left join lb_union_lessee lul on lul.CUSTOMER_ID = cp.CUSTOMERID where cp.CERTID = '"+certid+"' and lul.IS_MAIN = 'Y' group by cp.CERTID"; - List> gm_number = con.executeQuery(gm_nu); - String gmnum = ""; - if(gm_number.size()>0){ - gmnum = gm_number.get(0).get("num"); - }else { - gmnum = "0"; + //根据证件号获取合同ID + //获取主承租人合同ID + String czrprojid = "select lul.CONTRACT_ID from customer_person cp left join lb_union_lessee lul on cp.CUSTOMERID = lul.CUSTOMER_ID left join lb_contract_info lci on lul.CONTRACT_ID = lci.ID where cp.CERTID = '"+certid+"' and lul.CONTRACT_ID <> '' and lul.IS_MAIN = 'Y' and lci.CONTRACT_STATUS <> '101' and lci.CONTRACT_STATUS <> '104'"; + List> czrproj_id = con.executeQuery(czrprojid); + String czr_proj_id = ""; + for (int j = 0; j < czrproj_id.size(); j++) { + if(czrproj_id.size()==j+1){ + czr_proj_id = czr_proj_id+"'"+czrproj_id.get(j).get("contract_id")+"'"; + }else { + czr_proj_id = czr_proj_id+"'"+czrproj_id.get(j).get("contract_id")+"'"+","; + } } - ///获取客户为主承租融资金额和 - String sum_rz = "select format(sum(nvl(CLEAN_LEASE_MONEY,0)),2) as CLEAN_LEASE_MONEY from customer_person cp left join lb_union_lessee lul on lul.CUSTOMER_ID = cp.CUSTOMERID left join lb_contract_info lci on lci.id = lul.CONTRACT_ID left join lc_calc_condition lcc on lcc.CONTRACT_ID = lul.CONTRACT_ID where cp.CERTID = '"+certid+"' and lul.IS_MAIN = 'Y' and lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <> '104' group by cp.CERTID"; - List> rz = con.executeQuery(sum_rz); - String CLEAN_LEASE_MONEY = ""; - if(rz.size()>0){ - CLEAN_LEASE_MONEY = rz.get(0).get("clean_lease_money"); - }else { - CLEAN_LEASE_MONEY = "0"; - } - //获取客户为主承租已结清合同数 - String jq_contract_num = "select count(lci.ID) as num from customer_person cp left join lb_union_lessee lul on lul.CUSTOMER_ID = cp.CUSTOMERID left join lb_contract_info lci on lci.id = lul.CONTRACT_ID where cp.CERTID = '"+certid+"' and lul.IS_MAIN = 'Y' and lci.CONTRACT_STATUS in ('100','105') group by cp.CERTID"; - List> jq_num = con.executeQuery(jq_contract_num); - String jq_number = ""; - if(jq_num.size()>0){ - jq_number = jq_num.get(0).get("num"); - }else { - jq_number = "0"; - } - //获取客户为主承租未结清合同数 - String wjq_contract_num = "select count(lci.ID) as num from customer_person cp left join lb_union_lessee lul on lul.CUSTOMER_ID = cp.CUSTOMERID left join lb_contract_info lci on lci.id = lul.CONTRACT_ID where cp.CERTID = '"+certid+"' and lul.IS_MAIN = 'Y' and lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <= 100 group by cp.CERTID"; - List> wjq_num = con.executeQuery(wjq_contract_num); - String wjq_number = ""; - if(wjq_num.size()>0){ - wjq_number = wjq_num.get(0).get("num"); - }else { - wjq_number = "0"; - } - //获取客户为主承租车辆总和 - String car_num = "select count(lec.ID) as num from customer_person cp left join lb_union_lessee lul on lul.CUSTOMER_ID = cp.CUSTOMERID left join lb_equipment_car lec on lec.CONTRACT_ID = lul.CONTRACT_ID where cp.CERTID = '"+certid+"' and lul.IS_MAIN = 'Y' and lec.car_attribute = 'head' group by cp.CERTID"; - List> car_number = con.executeQuery(car_num); - String carnumber = ""; - if(car_number.size()>0){ - carnumber = car_number.get(0).get("num"); - }else { - carnumber = "0"; - } - //获取客户为主承租结清车辆总和 - String car_jq_num = "select count(lec.ID) as num from customer_person cp left join lb_union_lessee lul on lul.CUSTOMER_ID = cp.CUSTOMERID left join lb_equipment_car lec on lec.CONTRACT_ID = lul.CONTRACT_ID left join lb_contract_info lci on lci.id = lul.CONTRACT_ID where cp.CERTID = '"+certid+"' and lul.IS_MAIN = 'Y' and lci.CONTRACT_STATUS in ('100','105') and lec.car_attribute = 'head' group by cp.CERTID"; - List> car_jq_number = con.executeQuery(car_jq_num); - String carjqnumber = ""; - if(car_jq_number.size()>0){ - carjqnumber = car_jq_number.get(0).get("num"); - }else { - carjqnumber = "0"; - } - //获取客户为主承租未结清车辆总和 - String car_wjq_num = "select count(lec.ID) as num from customer_person cp left join lb_union_lessee lul on lul.CUSTOMER_ID = cp.CUSTOMERID left join lb_equipment_car lec on lec.CONTRACT_ID = lul.CONTRACT_ID left join lb_contract_info lci on lci.id = lul.CONTRACT_ID where cp.CERTID = '"+certid+"' and lul.IS_MAIN = 'Y' and lci.CONTRACT_STATUS >='31' and lci.CONTRACT_STATUS <= '100' and lec.car_attribute = 'head' group by cp.CERTID"; - List> car_wjq_number = con.executeQuery(car_wjq_num); - String carwjqnumber = ""; - if(car_wjq_number.size()>0){ - carwjqnumber = car_wjq_number.get(0).get("num"); - }else { - carwjqnumber = "0"; - } - //获取客户为主承租剩余租金,逾期租金 - //总实收 - String ssmoney_num = "select sum(nvl(lri.corpus, 0)) as corpus from customer_person cp left join lb_union_lessee lul on lul.CUSTOMER_ID = cp.CUSTOMERID left join lc_rent_income lri on lul.CONTRACT_ID = lri.CONTRACT_ID where cp.CERTID = '"+certid+"' and lul.IS_MAIN = 'Y' group by cp.CERTID"; - List> ssmoney_number = con.executeQuery(ssmoney_num); - BigDecimal ssmoney = new BigDecimal(0); - if(ssmoney_number.size()!=0){ - ssmoney = new BigDecimal(ssmoney_number.get(0).get("corpus")); - } - //剩余本金 - BigDecimal czr_rent_over = new BigDecimal(CLEAN_LEASE_MONEY.replace(",","")).subtract(ssmoney); + //主承租人取值 + String gmnum = "0"; + String CLEAN_LEASE_MONEY = "0"; + String jq_number = "0"; + String wjq_number = "0"; + String carnumber = "0"; + String carjqnumber = "0"; + String carwjqnumber = "0"; + BigDecimal czr_rent_over = new BigDecimal(0); + String czr_yqrent_over = "0"; + if(!"".equals(czr_proj_id)){ + //获取客户为主承租人订单总数 + String gm_nu = "select count(lul.id) as num from lb_union_lessee lul where CONTRACT_ID in ("+czr_proj_id+")"; + List> gm_number = con.executeQuery(gm_nu); + if(gm_number.size()>0){ + gmnum = gm_number.get(0).get("num"); + } + ///获取客户为主承租融资金额和 + String sum_rz = "select format(sum(nvl(CLEAN_LEASE_MONEY,0)),2) as CLEAN_LEASE_MONEY from lb_contract_info lci left join lc_calc_condition lcc on lcc.CONTRACT_ID = lci.ID where lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <> '104' and lci.CONTRACT_STATUS <> '101' and lci.ID in ("+czr_proj_id+")"; + List> rz = con.executeQuery(sum_rz); + if(rz.size()>0){ + CLEAN_LEASE_MONEY = rz.get(0).get("clean_lease_money"); + } + //获取客户为主承租已结清合同数 + String jq_contract_num = "select count(lci.ID) as num from lb_contract_info lci where lci.ID in ("+czr_proj_id+") and lci.CONTRACT_STATUS in ('100','105')"; + List> jq_num = con.executeQuery(jq_contract_num); + if(jq_num.size()>0){ + jq_number = jq_num.get(0).get("num"); + } + //获取客户为主承租未结清合同数 + String wjq_contract_num = "select count(lci.ID) as num from lb_contract_info lci where lci.ID in ("+czr_proj_id+") and lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <= 100"; + List> wjq_num = con.executeQuery(wjq_contract_num); + if(wjq_num.size()>0){ + wjq_number = wjq_num.get(0).get("num"); + } + //获取客户为主承租车辆总和 + String car_num = "select count(lec.ID) as num from lb_union_lessee lul left join lb_equipment_car lec on lec.CONTRACT_ID = lul.CONTRACT_ID where lul.CONTRACT_ID in ("+czr_proj_id+") and lec.car_attribute = 'head'"; + List> car_number = con.executeQuery(car_num); + if(car_number.size()>0){ + carnumber = car_number.get(0).get("num"); + } + //获取客户为主承租结清车辆总和 + String car_jq_num = "select count(lec.ID) as num from lb_contract_info lci left join lb_equipment_car lec on lec.CONTRACT_ID = lci.ID where lci.CONTRACT_STATUS in ('100','105') and lec.car_attribute = 'head' and lci.ID in ("+czr_proj_id+")"; + List> car_jq_number = con.executeQuery(car_jq_num); + if(car_jq_number.size()>0){ + carjqnumber = car_jq_number.get(0).get("num"); + } + //获取客户为主承租未结清车辆总和 + String car_wjq_num = "select count(lec.ID) as num from lb_contract_info lci left join lb_equipment_car lec on lec.CONTRACT_ID = lci.ID where lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <= 100 and lec.car_attribute = 'head' and lci.ID in ("+czr_proj_id+")"; + List> car_wjq_number = con.executeQuery(car_wjq_num); + if(car_wjq_number.size()>0){ + carwjqnumber = car_wjq_number.get(0).get("num"); + } + //获取客户为主承租剩余租金,逾期租金 + //总实收 + String ssmoney_num = "select sum(nvl(lri.corpus, 0)) as corpus from lc_rent_income lri where lri.CONTRACT_ID in ("+czr_proj_id+")"; + List> ssmoney_number = con.executeQuery(ssmoney_num); + BigDecimal ssmoney = new BigDecimal(0); + if(ssmoney_number.get(0).get("corpus")==null || "".equals(ssmoney_number.get(0).get("corpus"))){ + ssmoney = new BigDecimal(ssmoney_number.get(0).get("corpus")); + } + //剩余本金 + czr_rent_over = new BigDecimal(CLEAN_LEASE_MONEY.replace(",","")).subtract(ssmoney); - String yqmoney_num = "select format(sum(nvl(rent_over, 0)), 2) as yqrent_over from customer_person cp left join lb_union_lessee lul on lul.CUSTOMER_ID = cp.CUSTOMERID left join vi_rent_plan vrp on lul.contract_id = vrp.contract_id where cp.CERTID = '"+certid+"' and lul.IS_MAIN = 'Y' and STR_TO_DATE(vrp.plan_date,'%Y/%m/%d') < now() group by cp.CERTID"; + String yqmoney_num = "select sum(lrp.rent - t.RENT) as yqrent_over from \n" + + "lc_rent_plan lrp\n" + + "left join (select CONTRACT_ID,lri.PLAN_LIST,sum(RENT) as RENT from lc_rent_income lri where lri.CONTRACT_ID in ("+czr_proj_id+") group by lri.CONTRACT_ID,lri.PLAN_LIST) t \n" + + " on t.CONTRACT_ID = lrp.CONTRACT_ID and t.PLAN_LIST = lrp.PLAN_LIST \n" + + "where STR_TO_DATE(lrp.plan_date,'%Y/%m/%d') < now()\n" + + "\tand lrp.contract_id in ("+czr_proj_id+")"; List> yqmoney_number = con.executeQuery(yqmoney_num); - String czr_yqrent_over = ""; + czr_yqrent_over = ""; if(yqmoney_number.size()>0){ czr_yqrent_over = yqmoney_number.get(0).get("yqrent_over"); }else { czr_yqrent_over = "0"; } - //获取客户为共同承租人订单总数 - String gt_gm_nu = "select count(cf.id) as num from customer_family cf where cf.Partner_ = 'Y' and cf.certid = '"+certid+"' group by certid"; - List> gt_gm_number = con.executeQuery(gt_gm_nu); - String gtgmnumber = ""; - if(gt_gm_number.size()>0){ - gtgmnumber = gt_gm_number.get(0).get("num"); - }else { - gtgmnumber = "0"; - } - //获取客户为共同承租人融资额和 - String gt_sum_rz = "select format(sum(nvl(CLEAN_LEASE_MONEY,0)),2) as CLEAN_LEASE_MONEY from customer_family cf left join lb_union_lessee lul on cf.PROJECT_ID = lul.PROJECT_ID left join lb_contract_info lci on lci.id = lul.CONTRACT_ID left join lc_calc_condition lcc on lcc.CONTRACT_ID = lul.CONTRACT_ID where cf.certid = '"+certid+"' and cf.Partner_ = 'Y' and lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <> '104' group by cf.certid"; - List> gt_rz = con.executeQuery(gt_sum_rz); - String GT_CLEAN_LEASE_MONEY = ""; - if(gt_rz.size()>0){ - GT_CLEAN_LEASE_MONEY = gt_rz.get(0).get("clean_lease_money"); - }else { - GT_CLEAN_LEASE_MONEY = "0"; - } - //获取客户为共同承租人已结清单数 - String gt_jq_contract_num = "select count(lci.ID) as num from customer_family cf left join lb_union_lessee lul on lul.PROJECT_ID = cf.PROJECT_ID left join lb_contract_info lci on lci.id = lul.CONTRACT_ID where cf.certid = '"+certid+"' and cf.Partner_ = 'Y' and lci.CONTRACT_STATUS in ('100','105') group by cf.certid"; - List> gt_jq_num = con.executeQuery(gt_jq_contract_num); - String gt_jq_number = ""; - if(gt_jq_num.size()>0){ - gt_jq_number = gt_jq_num.get(0).get("num"); - }else { - gt_jq_number = "0"; - } - //获取客户为共同承租人未结清单数 - String gt_wjq_contract_num = "select count(lci.ID) as num from customer_family cf left join lb_union_lessee lul on lul.PROJECT_ID = cf.PROJECT_ID left join lb_contract_info lci on lci.id = lul.CONTRACT_ID where cf.certid = '"+certid+"' and cf.Partner_ = 'Y' and lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <= 100 group by cf.certid"; - List> gt_wjq_num = con.executeQuery(gt_wjq_contract_num); - String gt_wjq_number = ""; - if(gt_wjq_num.size()>0){ - gt_wjq_number = gt_wjq_num.get(0).get("num"); - }else { - gt_wjq_number = "0"; - } - //获取客户为共同承租人车辆总和 - String gt_car_num = "select count(lec.ID) as num from customer_family cf left join lb_union_lessee lul on cf.PROJECT_ID = cf.PROJECT_ID left join lb_equipment_car lec on lec.CONTRACT_ID = lul.CONTRACT_ID where cf.certid = '"+certid+"' and cf.Partner_ = 'Y' and lec.car_attribute = 'head' group by cf.certid"; - List> gt_car_number = con.executeQuery(gt_car_num); - String gtcarnumber = ""; - if(gt_car_number.size()>0){ - gtcarnumber = gt_car_number.get(0).get("num"); - }else { - gtcarnumber = "0"; - } - //获取客户为共同承租人结清车辆总和 - String gt_car_jq_num = "select count(lec.ID) as num from customer_family cf left join lb_union_lessee lul on cf.PROJECT_ID = cf.PROJECT_ID left join lb_equipment_car lec on lec.CONTRACT_ID = lul.CONTRACT_ID left join lb_contract_info lci on lci.id = lul.CONTRACT_ID where cf.certid = '"+certid+"' and cf.Partner_ = 'Y' and lci.CONTRACT_STATUS in ('100','105') and lec.car_attribute = 'head' group by cf.certid"; - List> gt_car_jq_number = con.executeQuery(gt_car_jq_num); - String gtcarjqnumber = ""; - if(gt_car_jq_number.size()>0){ - gtcarjqnumber = gt_car_jq_number.get(0).get("num"); - }else { - gtcarjqnumber = "0"; - } - //获取客户为共同承租人未结清车辆总和 - String gt_car_wjq_num = "select count(lec.ID) as num from customer_family cf left join lb_union_lessee lul on cf.PROJECT_ID = cf.PROJECT_ID left join lb_equipment_car lec on lec.CONTRACT_ID = lul.CONTRACT_ID left join lb_contract_info lci on lci.id = lul.CONTRACT_ID where cf.certid = '"+certid+"' and cf.Partner_ = 'Y' and lci.CONTRACT_STATUS >='31' and lci.CONTRACT_STATUS <= '100' and lec.car_attribute = 'head' group by cf.certid"; - List> gt_car_wjq_number = con.executeQuery(gt_car_wjq_num); - String gtcarwjqnumber = ""; - if(gt_car_wjq_number.size()>0){ - gtcarwjqnumber = gt_car_wjq_number.get(0).get("num"); - }else { - gtcarwjqnumber = "0"; - } - //获取客户为共同承租人剩余租金,罚息 - //总实收 - String ssgt_money_num = "select sum(nvl(corpus, 0)) as corpus from customer_family cf left join lb_union_lessee lul on cf.PROJECT_ID = lul.PROJECT_ID left join lc_rent_income lri on lul.contract_id = lri.contract_id where cf.certid = '"+certid+"' and cf.Partner_ = 'Y' group by cf.certid"; - List> ssgt_money_number = con.executeQuery(ssgt_money_num); - BigDecimal ssgt_money = new BigDecimal(0); - if(ssgt_money_number.size()!=0){ - ssgt_money = new BigDecimal(ssgt_money_number.get(0).get("corpus")); + } - //总剩余本金 - BigDecimal gt_rent_over = new BigDecimal(GT_CLEAN_LEASE_MONEY.replace(",","")).subtract(ssgt_money); - String gt_yqmoney_num = "select format(sum(nvl(rent_over, 0)), 2) as yqrent_over from customer_family cf left join lb_union_lessee lul on cf.PROJECT_ID = lul.PROJECT_ID left join vi_rent_plan vrp on lul.contract_id = vrp.contract_id where cf.certid = '"+certid+"' and cf.Partner_ = 'Y' and STR_TO_DATE(vrp.plan_date,'%Y/%m/%d') < now() group by cf.certid"; + //获取共同承租人合同ID + String gtprojid = "select lci.ID from customer_family cf left join lb_contract_info lci on cf.PROJECT_ID = lci.PROJECT_ID where cf.certid = '"+certid+"' and cf.Partner_ = 'Y' and lci.CONTRACT_STATUS <> '101' and lci.CONTRACT_STATUS <> '104'"; + List> gtproj_id = con.executeQuery(gtprojid); + String gt_proj_id = ""; + for (int j = 0; j < gtproj_id.size(); j++) { + if(gtproj_id.size()==j+1){ + gt_proj_id = gt_proj_id+"'"+gtproj_id.get(j).get("id")+"'"; + }else { + gt_proj_id = gt_proj_id+"'"+gtproj_id.get(j).get("id")+"'"+","; + } + } + //共同承租人取值 + String gtgmnumber = "0"; + String GT_CLEAN_LEASE_MONEY = "0"; + String gt_jq_number = "0"; + String gt_wjq_number = "0"; + String gtcarnumber = "0"; + String gtcarjqnumber = "0"; + String gtcarwjqnumber = "0"; + BigDecimal gt_rent_over = new BigDecimal(0); + String gt_yqrent_over = "0"; + if(!"".equals(gt_proj_id)){ + //获取客户为共同承租人订单总数 + String gt_gm_nu = "select count(lci.ID) as num from lb_contract_info lci where lci.ID in ("+gt_proj_id+")"; + List> gt_gm_number = con.executeQuery(gt_gm_nu); + if(gt_gm_number.size()>0){ + gtgmnumber = gt_gm_number.get(0).get("num"); + } + //获取客户为共同承租人融资额和 + String gt_sum_rz = "select format(sum(nvl(CLEAN_LEASE_MONEY,0)),2) as CLEAN_LEASE_MONEY from lb_contract_info lci left join lc_calc_condition lcc on lcc.CONTRACT_ID = lci.ID where lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <> '104' and lci.CONTRACT_STATUS <> '101' and lci.ID in ("+gt_proj_id+")"; + List> gt_rz = con.executeQuery(gt_sum_rz); + if(gt_rz.size()>0){ + GT_CLEAN_LEASE_MONEY = gt_rz.get(0).get("clean_lease_money"); + } + //获取客户为共同承租人已结清单数 + String gt_jq_contract_num = "select count(lci.ID) as num from lb_contract_info lci where lci.ID in ("+gt_proj_id+") and lci.CONTRACT_STATUS in ('100','105')"; + List> gt_jq_num = con.executeQuery(gt_jq_contract_num); + if(gt_jq_num.size()>0){ + gt_jq_number = gt_jq_num.get(0).get("num"); + } + //获取客户为共同承租人未结清单数 + String gt_wjq_contract_num = "select count(lci.ID) as num from lb_contract_info lci where lci.ID in ("+gt_proj_id+") and lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <= 100"; + List> gt_wjq_num = con.executeQuery(gt_wjq_contract_num); + if(gt_wjq_num.size()>0){ + gt_wjq_number = gt_wjq_num.get(0).get("num"); + } + //获取客户为共同承租人车辆总和 + String gt_car_num = "select count(lec.ID) as num from lb_contract_info lci left join lb_equipment_car lec on lec.CONTRACT_ID = lci.ID where lci.CONTRACT_STATUS in ('100','105') and lec.car_attribute = 'head' and lci.ID in ("+gt_proj_id+")"; + List> gt_car_number = con.executeQuery(gt_car_num); + if(gt_car_number.size()>0){ + gtcarnumber = gt_car_number.get(0).get("num"); + } + //获取客户为共同承租人结清车辆总和 + String gt_car_jq_num = "select count(lci.ID) as num from lb_contract_info lci where lci.ID in ("+gt_proj_id+") and lci.CONTRACT_STATUS in ('100','105')"; + List> gt_car_jq_number = con.executeQuery(gt_car_jq_num); + if(gt_car_jq_number.size()>0){ + gtcarjqnumber = gt_car_jq_number.get(0).get("num"); + } + //获取客户为共同承租人未结清车辆总和 + String gt_car_wjq_num = "select count(lec.ID) as num from lb_contract_info lci left join lb_equipment_car lec on lec.CONTRACT_ID = lci.ID where lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <= 100 and lec.car_attribute = 'head' and lci.ID in ("+gt_proj_id+")"; + List> gt_car_wjq_number = con.executeQuery(gt_car_wjq_num); + if(gt_car_wjq_number.size()>0){ + gtcarwjqnumber = gt_car_wjq_number.get(0).get("num"); + } + //获取客户为共同承租人剩余租金,罚息 + //总实收 + String ssgt_money_num = "select sum(nvl(lri.corpus, 0)) as corpus from lc_rent_income lri where lri.CONTRACT_ID in ("+gt_proj_id+")"; + List> ssgt_money_number = con.executeQuery(ssgt_money_num); + BigDecimal ssgt_money = new BigDecimal(0); + if(ssgt_money_number.get(0).get("corpus")==null||"".equals(ssgt_money_number.get(0).get("corpus"))){ + ssgt_money = new BigDecimal(ssgt_money_number.get(0).get("corpus")); + } + + //总剩余本金 + gt_rent_over = new BigDecimal(GT_CLEAN_LEASE_MONEY.replace(",","")).subtract(ssgt_money); + + String gt_yqmoney_num = "select sum(lrp.rent - t.RENT) as yqrent_over from \n" + + "lc_rent_plan lrp\n" + + "left join (select CONTRACT_ID,lri.PLAN_LIST,sum(RENT) as RENT from lc_rent_income lri where lri.CONTRACT_ID in ("+gt_proj_id+") group by lri.CONTRACT_ID,lri.PLAN_LIST) t \n" + + " on t.CONTRACT_ID = lrp.CONTRACT_ID and t.PLAN_LIST = lrp.PLAN_LIST \n" + + "where STR_TO_DATE(lrp.plan_date,'%Y/%m/%d') < now()\n" + + "\tand lrp.contract_id in ("+gt_proj_id+")"; List> gt_yqmoney_number = con.executeQuery(gt_yqmoney_num); - String gt_yqrent_over = ""; + gt_yqrent_over = ""; if(gt_yqmoney_number.size()>0){ gt_yqrent_over = gt_yqmoney_number.get(0).get("yqrent_over"); }else { gt_yqrent_over = "0"; } - //获取客户为担保人订单总数 - String db_gm_nu = "select count(lgu.id) as num from lb_guarantee_unit lgu where lgu.certid = '"+certid+"' group by lgu.certid"; - List> db_gm_number = con.executeQuery(db_gm_nu); - String dbgmnumber = ""; - if(db_gm_number.size()>0){ - dbgmnumber = db_gm_number.get(0).get("num"); - }else { - dbgmnumber = "0"; - } - //获取客户为担保人融资额和 - String db_sum_rz = "select format(sum(nvl(CLEAN_LEASE_MONEY,0)),2) as CLEAN_LEASE_MONEY from lb_guarantee_unit lgu left join lb_contract_info lci on lci.id = lgu.CONTRACT_ID left join lc_calc_condition lcc on lcc.CONTRACT_ID = lgu.CONTRACT_ID where lgu.certid = '"+certid+"' and lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <> '104' group by lgu.certid"; - List> db_rz = con.executeQuery(db_sum_rz); - String DB_CLEAN_LEASE_MONEY = ""; - if(db_rz.size()>0){ - DB_CLEAN_LEASE_MONEY = db_rz.get(0).get("clean_lease_money"); - }else { - DB_CLEAN_LEASE_MONEY = "0"; - } - //获取客户为担保人已结清单数 - String db_jq_contract_num = "select count(lci.ID) as num from lb_guarantee_unit lgu left join lb_contract_info lci on lci.id = lgu.CONTRACT_ID where lgu.certid = '"+certid+"' and lci.CONTRACT_STATUS in ('100','105') group by lgu.certid"; - List> db_jq_num = con.executeQuery(db_jq_contract_num); - String db_jq_number = ""; - if(db_jq_num.size()>0){ - db_jq_number = db_jq_num.get(0).get("num"); - }else { - db_jq_number = "0"; - } - //获取客户为担保人未结清单数 - String db_wjq_contract_num = "select count(lci.ID) as num from lb_guarantee_unit lgu left join lb_contract_info lci on lci.id = lgu.CONTRACT_ID where lgu.certid = '"+certid+"' and lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <= 100 group by lgu.certid"; - List> db_wjq_num = con.executeQuery(db_wjq_contract_num); - String db_wjq_number = ""; - if(db_wjq_num.size()>0){ - db_wjq_number = db_wjq_num.get(0).get("num"); - }else { - db_wjq_number = "0"; - } - //获取客户为担保人车辆总和 - String db_car_num = "select count(lec.ID) as num from lb_guarantee_unit lgu left join lb_equipment_car lec on lec.CONTRACT_ID = lgu.CONTRACT_ID where lgu.certid = '"+certid+"' and lec.car_attribute = 'head' group by lgu.certid"; - List> db_car_number = con.executeQuery(db_car_num); - String dbcarnumber = ""; - if(db_car_number.size()>0){ - dbcarnumber = db_car_number.get(0).get("num"); - }else { - dbcarnumber = "0"; - } - //获取客户为担保人结清车辆总和 - String db_car_jq_num = "select count(lec.ID) as num from lb_guarantee_unit lgu left join lb_equipment_car lec on lec.CONTRACT_ID = lgu.CONTRACT_ID left join lb_contract_info lci on lci.id = lgu.CONTRACT_ID where lgu.certid = '"+certid+"' and lci.CONTRACT_STATUS in ('100','105') and lec.car_attribute = 'head' group by lgu.certid"; - List> db_car_jq_number = con.executeQuery(db_car_jq_num); - String dbcarjqnumber = ""; - if(db_car_jq_number.size()>0){ - dbcarjqnumber = db_car_jq_number.get(0).get("num"); - }else { - dbcarjqnumber = "0"; - } - //获取客户为担保人结清车辆总和 - String db_car_wjq_num = "select count(lec.ID) as num from lb_guarantee_unit lgu left join lb_equipment_car lec on lec.CONTRACT_ID = lgu.CONTRACT_ID left join lb_contract_info lci on lci.id = lgu.CONTRACT_ID where lgu.certid = '"+certid+"' and lci.CONTRACT_STATUS >='31' and lci.CONTRACT_STATUS <= '100' and lec.car_attribute = 'head' group by lgu.certid"; - List> db_car_wjq_number = con.executeQuery(db_car_wjq_num); - String dbcarwjqnumber = ""; - if(db_car_wjq_number.size()>0){ - dbcarwjqnumber = db_car_wjq_number.get(0).get("num"); - }else { - dbcarwjqnumber = "0"; - } - //获取客户为担保人剩余租金,罚息 - //总实收 - String ssdb_money_num = "select sum(nvl(corpus, 0)) as corpus from lb_guarantee_unit lgu left join lc_rent_income lri on lgu.contract_id = lri.contract_id where lgu.certid = '"+certid+"' group by lgu.certid"; - List> ssdb_money_number = con.executeQuery(ssdb_money_num); - BigDecimal ssdb_money = new BigDecimal(0); - if(ssdb_money_number.size()!=0){ - ssdb_money = new BigDecimal(ssdb_money_number.get(0).get("corpus")); - } - //总剩余本金 - BigDecimal db_rent_over = new BigDecimal(DB_CLEAN_LEASE_MONEY.replace(",","")).subtract(ssdb_money); - String db_yqmoney_num = "select format(sum(nvl(rent_over, 0)), 2) as yqrent_over from lb_guarantee_unit lgu left join vi_rent_plan vrp on lgu.contract_id = vrp.contract_id where lgu.certid = '"+certid+"' and STR_TO_DATE(vrp.plan_date,'%Y/%m/%d') < now() group by lgu.certid"; - List> db_yqmoney_number = con.executeQuery(db_yqmoney_num); - String db_yqrent_over = ""; + } + + + + //获取担保人合同ID + String dbprojid = "select lci.id from lb_guarantee_unit lgu left join lb_contract_info lci on lci.ID = lgu.CONTRACT_ID where lgu.certid = '"+certid+"' and lci.CONTRACT_STATUS <> '101' and lci.CONTRACT_STATUS <> '104'"; + List> dbproj_id = con.executeQuery(dbprojid); + String db_proj_id = ""; + for (int j = 0; j < dbproj_id.size(); j++) { + if(dbproj_id.size()==j+1){ + db_proj_id = db_proj_id+"'"+dbproj_id.get(j).get("id")+"'"; + }else { + db_proj_id = db_proj_id+"'"+dbproj_id.get(j).get("id")+"'"+","; + } + } + //担保人取值 + String dbgmnumber = "0"; + String DB_CLEAN_LEASE_MONEY = "0"; + String db_jq_number = "0"; + String db_wjq_number = "0"; + String dbcarnumber = "0"; + String dbcarjqnumber = "0"; + String dbcarwjqnumber = "0"; + BigDecimal db_rent_over = new BigDecimal(0); + String db_yqrent_over = "0"; + if(!"".equals(db_proj_id)){ + //获取客户为担保人订单总数 + String db_gm_nu = "select count(lci.ID) as num from lb_contract_info lci where lci.ID in ("+db_proj_id+")"; + List> db_gm_number = con.executeQuery(db_gm_nu); + if(db_gm_number.size()>0){ + dbgmnumber = db_gm_number.get(0).get("num"); + } + //获取客户为担保人融资额和 + String db_sum_rz = "select format(sum(nvl(CLEAN_LEASE_MONEY,0)),2) as CLEAN_LEASE_MONEY from lb_contract_info lci left join lc_calc_condition lcc on lcc.CONTRACT_ID = lci.ID where lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <> '104' and lci.CONTRACT_STATUS <> '101' and lci.ID in ("+db_proj_id+")"; + List> db_rz = con.executeQuery(db_sum_rz); + if(db_rz.size()>0){ + DB_CLEAN_LEASE_MONEY = db_rz.get(0).get("clean_lease_money"); + } + //获取客户为担保人已结清单数 + String db_jq_contract_num = "select count(lci.ID) as num from lb_contract_info lci where lci.ID in ("+db_proj_id+") and lci.CONTRACT_STATUS in ('100','105')"; + List> db_jq_num = con.executeQuery(db_jq_contract_num); + if(db_jq_num.size()>0){ + db_jq_number = db_jq_num.get(0).get("num"); + } + //获取客户为担保人未结清单数 + String db_wjq_contract_num = "select count(lci.ID) as num from lb_contract_info lci where lci.ID in ("+db_proj_id+") and lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <= 100"; + List> db_wjq_num = con.executeQuery(db_wjq_contract_num); + if(db_wjq_num.size()>0){ + db_wjq_number = db_wjq_num.get(0).get("num"); + } + //获取客户为担保人车辆总和 + String db_car_num = "select count(lec.ID) as num from lb_contract_info lci left join lb_equipment_car lec on lec.CONTRACT_ID = lci.ID where lci.CONTRACT_STATUS in ('100','105') and lec.car_attribute = 'head' and lci.ID in ("+db_proj_id+")"; + List> db_car_number = con.executeQuery(db_car_num); + if(db_car_number.size()>0){ + dbcarnumber = db_car_number.get(0).get("num"); + } + //获取客户为担保人结清车辆总和 + String db_car_jq_num = "select count(lci.ID) as num from lb_contract_info lci where lci.ID in ("+db_proj_id+") and lci.CONTRACT_STATUS in ('100','105')"; + List> db_car_jq_number = con.executeQuery(db_car_jq_num); + if(db_car_jq_number.size()>0){ + dbcarjqnumber = db_car_jq_number.get(0).get("num"); + } + //获取客户为担保人未结清车辆总和 + String db_car_wjq_num = "select count(lec.ID) as num from lb_contract_info lci left join lb_equipment_car lec on lec.CONTRACT_ID = lci.ID where lci.CONTRACT_STATUS >=31 and lci.CONTRACT_STATUS <= 100 and lec.car_attribute = 'head' and lci.ID in ("+db_proj_id+")"; + List> db_car_wjq_number = con.executeQuery(db_car_wjq_num); + if(db_car_wjq_number.size()>0){ + dbcarwjqnumber = db_car_wjq_number.get(0).get("num"); + } + //获取客户为担保人剩余租金,罚息 + //总实收 + String ssdb_money_num = "select sum(nvl(lri.corpus, 0)) as corpus from lc_rent_income lri where lri.CONTRACT_ID in ("+db_proj_id+")"; + List> ssdb_money_number = con.executeQuery(ssdb_money_num); + BigDecimal ssdb_money = new BigDecimal(0); + if(ssdb_money_number.get(0).get("corpus") != null || "".equals(ssdb_money_number.get(0).get("corpus"))){ + ssdb_money = new BigDecimal(ssdb_money_number.get(0).get("corpus")); + } + //总剩余本金 + db_rent_over = new BigDecimal(DB_CLEAN_LEASE_MONEY.replace(",","")).subtract(ssdb_money); + + String db_yqmoney_num = "select sum(lrp.rent - t.RENT) as yqrent_over from \n" + + "lc_rent_plan lrp\n" + + "left join (select CONTRACT_ID,lri.PLAN_LIST,sum(RENT) as RENT from lc_rent_income lri where lri.CONTRACT_ID in ("+db_proj_id+") group by lri.CONTRACT_ID,lri.PLAN_LIST) t \n" + + " on t.CONTRACT_ID = lrp.CONTRACT_ID and t.PLAN_LIST = lrp.PLAN_LIST \n" + + "where STR_TO_DATE(lrp.plan_date,'%Y/%m/%d') < now()\n" + + "\tand lrp.contract_id in ("+db_proj_id+")"; + List> db_yqmoney_number = con.executeQuery(db_yqmoney_num); + db_yqrent_over = ""; if(db_yqmoney_number.size()>0){ db_yqrent_over = db_yqmoney_number.get(0).get("yqrent_over"); }else { db_yqrent_over = "0"; } + + } + //客户敞口计算 Transaction sqlca = Transaction.createTransaction(tx); BigDecimal exposureMoney = LBBusinessPrimary.obtainExposureMoney(sqlca,flowunid);