package com.tenwa.reckon.product; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Vector; import jbo.sys.CODE_LIBRARY; import com.amarsoft.app.als.sys.tools.DateUtil; import com.amarsoft.app.awe.config.InitDBType; import com.amarsoft.app.util.ProductParamUtil; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.awe.dw.ASObjectModel; import com.amarsoft.awe.dw.ui.validator.ValidateRule; import com.tenwa.officetempalte.util.FileOperatorUtil; import com.tenwa.quartz.StringUtil; public class ProductCondition { public ProductConditionService prodSer=new ProductConditionService(); /** * 获取测算相关产品配置信息 * @param doTemp * @param productId * @return * @throws Exception */ public String getProductRules(ASObjectModel doTemp,String productId,Vector vali) throws Exception{ doTemp.setDefaultValue("LEASE_AMT_DATE", DateUtil.getToday()); StringBuilder sb=new StringBuilder(); sb.append("{"); sb.append("'fund':"+getProductFundRules(doTemp, productId,vali));//资金配置项 sb.append(",'grace':"+this.getProductGraceRules(doTemp, productId, vali));//宽限期 sb.append(",'method':"+this.getProductSettleRules(doTemp, productId));//计算方式 sb.append("}"); setRentOrRate(doTemp, productId);//租金推算方法 this.getOtherRule(doTemp, productId);//其它配置 this.getProductPenaRules(doTemp, productId);//罚息 this.getProductAdjustRules(doTemp, productId);//调息 this.getGrossRules(doTemp, productId);// //this.setDateRule(doTemp, productId);//日期 this.getCautionRatio(doTemp, productId);//保证金比例 return sb.toString(); } /** * 设置日期 * @param doTemp * @param productId * @throws Exception */ public void setDateRule(ASObjectModel doTemp,String productId) throws Exception{ Map> map=ProductParamUtil.getProductComponentType(productId, "PRD0340"); if(map.containsKey("PaymentDate")){//还款日 Map plandatemap=map.get("PaymentDate"); if(plandatemap.containsKey("HolidayAdjust")){ doTemp.setDefaultValue("PLAN_DATE_HOILDAY", plandatemap.get("HolidayAdjust")); }else{ doTemp.setDefaultValue("PLAN_DATE_HOILDAY", "unchanged"); } if(plandatemap.containsKey("date_proc")){ String s=plandatemap.get("date_proc"); if(s.indexOf("1")>=0){ doTemp.setColumnAttribute("FIRST_PLAN_DATE", "colvisible", "1"); doTemp.setColumnAttribute("FIRST_PLAN_DATE", "colrequired", "1"); } if(s.indexOf("2")>=0){ doTemp.setColumnAttribute("LAST_PLAN_DATE", "colvisible", "1"); doTemp.setColumnAttribute("LAST_PLAN_DATE", "colrequired", "1"); } if(s.indexOf("3")>=0){ doTemp.setColumnAttribute("PLAN_DATE_HOILDAY", "colvisible", "1"); doTemp.setColumnAttribute("PLAN_DATE_HOILDAY", "colrequired", "1"); } } } if(map.containsKey("InterestDate")){//计息日 Map plandatemap=map.get("InterestDate"); if(plandatemap.containsKey("HolidayAdjust")){ doTemp.setDefaultValue("INTEREST_DATE_HOLIDAY", plandatemap.get("HolidayAdjust")); }else{ doTemp.setDefaultValue("INTEREST_DATE_HOLIDAY", "unchanged"); } if(plandatemap.containsKey("date_proc")){ String s=plandatemap.get("date_proc"); if(s.indexOf("1")>=0){ doTemp.setColumnAttribute("FIRST_INTEREST_DATE", "colvisible", "1"); doTemp.setColumnAttribute("FIRST_INTEREST_DATE", "colrequired", "1"); } if(s.indexOf("2")>=0){ doTemp.setColumnAttribute("LAST_INTEREST_DATA", "colvisible", "1"); doTemp.setColumnAttribute("LAST_INTEREST_DATA", "colrequired", "1"); } if(s.indexOf("3")>=0){ doTemp.setColumnAttribute("INTEREST_DATE_HOLIDAY", "colvisible", "1"); doTemp.setColumnAttribute("INTEREST_DATE_HOLIDAY", "colrequired", "1"); } } } if(map.containsKey("RateInfo")){ doTemp.setDefaultValue("RATE", map.get("RateInfo").get("RATE")); doTemp.setDefaultValue("ADDITIONAL_RATE", map.get("RateInfo").get("AdditionalRate")); } } /** * 项目粗利 净融资额 期初付款总计 是否显示 * @param doTemp * @param productId * @throws Exception */ public void getGrossRules(ASObjectModel doTemp,String productId) throws Exception{ Map> map=ProductParamUtil.getProductComponentType(productId, "PRD0330"); if(!map.containsKey("GrossProfit")){ doTemp.setVisible("GROSS_PROFIT",false); } if(!map.containsKey("CleanCreditMoney")){ doTemp.setVisible("CLEAN_CREDIT_MONEY",false); doTemp.setVisible("CLEAN_CREDIT_RATIO",false); } if(!map.containsKey("PeriodBeginPayMoney")){ doTemp.setVisible("FIRST_PAYMENT_TOTAL",false); } } /** * 设置租金推算方法 下拉选项 * @param doTemp * @param productId * @throws Exception */ public void setRentOrRate(ASObjectModel doTemp,String productId) throws Exception{ Map> map=ProductParamUtil.getProductComponentType(productId, "PRD0310"); if(map.containsKey("ROR01")){ if(map.get("ROR01").get("RentOrRate").length()>0){ String[] rule=map.get("ROR01").get("RentOrRate").split(","); String s=""; for(int i=0;i0){s+=",";} s+="'"+rule[i]+"'"; } doTemp.setColumnAttribute("RENT_OR_RATE","coleditsource","jbo.sys.CODE_LIBRARY,itemno,itemname,codeno='rent_or_rate' and itemno in ("+s+") order by sortno"); } } } /** * 获取产品配置的资金项 * @param productId * @return * @throws Exception */ @SuppressWarnings("unchecked") public String getProductFundList(String productId) throws Exception{ Map> map=ProductParamUtil.getProductComponentType(productId, "PRD0315"); String sql="codeno='FeeType' and relativecode is not null and relativecode<>''"; if(InitDBType.DBTYPE.equals("ORACLE")){ sql="codeno='FeeType' and relativecode is not null"; } List feeList=JBOFactory.createBizObjectQuery(CODE_LIBRARY.CLASS_NAME,sql).getResultList(false); String list=""; for(BizObject fee:feeList){ if(map.containsKey(fee.getAttribute("relativecode").getString())){ if(list.length()>0){list+=",";} if("feetype10".equals(fee.getAttribute("itemno").getString())){ continue; } list+=fee.getAttribute("itemno").getString(); if(fee.getAttribute("itemno").getString().equals("feetype2")){ list+=",feetype16,feetype17"; } } } return list; } /** * 获取产品 资金类型 配置 显示页面 * @param doTemp * @param productId * @return * @throws Exception */ @SuppressWarnings("unchecked") public String getProductFundRules(ASObjectModel doTemp,String productId,Vector vali) throws Exception{ StringBuilder sb=new StringBuilder(); sb.append("{"); //获取产品资金项 Map> map=ProductParamUtil.getProductComponentType(productId, "PRD0315"); //获取需要和产品关联的资金项 String sql=""; // if("MYSQL".equals(InitDBType.DBTYPE)){ sql="codeno='FeeType' and relativecode is not null and relativecode<>''"; // }else if("ORACLE".equals(InitDBType.DBTYPE)){ // sql="codeno='FeeType' and relativecode is not null"; //} List feeList=JBOFactory.createBizObjectQuery(CODE_LIBRARY.CLASS_NAME,sql).getResultList(false); String rule=""; for(BizObject fee:feeList){ rule=""; String col=fee.getAttribute("relativecode").getString();//费用项在表中的字段 String colName=fee.getAttribute("itemname").getString();//费用名称 String isFina=fee.getAttribute("attribute2").getString();//是否参与融资 String fina = ProductParamUtil.getProductParameterValue(productId, "PRD0315",col,"FINAN"); String cautionMoneymethod = ProductParamUtil.getProductParameterValue(productId, "PRD0315",col,"DepositStyle"); if(!"".equals(cautionMoneymethod)&&cautionMoneymethod!=null){ doTemp.setDefaultValue("CAUTION_MONEY_METHOD",cautionMoneymethod); } if("Y".equals(fina)){ fina = "finatype02"; }else { fina = "finatype01"; } if(fee.getAttribute("itemno").getString().equals("feetype10")){ rule=prodSer.getEquipRule(doTemp, map,col,vali); }else{ if(map.containsKey(col)){//产品配置了该费用项 rule=prodSer.getFeeRule(doTemp, map, col,colName,vali); doTemp.setDefaultValue(col+"_FINA",fina); }else{ if("FINA".equals(isFina)){ doTemp.setVisible(col+"_"+isFina, false); } doTemp.setVisible(col, false); if(fee.getAttribute("itemno").getString().equals("feetype2")){ doTemp.setVisible("CAUTION_DEDUCTION_MONEY", false); doTemp.setVisible("CAUTION_MONEY_REMAIN", false); doTemp.setVisible("CAUTION_MONEY_METHOD", false); doTemp.setRequired("CAUTION_MONEY_METHOD", false); } if("FINAL_PAYMENT".equals(col)) { doTemp.setVisible(col + "_METHOD", false); doTemp.setRequired(col + "_METHOD", false); } rule=null; } } if(rule!=null){ if(sb.length()>1){sb.append(",");} sb.append("'"+col+"':"+rule+""); } } for(String key:map.keySet()){ if(key.toUpperCase().indexOf("FEETYPE")>=0){ rule=prodSer.getFeeRule(doTemp, map, key,map.get(key).get("colheader"),vali); if(sb.length()>1){sb.append(",");} sb.append("'"+key.toUpperCase()+"':"+rule+""); } } sb.append("}"); return sb.toString(); } /** * 宽限期最大值 * @param doTemp * @param flowunid * @return * @throws Exception */ public String getProductGraceRules(ASObjectModel doTemp,String productId,Vector vali) throws Exception{ Map rule=new HashMap(); //获取产品其它 Map> map=ProductParamUtil.getProductComponentType(productId, "PRD0311"); if(map.isEmpty()){ doTemp.setColumnAttribute("GRACE", "colvisible", "0"); }else if(map.containsKey("LT01")&&map.get("LT01").containsKey("isleaseterm")&&"N".equals(map.get("LT01").get("isleaseterm"))){ doTemp.setColumnAttribute("GRACE", "colvisible", "0"); }else{ if(map.containsKey("LT01")){ String max=StringUtil.nullToString(map.get("LT01").get("leaseterm-MAX")); if(max.length()>0){ rule.put("max",max); String vaildat=this.prodSer.getValidat(max,"宽限期最大"+max+"期","<="); this.prodSer.setColValidat(vali,"GRACE", vaildat); } } } return FileOperatorUtil.getMapToJsonStr(rule); } /** * 设置 第一期还款计划 第二期还款计划 期末余值 是否显示 * @param doTemp * @param productId * @throws Exception */ public void getOtherRule(ASObjectModel doTemp,String productId) throws Exception{ String[] param={"EQUIP_END_VALUE"}; //获取产品其它 Map> map=ProductParamUtil.getProductComponentType(productId, "PRD0311"); for(int i=0;i> map=ProductParamUtil.getProductComponentType(productId, "PRD0308"); if(map.containsKey("PFD01")){//免罚息天数 String day=map.get("PFD01").get("PenaltyFreeDays"); if(day.length()>0){ doTemp.setDefaultValue("FREE_DEFA_INTER_DAY", day); } if("N".equals(map.get("PFD01").get("AllowModify"))){ doTemp.setColumnAttribute("FREE_DEFA_INTER_DAY","colreadonly", "1"); } } if(map.containsKey("PENALTY_RATE_DAY")){//罚息日利率 String rate=map.get("PENALTY_RATE_DAY").get("PENALTY_RATE_DAY"); if(rate.length()>0){ doTemp.setDefaultValue("PENA_RATE", rate); } if("N".equals(map.get("PENALTY_RATE_DAY").get("AllowModify"))){ doTemp.setColumnAttribute("PENA_RATE","colreadonly", "1"); } } } /** * 设置调息规则 * @param doTemp * @param productId * @throws Exception */ public void getProductAdjustRules(ASObjectModel doTemp,String productId) throws Exception{ Map> map=ProductParamUtil.getProductComponentType(productId, "PRD0320"); if(map.containsKey("ADJUST_INTEREST")){ Map rule=map.get("ADJUST_INTEREST"); if("N".equals(rule.get("ISADJUST_INTEREST"))){ doTemp.setColumnAttribute("ADJUST_STYLE","colvisible", "0"); doTemp.setColumnAttribute("ADJUST_TYPE","colvisible", "0"); }else if("Y".equals(rule.get("ISADJUST_INTEREST"))){ doTemp.setColumnAttribute("ADJUST_STYLE","colvisible", "0"); doTemp.setColumnAttribute("ADJUST_TYPE","colvisible", "0"); //调息生效节点 doTemp.setColumnAttribute("ADJUST_STYLE","coleditsource","jbo.sys.CODE_LIBRARY,itemno,itemname,codeno='adjust_style' and itemno in ("+this.getSqlWhere(rule.get("adjust_style"))+") order by sortno"); //调息方式 doTemp.setColumnAttribute("ADJUST_TYPE","coleditsource","jbo.sys.CODE_LIBRARY,itemno,itemname,codeno='adjust_type' and itemno in ("+this.getSqlWhere(rule.get("rate_float_type"))+") order by sortno"); } } } /** * 设置计算方式 * @param doTemp * @param productId * @return * @throws Exception */ public String getProductSettleRules(ASObjectModel doTemp,String productId) throws Exception{ //租金计算方式 Map> map=ProductParamUtil.getProductComponentType(productId, "PRD0301"); //分段 Map> submap=ProductParamUtil.getProductComponentType(productId, "PRD0321"); String s=""; String sJson=""; for(Map.Entry> entry:map.entrySet()){ if(s.length()>0)s+=","; s+="'"+entry.getKey()+"'"; if(sJson.length()>0)sJson+=","; sJson+="'"+entry.getKey()+"':"+FileOperatorUtil.getMapToJsonStr(entry.getValue()); if(entry.getKey().equals( doTemp.getColumnAttribute("SETTLE_METHOD", "coldefaultvalue"))){ Map values=entry.getValue(); if(values.containsKey("HolidayAdjust")){ doTemp.setDefaultValue("PLAN_DATE_HOILDAY", values.get("HolidayAdjust")); } if(values.containsKey("InterestHolidayAdjust")){ doTemp.setDefaultValue("INTEREST_DATE_HOLIDAY", values.get("InterestHolidayAdjust")); } if(values.containsKey("RATE")){ doTemp.setDefaultValue("RATE", values.get("RATE")); } if(values.containsKey("AdditionalRate")){ doTemp.setDefaultValue("ADDITIONAL_RATE", values.get("AdditionalRate")); } if(values.containsKey("InterestDayType")){ doTemp.setDefaultValue("INTEREST_DAY_TYPE", values.get("InterestDayType")); } } } if(submap.containsKey("ISSUBSECTION")){ if(s.length()>0)s+=","; s+="'even_subsection'"; } if(s.indexOf("even_rent") != -1) { s = "'even_rent'"; } else if(s.indexOf("even_corpus") != -1) { s = "'even_corpus'"; } else { s = "'even_interest'"; } doTemp.setReadOnly("SETTLE_METHOD", true); doTemp.setColumnAttribute("SETTLE_METHOD","coleditsource","jbo.sys.CODE_LIBRARY,itemno,itemname,codeno='settle_method' and itemno in ("+s+") order by sortno"); return "{"+sJson+"}"; } /** * 获取产品 资金类型 配置 添加列 * @param doTemp * @param productId * @return * @throws Exception */ @SuppressWarnings("unchecked") public void getProductFundRules(ASObjectModel doTemp,String productId) throws Exception{ //获取产品资金项 Map> map=ProductParamUtil.getProductComponentType(productId, "PRD0315"); for(String key:map.keySet()){ if(!("EQUIP_AMT".equals(key)||"FIRST_PAYMENT".equals(key))){//设备款和首付款不管 if("feetype_test".equals(key)){//测试费用 doTemp.Columns.add(this.prodSer.createFeeCol(key, map.get(key))); doTemp.Columns.add(this.prodSer.createFeeColRatio(key, map.get(key))); } } } } public String getSqlWhere(String condition){ String[] conds=condition.split(","); String s=""; for(int i=0;i0)s+=","; s+="'"+conds[i]+"'"; } return s; } //获取期数等 public void getCautionRatio(ASObjectModel doTemp,String productId) throws Exception{ //测算年利率字段 Map> productRates = ProductParamUtil.getProductComponentType(productId, "PRD0350"); Map productRate = productRates.get("product_rate"); if(productRate != null) { String incomeNumber = productRate.get("INCOME_NUMBER") == null ? "0" : productRate.get("INCOME_NUMBER"); doTemp.setDefaultValue("INCOME_NUMBER",incomeNumber); String periodType = productRate.get("begin_end") == null ? "period_type_0" : productRate.get("begin_end"); doTemp.setDefaultValue("PERIOD_TYPE",periodType); String ProductType = productRate.get("ProductType") == null ? "0" : productRate.get("ProductType"); String isReadOnly = productRate.get("ProductRateReadOnly") == null ? "Y" : productRate.get("ProductRateReadOnly"); String YEAR_RATE = productRate.get("ProductRate") == null ? "0" : productRate.get("ProductRate"); //利率为0,费率为1 if("1".equals(ProductType)){ doTemp.setColumnAttribute("YEAR_RATE","colheader","测算费率"); } if("Y".equals(isReadOnly)){ doTemp.setColumnAttribute("YEAR_RATE","colreadyonly","1"); } doTemp.setDefaultValue("YEAR_RATE",YEAR_RATE); } } }