public void service(HttpServletRequest req, HttpServletResponse res)
     throws IOException, ServletException {
   MultipartHttpServletRequest httpReq = getMultipartResolver().resolveMultipart(req);
   // 单据类型
   String bill_type = httpReq.getParameter("bill_type");
   if (!getMultipartResolver().isMultipart(req)) {
     throw new IllegalArgumentException(
         NCLangRes4VoTransl.getNCLangRes()
             .getStrByID("lfw", "LfwFileUploadServlet-000000") /* 请求不是一个multipart请求! */);
   }
   try {
     Object result = doSaveFiles(req, res, httpReq);
     if (result != null) {
       LfwJsonSerializer serializer = new LfwJsonSerializer();
       String strResult = serializer.toJsObject(result);
       req.setAttribute("result", strResult);
       RequestDispatcher dispatcher =
           getServletContext()
               .getRequestDispatcher("/html/nodes/importbodydata/uploadsuccess.jsp");
       dispatcher.forward(req, res);
     } else {
       RequestDispatcher dispatcher =
           getServletContext()
               .getRequestDispatcher("/html/nodes/importbodydata/uploadsuccess.jsp");
       dispatcher.forward(req, res);
     }
   } catch (Exception e) {
     logger.error(e);
   }
 }
Beispiel #2
0
  // 季凌峰 2012/12/25 附件解密
  public String loupadate(
      String opensource, String pk_xy_proj_main, String pk_xy_pub_step, String price_type) {
    String keyValue = null;
    // 附件解密方法
    Properties props = new Properties();
    // 文件存放的路径。评标会解密的附件压缩
    String ebsfile = "";
    BaseDAO dao = new BaseDAO();
    InputStream is = null;
    try {
      // 读取应用下的配置文件
      String path =
          RuntimeEnv.getInstance().getNCHome()
              + File.separatorChar
              + "hotwebs"
              + File.separatorChar
              + "ebscg"
              + File.separatorChar
              + "WEB-INF"
              + File.separatorChar
              + "conf"
              + File.separatorChar
              + "system.properties";
      is = new FileInputStream(path);
      props.load(is);
      keyValue = props.getProperty(EbsOperaitonConst.CHECK_KEY);
    } catch (Exception e) {
      Logger.error("读取系统配置错误!", e);
      try {
        if (is != null) is.close();
      } catch (Exception et) {
        Logger.error("读取系统配置错误!", et);
      }
    } finally {
      try {
        if (is != null) is.close();
      } catch (IOException e) {
        Logger.error("读取系统配置错误!", e);
      }
    }

    // 如果为1的时候则对文件解密
    if (keyValue != null) {

      // 因为没有从js获取,没有打开界面调用数据,所以参数需要自己定义和获取。
      String openvalue = "2";

      // 模块类型  model_type    7门户上传附件
      String modelType = "7";
      // 来源单据类型  bill_type  //发标应答  E059   发布应答     E05A
      String billType = "E059"; // 发标应答  E059
      if (opensource != null && opensource.equals("0")) {
        billType = "E05A"; // 发布应答     E05A				
      }
      // 所属单据ID bill_id   采购方案主键
      String billId = pk_xy_proj_main;
      // 所属单据明细ID itemid  供应商确定主键
      try {

        String sql =
            "select * from ebs_xy_proj_item_sup_cfm  where pk_xy_proj_main = '"
                + pk_xy_proj_main
                + "' and isnull(dr,0) = 0 ";
        List<ProjItemSupCfmVO> sp =
            (List<ProjItemSupCfmVO>)
                dao.executeQuery(sql, new BeanListProcessor(ProjItemSupCfmVO.class));
        if (sp != null && sp.size() > 0) {
          for (ProjItemSupCfmVO sup : sp) {
            // 获取每次供应商的附件
            // 修改下面的方法,主要是为了取得对应的附件类型。

            String sqls =
                "select * from ebs_da_att where model_type='"
                    + modelType
                    + "' and bill_type= '"
                    + billType
                    + "' and bill_id='"
                    + billId
                    + "' and itemid='"
                    + sup.getPk_xy_proj_item_sup_cfm()
                    + "' and zdy3='"
                    + pk_xy_pub_step
                    + "' and price_type in ("
                    + price_type
                    + ") and ISNULL(dr,0) = 0      ";

            List<AttVO> list =
                (List<AttVO>) dao.executeQuery(sqls, new BeanListProcessor(AttVO.class));
            // List<AttVO> list = getOpenQueryService().getCaFileByPara(modelType, billType, billId,
            // sup.getPk_xy_proj_item_sup_cfm());
            EbscgFileUploadHandler fileHandler =
                (EbscgFileUploadHandler)
                    LfwClassUtil.newInstance(EbscgFileUploadHandler.class.getName());
            if (list != null && list.size() > 0) {
              SignVO signvo = null;
              byte[] baOutPlaintext = null;
              for (AttVO attvo : list) {
                if (attvo != null && attvo.getAfter_ca() != null && attvo.getAfter_ca() == 1) {
                  continue;
                }
                try {
                  // 采用数据库读取文件数据
                  DataFileFactory dff = DataFileFactory.getInstance();
                  IDataBaseFileOper ibfo = dff.getFileDealServer();
                  byte[] content = null;
                  content = ibfo.obtainFileMess(attvo.getPk_da_att(), "ca_content");

                  EncrypteDecrypte3DES des = new EncrypteDecrypte3DES();
                  BASE64Decoder base64 = new BASE64Decoder();
                  des.setKey(base64.decodeBuffer(keyValue));
                  des.setIv(base64.decodeBuffer("zz7cZtYpVR4="));

                  baOutPlaintext = des.decrypt(base64.decodeBuffer(new String(content).trim()));
                  ibfo.updateFileMess(attvo.getPk_da_att(), baOutPlaintext, "content");

                  attvo.setAfter_ca(1);
                  // 设置文档解密状态
                  dao.updateVO(attvo, new String[] {"after_ca"});
                } catch (Exception ex) {
                  // TODO Auto-generated catch block
                  logger.error(ex.getMessage(), ex);
                  return "文件解密失败";
                  /*throw new LfwRuntimeException("文件解密失败");*/
                }
              }
            }
          }
        }
      } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return "文件解密失败";
        /*throw new LfwRuntimeException("文件解密失败");*/
      }
    }
    return "ok";
  }
  private Object doSaveFiles(
      HttpServletRequest req, HttpServletResponse res, MultipartHttpServletRequest httpReq)
      throws Exception {

    String dealClass = httpReq.getParameter("dealclass");
    String pkmessage = httpReq.getParameter("pkmessage");
    if ("null".equals(dealClass)) {
      dealClass = (String) req.getSession().getAttribute("dealclass");
    }
    if ("null".equals(pkmessage)) {
      pkmessage = (String) req.getSession().getAttribute("pkmessage");
    }

    if (dealClass == null) {
      req.setAttribute("message", "获取xls文件处理类失败,请检查参数信息!");
      RequestDispatcher dispatcher =
          getServletContext().getRequestDispatcher("/html/nodes/importbodydata/uploadsuccess.jsp");
      dispatcher.forward(req, res);
    }

    Iterator nameIt = httpReq.getFileNames();
    Map parameterMap = httpReq.getParameterMap();

    MultipartFile file = null;
    while (nameIt.hasNext()) {
      String fileName = (String) nameIt.next();
      logger.debug("get file:" + fileName);
      file = httpReq.getFile(fileName);
      logger.debug("end  file:");
    }

    if (file == null) {

      req.setAttribute("message", "无法获取到上传的文件数据信息,请重新上传数据文件!");
      RequestDispatcher dispatcher =
          getServletContext().getRequestDispatcher("/html/nodes/importbodydata/message.jsp");
      dispatcher.forward(req, res);
    }

    String message = "";
    try {
      Object obj = Class.forName(dealClass).newInstance();

      if (obj == null) {

        message = "数据导入时,实例化处理类失败,请联系维护人员解决此问题!";

      } else {

        if (obj instanceof ImportExcelIn) {

          ImportExcelIn iei = (ImportExcelIn) obj;

          message = iei.dealExcelFile(file.getInputStream(), httpReq);

        } else {
          message = "实际传入的类为" + dealClass + ",需实现相应接口,请检查实现接口是否有误!";
        }
      }

    } catch (Exception e) {

      message = "数据导入时,实例化处理类失败,请联系维护人员解决此问题!";
      logger.error("数据导入时,实例化处理类失败,class=" + dealClass);
      logger.error(e.getMessage(), e);
    }

    req.getSession().setAttribute("message", message);
    req.getSession().setAttribute("pkmessage", pkmessage);
    req.getSession().setAttribute("dealclass", dealClass);
    return null;
  }