app逾期客户or逾期合同查询sql优化,逻辑改变修改

This commit is contained in:
zhangjun 2020-07-10 19:48:19 +08:00
parent c23a49afea
commit 1d5f9bf0ed

View File

@ -227,13 +227,11 @@ public class ApplyArchiveServiceImpl implements ApplyArchiveService{
Map<String, Object> testMap = (Map<String, Object>) MultipartDataUtil
.readRequestParam(request, "UTF-8");
fieldMap = (Map<String, Object>) testMap.get("fieldMap");
String flowunid = fieldMap.get("flowunid") == null ? "" : fieldMap.get("flowunid").toString();
String contractid = fieldMap.get("contractid") == null ? "" : fieldMap.get("contractid").toString();
String distributor = fieldMap.get("distributor_no") == null ? "" : fieldMap.get("distributor_no").toString();
String userId = fieldMap.get("belongorg") == null ? "" : fieldMap.get("belongorg").toString();
String sql = "";
//sql = "select O.FULLNAME,O.mobile,O.SEX,O.WORKCORP,O.WORKADD,ca.fulladdress,O.EMERGENCY_CONTACT_PERSON from CUSTOMER_PERSON_TEMP O left join CUSTOMER_ADDRESS_TEMP ca on O.customerid=ca.customerid and O.flowunid=ca.flowunid where O.flowunid='"+flowunid+"' ";
sql = "SELECT lul.customer_name,cp.mobile,cp.SEX,cp.WORKCORP,cp.WORKADD,ca.fulladdress,cp.EMERGENCY_CONTACT_PERSON,lrp.contract_id,cp.customerid AS customer_id FROM lc_overdue_rent_plan lrp LEFT JOIN lb_contract_info lci ON lci.id=lrp.contract_id LEFT JOIN lb_union_lessee lul ON lul.CONTRACT_ID = lrp.CONTRACT_ID LEFT JOIN CUSTOMER_PERSON cp ON cp.customerid = lul.CUSTOMER_ID LEFT JOIN CUSTOMER_ADDRESS ca ON ca.customerid = cp.customerid WHERE lrp.plan_date < NOW() AND lrp.plan_status='δ½áÇå' AND lci.distributor_id=(SELECT distributor_no FROM distributor_info WHERE orgid='"+userId+"') GROUP BY lrp.contract_id ";
//sql = "select t.FULLNAME,t.mobile,t.SEX,t.WORKCORP,t.WORKADD,t.fulladdress,t.EMERGENCY_CONTACT_PERSON,t.plan_date,sum(t.residue_rent) as residue_rent from (select cp.FULLNAME,cp.mobile,cp.SEX,cp.WORKCORP,cp.WORKADD,ca.fulladdress,cp.EMERGENCY_CONTACT_PERSON,lrp.plan_date,ifnull(sum(lrp.rent),0) - ifnull(sum(lri.rent),0) as residue_rent from lc_rent_plan lrp left join lc_rent_income lri on lri.plan_id=lrp.id left join lb_union_lessee lul on lul.CONTRACT_ID=lrp.CONTRACT_ID left join CUSTOMER_PERSON cp on cp.customerid=lul.CUSTOMER_ID left join CUSTOMER_ADDRESS ca on ca.customerid=cp.customerid WHERE lrp.plan_date <NOW() group by lrp.id) t where t.residue_rent>=0 group by t.plan_date";
sql = "SELECT t.FULLNAME,t.mobile,t.SEX,t.WORKCORP,t.WORKADD,t.fulladdress,t.EMERGENCY_CONTACT_PERSON,t.plan_date,t.residue_rent AS residue_rent FROM (SELECT cp.FULLNAME,cp.mobile,cp.SEX,cp.WORKCORP,cp.WORKADD,ca.fulladdress,cp.EMERGENCY_CONTACT_PERSON,lrp.plan_date,IFNULL(lrp.rent, 0) - SUM(IFNULL(lri.rent, 0)) AS residue_rent FROM lc_rent_plan lrp LEFT JOIN lc_rent_income lri ON lri.plan_id = lrp.id LEFT JOIN lb_contract_info lci ON lrp.contract_id=lci.id LEFT JOIN lb_union_lessee lul ON lul.CONTRACT_ID = lrp.CONTRACT_ID LEFT JOIN CUSTOMER_PERSON cp ON cp.customerid = lul.CUSTOMER_ID LEFT JOIN CUSTOMER_ADDRESS ca ON ca.customerid = cp.customerid WHERE lrp.plan_date < NOW() AND lci.distributor_id='"+distributor+"' GROUP BY lrp.id) t WHERE t.residue_rent > 0 ";
//sql = "SELECT t.FULLNAME,t.mobile,t.SEX,t.WORKCORP,t.WORKADD,t.fulladdress,t.EMERGENCY_CONTACT_PERSON,t.plan_date,t.residue_rent AS residue_rent FROM (SELECT cp.FULLNAME,cp.mobile,cp.SEX,cp.WORKCORP,cp.WORKADD,ca.fulladdress,cp.EMERGENCY_CONTACT_PERSON,lrp.plan_date,IFNULL(lrp.rent, 0) - SUM(IFNULL(lri.rent, 0)) AS residue_rent FROM lc_rent_plan lrp LEFT JOIN lc_rent_income lri ON lri.plan_id = lrp.id LEFT JOIN lb_contract_info lci ON lrp.contract_id=lci.id LEFT JOIN lb_union_lessee lul ON lul.CONTRACT_ID = lrp.CONTRACT_ID LEFT JOIN CUSTOMER_PERSON cp ON cp.customerid = lul.CUSTOMER_ID LEFT JOIN CUSTOMER_ADDRESS ca ON ca.customerid = cp.customerid WHERE lrp.plan_date < NOW() AND lci.distributor_id='"+distributor+"' GROUP BY lrp.id) t WHERE t.residue_rent > 0 ";
List<Map<String, String>> dataList = DataOperatorUtil.getDataBySql(sql);
Map<String, Object> body = new HashMap<String, Object>();
@ -250,7 +248,8 @@ public class ApplyArchiveServiceImpl implements ApplyArchiveService{
fieldMap = (Map<String, Object>) testMap.get("fieldMap");
String customerid = fieldMap.get("customer_id") == null ? "" : fieldMap.get("customer_id").toString();
String sql = "";
sql = "select lrp.contract_id,lci.contract_number,lul.customer_name as lessee_name,lec.frame_number,lec.model,ifnull(sum(lrp.rent),0) - ifnull(sum(lri.rent),0) as residue_rent,lrp.rent,lcc.defaultdueday,lcc.lease_term,lrp.plan_list,lrp.penalty from lb_contract_info lci left join lc_calc_condition lcc on lcc.contract_id = lci.id left join lb_union_lessee lul on lcc.contract_id = lul.contract_id and lul.is_main = 'y' left join lb_equipment_car lec on lec.contract_id = lcc.contract_id left join lc_rent_plan lrp on lrp.contract_id=lci.id left join lc_rent_income lri on lri.plan_id=lrp.id where lul.customer_id='"+customerid+"' group by lrp.contract_id ";
//sql = "select lrp.contract_id,lci.contract_number,lul.customer_name as lessee_name,lec.frame_number,lec.model,ifnull(sum(lrp.rent),0) - ifnull(sum(lri.rent),0) as residue_rent,lrp.rent,lcc.defaultdueday,lcc.lease_term,lrp.plan_list,lrp.penalty from lb_contract_info lci left join lc_calc_condition lcc on lcc.contract_id = lci.id left join lb_union_lessee lul on lcc.contract_id = lul.contract_id and lul.is_main = 'y' left join lb_equipment_car lec on lec.contract_id = lcc.contract_id left join lc_rent_plan lrp on lrp.contract_id=lci.id left join lc_rent_income lri on lri.plan_id=lrp.id where lul.customer_id='"+customerid+"' group by lrp.contract_id ";
sql = "SELECT lrp.contract_id,lrp.contract_plan_number AS contract_number,lul.customer_name AS lessee_name,lec.frame_number,lec.model,lrp.overinterest AS residue_rent,lrp.rent,SUBSTRING(lrp.plan_date,-2) AS defaultdueday,lcc.lease_term,COUNT(*) AS plan_list,SUM(lrp.penalty) AS penalty FROM lc_overdue_rent_plan lrp LEFT JOIN lb_union_lessee lul ON lul.contract_id=lrp.contract_id AND lul.is_main = 'y' LEFT JOIN lb_equipment_car lec ON lec.contract_id = lrp.contract_id LEFT JOIN lc_calc_condition lcc ON lcc.contract_id = lrp.contract_id WHERE plan_status='δ½áÇå' AND lul.customer_id='"+customerid+"' GROUP BY lrp.contract_id ";
List<Map<String, String>> dataList = DataOperatorUtil.getDataBySql(sql);
Map<String, Object> body = new HashMap<String, Object>();