package com.tenwa.loan.handler; import java.math.BigDecimal; import java.util.List; import jbo.loan.LOAN_BILL_INFO; import jbo.loan.LOAN_CONTRACT_INFO; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.awe.dw.handler.impl.CommonHandler; public class LoanContractInfoHandler extends CommonHandler { @Override protected boolean validityCheck(BizObject bo, boolean isInsert) { try{ if(!isInsert){ String id=bo.getAttribute("id").getString(); BigDecimal amount=new BigDecimal( bo.getAttribute("LOAN_AMOUNT").getString()); List bills=JBOFactory.createBizObjectQuery(LOAN_BILL_INFO.CLASS_NAME,"contract_id=:contract_id").setParameter("contract_id",id).getResultList(false); BigDecimal billamount=BigDecimal.ZERO; for(BizObject bill:bills){ billamount=billamount.add(new BigDecimal(bill.getAttribute("LOAN_AMOUNT").getString())); } if(amount.compareTo(billamount)<0){ this.errors="贷款合同金额:"+amount+"小于借款总额:"+billamount+"不能修改"; return false; } } BizObject contract=JBOFactory.createBizObjectQuery(LOAN_CONTRACT_INFO.CLASS_NAME,"CONTRACT_NO=:contractno and id<>'"+bo.getAttribute("id").getString()+"'").setParameter("contractno",bo.getAttribute("contract_no").getString()).getSingleResult(false); if(contract!=null){ this.errors="贷款合同号重复!"; return false; } }catch(Exception e){ e.printStackTrace(); } return true; } }