@RemoteMethod
 public ListRange findAll(
     TemplateShareGroupDetailDto filter, SortField[] sortFields, int start, int limit) {
   ListRange lr = new ListRange();
   String hql =
       "FROM TemplateShareGroupDetail WHERE templateShare.templateFile.id = ? AND "
           + BusinessConstant.FIND_NOT_INCLUDE_DELETE_HQL
           + " ORDER BY create_date DESC";
   int count = 0;
   List<TemplateShareGroupDetail> list =
       templateShareGroupDetailDaoImpl.findAll(hql, start, limit, filter.getTemplateFileId());
   List<TemplateShareGroupDetailDto> dtoList = new ArrayList<TemplateShareGroupDetailDto>();
   for (TemplateShareGroupDetail templateShareGroupDetail : list) {
     TemplateShareGroupDetailDto templateShareGroupDetailDto =
         dozerAssembly.bean2Dto(templateShareGroupDetail, TemplateShareGroupDetailDto.class);
     templateShareGroupDetailDto.setCreate_date(
         DateUtils.DateToDateTimeString(templateShareGroupDetail.getCreate_date()));
     if (templateShareGroupDetail.getAccount() != null
         && templateShareGroupDetail.getAccount().getPerson() != null)
       templateShareGroupDetailDto.setPersonName(
           templateShareGroupDetail.getAccount().getPerson().getName());
     dtoList.add(templateShareGroupDetailDto);
   }
   count = templateShareGroupDetailDaoImpl.getCount(hql, filter.getTemplateFileId());
   lr.setData(dtoList);
   lr.setTotalSize(count);
   return lr;
 }
 @RemoteMethod
 public FileTransfer downloadFile(String id, HttpServletRequest request) {
   TemplateShareGroupDetail shareGroupDetail = templateShareGroupDetailDaoImpl.findById(id);
   String path =
       formTemplateService.downLoadFilePath(
               shareGroupDetail.getAccount(), shareGroupDetail.getCreate_date())
           + "/"
           + shareGroupDetail.getFilePath();
   return FileDownLoadUtils.downloadFile(path, shareGroupDetail.getFileName());
 }
 public void saveGroupDetail(
     String shareGroupDetailId,
     String filePath,
     User user,
     String fileName,
     TemplateShare templateShare) {
   TemplateShareGroupDetail templateShareGroupDetail = null;
   if (!StringUtils.isEmpty(shareGroupDetailId))
     templateShareGroupDetail = templateShareGroupDetailDaoImpl.findById(shareGroupDetailId);
   else templateShareGroupDetail = new TemplateShareGroupDetail();
   templateShareGroupDetail.setAccount(user);
   templateShareGroupDetail.setCreate_date(DateUtils.getCurrentDateTime());
   templateShareGroupDetail.setFileName(fileName);
   templateShareGroupDetail.setFilePath(filePath);
   templateShareGroupDetail.setTemplateShare(templateShare);
   templateShareGroupDetailDaoImpl.saveOrUpdate(templateShareGroupDetail);
   if (StringUtils.isEmpty(shareGroupDetailId))
     templateFileLogService.addOperationLog(
         templateShare.getTemplateFile(), BusinessConstant.OPERATION_SHARE_GROUP_DETAIL_ADD, null);
   else
     templateFileLogService.addOperationLog(
         templateShare.getTemplateFile(),
         BusinessConstant.OPERATION_SHARE_GROUP_DETAIL_EDIT,
         null);
 }
  /**
   * saveMerage 合并多个excel文件
   *
   * @param args
   * @return void
   * @exception
   */
  @RemoteMethod
  public void saveMerage(List<String> args, String templateFileId) {
    HSSFWorkbook hSSFtargetWorkbook = new HSSFWorkbook();
    // XSSFWorkbook xSSFtargetWorkbook = new XSSFWorkbook();
    Workbook workbook = null;
    FileOutputStream out = null;
    InputStream sourceStream = null;
    try {
      // 保存上传的合并文件
      TemplateFile templateFile = templateFileDaoImpl.findById(templateFileId);
      String uuid = UUID.randomUUID().toString();
      String templateFilePath = getFilePath(templateFile);
      String uploadFilePath =
          formTemplateService.getUploadFilePath(null, BusinessConstant.FORM_UPLOAD)
              + "/"
              + uuid
              + FileUploadUtils.getFileType(templateFilePath);
      templateFile.setGroupFileName(templateFile.getFileName());
      templateFile.setGroupFilePath(uuid + FileUploadUtils.getFileType(templateFilePath));
      templateFileDaoImpl.saveOrUpdate(templateFile);

      for (String detaiId : args) {
        TemplateShareGroupDetail templateShareGroupDetail =
            templateShareGroupDetailDaoImpl.findById(detaiId);
        String filePath =
            formTemplateService.downLoadFilePath(
                    templateShareGroupDetail.getAccount(),
                    templateShareGroupDetail.getCreate_date())
                + "/"
                + templateShareGroupDetail.getFilePath();
        sourceStream = new FileInputStream(filePath); // 每个实例的文件路径
        workbook = WorkbookFactory.create(sourceStream);
        if (".xls".equals(FileUploadUtils.getFileType(templateShareGroupDetail.getFilePath()))
            || ".et".equals(FileUploadUtils.getFileType(templateShareGroupDetail.getFilePath()))) {
          out = new FileOutputStream(new File(uploadFilePath)); // 合并后的文件路径
          PoiUtils.copySheet2003(
              hSSFtargetWorkbook.createSheet(
                  templateShareGroupDetail.getAccount().getPerson().getName()),
              (HSSFSheet) workbook.getSheetAt(0),
              hSSFtargetWorkbook,
              (HSSFWorkbook) workbook,
              true,
              true);
          hSSFtargetWorkbook.write(out);
        }
        // 由于金格office编辑器在编辑07版本的excel时会将其内在格式转换为03版本,故poi无法将以.xlsx为后缀的excel读取为XSSFWorkBook对象,此功能暂注释
        // else if
        // (".xlsx".equals(getFileType(templateShareGroupDetail.getFilePath())))
        // {// 2007
        // out = new FileOutputStream(new File("d:\\hhh2.xlsx"));
        // PoiUtils.copySheet2007(xSSFtargetWorkbook.createSheet(templateShareGroupDetail.getAccount().getPerson().getName()),
        // (XSSFSheet) workbook.getSheetAt(0), xSSFtargetWorkbook,
        // (XSSFWorkbook) workbook, true);
        // xSSFtargetWorkbook.write(out);
        // }
        else throw new BusinessException(ERR_COMPONENT + "101");
      }
      templateFileLogService.addOperationLog(
          templateFile, BusinessConstant.OPERATION_SHARE_GROUP_MODIFY, null);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BusinessException(ERR_COMPONENT + "101");
    } finally {
      try {
        if (out != null) out.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }