| | |
| | | import okhttp3.MediaType; |
| | | import okhttp3.MultipartBody; |
| | | import okhttp3.RequestBody; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | // 存放在数据库中的文件,直接判定是否有值 |
| | | if (attachmentFse.getValue(CmnConst.FILE_CONTENT) != null) { |
| | | return true; |
| | | } |
| | | |
| | | //判断文件存放在服务器还是本地 |
| | | boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN)); |
| | | String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL); |
| | |
| | | String fileFinalName = ""; |
| | | for (Map.Entry<Object, Object> entry : map.entrySet()) { |
| | | fieldFse = fieldMetaEntity.getFieldMeta(fieldName); |
| | | if (fieldFse == null || !Arrays.asList(CmnConst.ATTACHMENT_TYPE, "file-image", FieldType.FILE_ATTACHMENT.getDictValue()).contains(fieldFse.getString(CmnConst.FIELD_TYPE))) { |
| | | if (fieldFse == null || !Arrays.asList(CmnConst.ATTACHMENT_TYPE, "file-image", FieldType.FILE_ATTACHMENT.getDictValue(), FieldType.SIGNATURE.getDictValue()).contains(fieldFse.getString(CmnConst.FIELD_TYPE))) { |
| | | fse.setValue(entry.getKey().toString(), null); |
| | | continue; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | boolean saveInDbFlag = FieldType.FILE_ATTACHMENT.getDictValue().equals(fieldFse.getString("field_type")); |
| | | boolean saveInDbFlag = FieldType.checkSaveInDB(fieldFse.getString("field_type")); |
| | | if (!saveInDbFlag) { |
| | | fileFinalName = FileUtils.uploadFile(tempFile, templateType, clientUuid); |
| | | } else { |
| | |
| | | if (saveInDb) { |
| | | File localFile = new File(Global.getSystemConfig("local.dir", "") + File.separator + attachmentFse.getString(CmnConst.ATTACHMENT_URL) + File.separator + fileName); |
| | | if (!localFile.exists()) { |
| | | localFile.getParentFile().mkdirs(); |
| | | Files.copy(is, localFile.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | | } |
| | | } |
| | |
| | | FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false); |
| | | return this.getFileContent(attachmentFse); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户签名 |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | public String getSignature(FieldSetEntity fse) throws BaseException { |
| | | String bytes = Base64.encodeBase64String(getFileContent(fse.getUUID())); |
| | | if (bytes == null) { |
| | | return null; |
| | | } |
| | | return "data:image/png;base64," + bytes; |
| | | } |
| | | |
| | | /** |
| | | * 根据附件uuid获取文件 |
| | |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 验证是否可以预览 |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | public Object checkPreview(FieldSetEntity fse) { |
| | | String fileName = fse.getString("file_name"); |
| | | boolean allowPreviewFlag = Global.getPropertyToBoolean("file.view.online", "true"); |
| | | List<String> canTransferFormatList = Lists.newArrayList(Arrays.asList(Global.getSystemConfig("can.transfer.format", "").split(","))); |
| | | List<String> canDirectPreviewList = Lists.newArrayList(Arrays.asList(Global.getSystemConfig("can.direct.view.online.format", "").split(","))); |
| | | List<String> canPreviewList = Lists.newArrayList(); |
| | | canPreviewList.addAll(canTransferFormatList); |
| | | canPreviewList.addAll(canDirectPreviewList); |
| | | if (StringUtils.isEmpty(fileName)) { |
| | | if (allowPreviewFlag) { |
| | | return BaseUtil.collection2String(canPreviewList); |
| | | } else { |
| | | return ""; |
| | | } |
| | | } else { |
| | | String tail = fileName.substring(fileName.lastIndexOf(".") + 1); |
| | | return allowPreviewFlag && canPreviewList.contains(tail); |
| | | } |
| | | } |
| | | } |