| | |
| | | return baseDao.executeUpdate(sql.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 根据附件uuid判断文件是否存在 |
| | | * |
| | | * @param uuid |
| | | * @return |
| | | */ |
| | | public boolean fileExist(String uuid) { |
| | | if (StringUtils.isEmpty(uuid)) { |
| | | return false; |
| | | } |
| | | FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false); |
| | | if (attachmentFse == null) { |
| | | return false; |
| | | } |
| | | |
| | | //判断文件存放在服务器还是本地 |
| | | boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN)); |
| | | String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL); |
| | | String fileName = attachmentFse.getString(CmnConst.ATTACHMENT_TITLE); |
| | | boolean encrptSignFlag = "1".equals(attachmentFse.getString(CmnConst.ENCRPT_SIGN)); |
| | | |
| | | if (needDownloadFromServerFlag) { |
| | | // 需要从附件服务器上取文件 |
| | | FTPService ftpService = new FTPService(); |
| | | return ftpService.fileIsExist(dir, fileName); |
| | | } else { |
| | | // 直接在本地的目录中找文件 |
| | | String localBasePath = Global.getSystemConfig("local.dir", ""); |
| | | String path = localBasePath + File.separator + dir + File.separator + fileName; |
| | | File file = new File(path); |
| | | return file.isFile(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 上传文件到本地服务器 |
| | |
| | | attachmentFse.setValue(CmnConst.ENCRPT_SIGN, Global.getPropertyToBoolean("file.encrypt", "true") ? 1 : 0); |
| | | attachmentFse.setValue(CmnConst.ATTACHMENT_SIZE, fileLength); |
| | | attachmentFse.setValue(CmnConst.UPLOAD_SIGN, needUpload2FileServerFlag ? 1 : 0); |
| | | |
| | | attachmentFse.setValue(CmnConst.FUNCTION_UUID, fse.getString(CmnConst.FUNCTION_UUID)); |
| | | attachmentFse.setValue(CmnConst.ATTACHMENT_CONTAINER, fse.getString(CmnConst.ATTACHMENT_CONTAINER)); |
| | | attachmentFse.setValue(CmnConst.ATTACHMENT_DOMAIN, fse.getString(CmnConst.ATTACHMENT_DOMAIN)); |
| | | attachmentFse.setValue(CmnConst.MODULE_UUID, fse.getString(CmnConst.MODULE_UUID)); |
| | |
| | | } |
| | | os.flush(); |
| | | } |
| | | |
| | | is.close(); |
| | | } |
| | | logger.info("文件流获取成功"); |
| | | } |
| | |
| | | try { |
| | | temp.createNewFile(); |
| | | } catch (IOException e) { |
| | | throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() : "")); |
| | | throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() + ",uuid:" + attachmentFse.getUUID() : "")); |
| | | } |
| | | try (FileOutputStream fos = new FileOutputStream(temp); BufferedOutputStream out = new BufferedOutputStream(fos)) { |
| | | |
| | |
| | | return temp; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() : "")); |
| | | throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() + ",uuid:" + attachmentFse.getUUID() : "")); |
| | | } |
| | | } |
| | | throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText()); |
| | | throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + ",uuid:" + attachmentFse.getUUID()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public byte[] getFileContent(FieldSetEntity attachmentFse) throws BaseException { |
| | | if (attachmentFse == null || !CmnConst.PRODUCT_SYS_ATTACHMENTS.equals(attachmentFse.getTableName())) { |
| | | return new byte[16]; |
| | | //返回一个空的字节数组 |
| | | return new byte[0]; |
| | | } |
| | | try (ByteArrayOutputStream os = new ByteArrayOutputStream();) { |
| | | FTPService ftpService = new FTPService(); |