兩個List集合判斷取出大集合中不包含小集合的數據, sql加入 in() 條件查詢

	//記錄結算單中沒在付款單中出現的合同號(完全沒有承擔的虧損)--------------------mz---------------------
		String x2="SELECT a.CFCONTRACTNUMBER 合同號,sum(a.FACTUALAMT) 已承擔虧損 FROM T_CAS_ReceivingBillEntry a left join T_CAS_ReceivingBill b ON A.FReceivingBillID = B.FID left join T_BD_Customer c on b.FPAYERID=c.fid where c.fname_l2 ='"+this.prmtcust.getValue().toString()+"' and a.FCONTRACTENTRYSEQ=1 group by a.CFCONTRACTNUMBER";
		IRowSet rsx2 = SQLExecutorFactory.getRemoteInstance(x2).executeSQL();   
		ArrayList<String> yfcontractList = new  ArrayList<String>();
		while(rsx2.next()){
			yfcontractList.add(rsx2.getString("合同號"))	; //應付單裏面承擔的虧損的合同號
		}
		//循環遍歷取出不在付款單集合中的該養戶的結算單中的合同號
		jscontractList.removeAll(yfcontractList); //差異集合, 
	 
		StringBuffer  contacts=new StringBuffer();
        for (int j = 0; j < jscontractList.size(); j++) {
        	contacts.append("'" + jscontractList.get(j) + "',");
		}
          String result = contacts.toString();
          if(!result.equals("")){
        	  String tp = result.substring(result.length() - 1, result.length());
    		  result=result.substring(0, result.length() - 1);
            String mz="select d.fnumber 合同號,a.CFCURRENTBALANCE 虧損金額,a.CFCUSTINFO 信息 from CT_DUC_CalculateStatement a left join T_DUC_BreedingContract d on a.CFCONTRACTNOID=d.fid   left join T_BD_Customer c on a.CFCUSTID=c.fid where c.fname_l2 ='"+this.prmtcust.getValue().toString()+"' and a.CFCURRENTBALANCE<0 and d.fnumber  in (  "+result+"  )  ";
    		IRowSet rsmz = SQLExecutorFactory.getRemoteInstance(mz).executeSQL();
            while(rsmz.next()){
            	IRow irow = this.kdtE2.addRow();
    			irow.getCell("conNo").setValue(rsmz.getString("合同號"));
    			irow.getCell("materiel").setValue("虧損");
    			irow.getCell("qty").setValue("1");
    			irow.getCell("measurementUnit").setValue("筆");
    			irow.getCell("amount").setValue(rsmz.getDouble("虧損金額")*(-1));
            } 
          }
		

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章