// add ---wangzhixin----2009/07/21 start public boolean processFile() { if (checkData()) { try { long time = System.currentTimeMillis(); // BaseConfig tBaseConfig=new BaseConfig(); // ProductCombinationDef // tProductCombinationDef=(ProductCombinationDef)tBaseConfig.getValue("productCombinationDef", "requestScope"); // String fileName =tProductCombinationDef.getRiskCode()+".jpg"; // String fileName = new File(upfile.getName()).getName(); String fileName = new File(upfile.getName()).getName(); String endwith = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); fileName = simpleDateFormat.format(new Date()) + "." + endwith; this.myFile = fileName; System.out.println(fileName); InputStream in = upfile.getInputStream(); if (limitSize(in.available())) { return false; } // (double)((double)in.available()/1024/1024) System.out.println(".............." + in.available()); FacesContext ctx = FacesContext.getCurrentInstance(); HttpSession hs = (HttpSession) ctx.getExternalContext().getSession(true); String directory = hs.getServletContext().getRealPath("/") + "/upload"; directory.replace("\\", "/"); System.out.println("directory....." + directory); directory.replace("\\", "/"); File fileDir = new File(directory); if (!fileDir.exists()) { if (!fileDir.mkdir()) { System.out.println("文件夹创建失败"); } } String file = hs.getServletContext().getRealPath("/") + "/upload/" + fileName; // this.action(fileName, file); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); byte[] buffer = new byte[1024 * 2]; int length; while ((length = in.read(buffer, 0, buffer.length)) > 0) { out.write(buffer, 0, length); } out.flush(); out.close(); copyFileToFront(fileName, file); // 将条款拷贝到前台一份 add by fengzg 2009-06-16 return true; } catch (Exception e) { e.printStackTrace(); return false; } } else { return false; } }
@SuppressWarnings("deprecation") private boolean checkData() { // 校验停售日期不能小于当前日期 boolean flag = true; boolean isNum = true; for (int i = timeoutDef.length(); --i >= 0; ) { int chr = timeoutDef.charAt(i); if (chr < 48 || chr > 57) { errorMessage.append("超时时间必须是大于0的整数!"); flag = false; isNum = false; break; } } /* if(!"".equals(timeoutDef)&&isNum&&Integer.parseInt(timeoutDef)<=0){ errorMessage.append("超时时间必须是大于0的整数!"); flag=false; } */ String startdate = ""; String enddate = ""; FDate fDate = new FDate(); if (null != endDate) { enddate = fDate.getString(endDate); } if (null != startDate) { startdate = fDate.getString(startDate); } /* if (null!=endDate && PubFun.calInterval(PubFun.getCurrentDate(), enddate, "D") <= 0) { operateResult = "checkfail"; errorMessage.append("销售止期必须大于当前日期!"); flag = false; } if (null!=endDate && null!=startDate && PubFun.calInterval(startdate, enddate, "D") < 0) { operateResult = "checkfail"; errorMessage.append("销售止期不能小于销售起期!"); flag = false; } */ // 校验险种的相关信息 int n = risks.length; if (n == 0) { operateResult = "checkfail"; errorMessage.append("请选择计划要包含的产品!"); flag = false; } else { ExeSQL tExeSql = new ExeSQL(); int mainRiskCount = 0; for (int i = 0; i < n; i++) { String sql = "select subriskflag,startdate,enddate,riskname from leprisk where riskcode='" + risks[i] + "'"; SSRS tSSRS = tExeSql.execSQL(sql); // 每个产品组合有且仅有一个主险 if (tSSRS.GetText(1, 1).equals("M")) { planMainRisk = risks[i]; mainRiskCount++; } // 销售起期要在产品的销售起期之后,停售日期要在所有产品停售之前 int s = PubFun.calInterval(tSSRS.GetText(1, 2), startdate, "D"); if (null != startDate && s < 0) { operateResult = "checkfail"; errorMessage.append( tSSRS.GetText(1, 4) + "的销售起期是" + tSSRS.GetText(1, 2) + ",产品组合的销售起期不能早于产品的销售起期!"); flag = false; } int e = PubFun.calInterval(tSSRS.GetText(1, 3), enddate, "D"); if (null != endDate && e > 0) { operateResult = "checkfail"; errorMessage.append( tSSRS.GetText(1, 4) + "的销售止期是" + tSSRS.GetText(1, 3) + ",产品组合的销售止期不能晚于产品的销售止期!"); flag = false; } } if (mainRiskCount < 1) { operateResult = "checkfail"; errorMessage.append("保险计划必须包含一个主险!"); flag = false; } else if (mainRiskCount > 1) { operateResult = "checkfail"; errorMessage.append("保险计划仅可包含一个主险!"); flag = false; } } /* if (!introduce.equals("") && introduce.trim().getBytes().length > 1600) { operateResult = "checkfail"; errorMessage.append("产品组合介绍不能多于800个汉字!"); flag = false; } if (!rule.equals("") && rule.trim().getBytes().length > 1600) { operateResult = "checkfail"; errorMessage.append("产品组合投保规则不能多于800个汉字!"); flag = false; } */ if (upfile != null && !("".equals(upfile))) { String fileName = new File(upfile.getName()).getName(); String endwith = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()); endwith = endwith.toUpperCase(); if (endwith == null || (!endwith.equals("JPG") && !endwith.equals("GIF") && !endwith.equals("BMP"))) { operateResult = "checkfail"; errorMessage.append("您上载图片类型" + endwith + "有误,只能上载jpg格式文件"); System.out.println("上载图片类型错误!"); flag = false; } } else { operateResult = "checkfail"; errorMessage.append("请选择要上传的图片"); flag = false; } return flag; }