/**
   * 添加附件
   * {"attachType":null,"attachName":"intel_ICS_Dx32.exe","result":"Y","attachGroupId":281,"attachId":345,"attachSize":"7.42
   * MB"}
   *
   * @author 何道军
   * @date 2011-1-7
   * @return String
   */
  public String addAttach() {
    Map<String, Object> attachMap = new HashMap<String, Object>();
    if (uploadAttach == null) {
      attachMap.put("success", false);
      attachMap.put("result", "添加失败。");
      JsonUtil.outJson(attachMap);
      return null;
    }

    if (uploadAttach.length() == 0) {
      attachMap.put("success", false);
      attachMap.put("result", "添加失败:不能上传大小为0 KB的文件。");
      JsonUtil.outJson(attachMap);
      return null;
    }

    if (maximumSize != null && maximumSize > 0 && maximumSize < uploadAttach.length()) {
      attachMap.put("success", false);
      attachMap.put(
          "result",
          "添加失败:文件大小不能超过 "
              + FormatUnitsUtil.formatBytes(maximumSize)
              + "。当前文件大小为:"
              + FormatUnitsUtil.formatBytes(uploadAttach.length()));
      JsonUtil.outJson(attachMap);
      return null;
    }
    if (StringUtils.isNotBlank(allowedExtensions)
        && !allowedExtensions.contains(FileUtil.getFileExp(uploadAttachFileName))) {
      attachMap.put("success", false);
      attachMap.put("result", "添加失败:只能上传后缀名为:" + allowedExtensions + "的文件。");
      JsonUtil.outJson(attachMap);
      return null;
    }
    try {
      if (attachGroupId != 0) {
        attachGroup = attachGroupService.getAttachGroup(attachGroupId);
        if (attachGroup == null) {
          attachMap.put("success", false);
          attachMap.put(
              "result", "系统错误:更新的附件组ID:" + attachGroupId + "不存在,如果要重新生成附件组ID,请设置附件组ID为空或0!");
          JsonUtil.outJson(attachMap);
          return null;
        }
      } else {
        attachGroup = new AttachGroup();
        attachGroup.setStatus(STATUS_NOT_DELETE);
        attachGroup.setSubmitDate(new Date());
        attachGroupService.saveAttachGroup(attachGroup);
      }

      dealSavePath();

      attach = new Attach();
      attach.setStatus(STATUS_NOT_DELETE);
      attach.setAttachName(uploadAttachFileName);
      attach.setAttachType(attachType);
      String attachURL = FileUtil.upload(uploadAttach, uploadAttachFileName, savePath);
      attach.setAttachUrl(attachURL);
      attach.setAttachGroup(attachGroup);
      attach.setSubmitDate(new Date());
      attach.setFileSize(FormatUnitsUtil.formatBytes(uploadAttach.length()));
      attach.setDownloadTime(0);
      attachService.saveAttach(attach);

      attachMap.put("attachGroupId", attachGroup.getAttachGroupId());
      attachMap.put("attachName", attach.getAttachName());
      attachMap.put("attachId", attach.getAttachId());
      attachMap.put("attachType", attach.getAttachType());
      attachMap.put("fileSize", attach.getFileSize());
      attachMap.put("success", true);
    } catch (Exception e) {
      attachMap.put("success", false);
      attachMap.put("result", "添加失败:" + e.getMessage());
      e.printStackTrace();
    }
    JsonUtil.outJson(attachMap);
    return null;
  }