| | |
| | | package com.product.file.service; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.common.collect.Lists; |
| | | import com.google.common.collect.Maps; |
| | | import com.product.common.lang.StringUtils; |
| | | import com.product.core.config.CoreConst; |
| | | import com.product.core.config.Global; |
| | | import com.product.core.connection.ConnectionManager; |
| | | import com.product.core.dao.BaseDao; |
| | |
| | | import com.product.file.util.FileUtil; |
| | | import com.product.file.util.FileUtils; |
| | | import com.product.module.sys.entity.SystemUser; |
| | | import com.product.util.BaseUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | |
| | | String uuids = ""; |
| | | for (Map.Entry<Object, Object> entry : map.entrySet()) { |
| | | fieldFse = fieldMetaEntity.getFieldMeta(fieldName); |
| | | if (fieldFse == null || !CmnConst.ATTACHMENT_TYPE.equals(fieldFse.getString(CmnConst.FIELD_TYPE))) { |
| | | if (fieldFse == null || (!CmnConst.ATTACHMENT_TYPE.equals(fieldFse.getString(CmnConst.FIELD_TYPE)) && !"file-image".equals(fieldFse.getString(CmnConst.FIELD_TYPE)))) { |
| | | fse.setValue(entry.getKey().toString(), null); |
| | | continue; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据附件表数据生成文档索引 |
| | | */ |
| | | public void readAttachmentCreateIndex() { |
| | | // 遍历附件表 |
| | | DataTableEntity dtAttachment = baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS); |
| | | if (BaseUtil.dataTableIsEmpty(dtAttachment)) { |
| | | return; |
| | | } |
| | | for (int i = 0; i < dtAttachment.getRows(); i++) { |
| | | // 获取附件信息,并判断是否有表和字段 |
| | | FieldSetEntity fseAttachment = dtAttachment.getFieldSetEntity(i); |
| | | if (BaseUtil.strIsNull(fseAttachment.getString("attachment_data_field")) || BaseUtil.strIsNull(fseAttachment.getString("attachment_data_field"))) { |
| | | continue; |
| | | } |
| | | // 查询原数据,有原数据再生成文档检索 |
| | | FieldSetEntity fseRecord = baseDao.getFieldSetEntityByFilter(fseAttachment.getString("attachment_data_table"), fseAttachment.getString("attachment_data_field") + " LIKE ?", new Object[]{"%" + fseAttachment.getUUID() + "%"}, false); |
| | | if (fseRecord != null) { |
| | | // 生成文档检索信息 |
| | | FieldSetEntity fseIndex = new FieldSetEntity(); |
| | | fseIndex.setTableName("fseIndex"); |
| | | fseIndex.setValue("function_uuid", fseAttachment.getString("function_uuid")); |
| | | fseIndex.setValue("attachment_uuid", fseAttachment.getUUID()); |
| | | CreateDocumentIndexThread.getInstance().appendAttaInfo(fseIndex); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 提取文件信息-下载文件或者在线预览文件 |
| | | * |
| | | * @param fse |
| | |
| | | String viewOnlineSign = attachmentFse.getString(CmnConst.VIEW_ONLINE_SIGN); |
| | | boolean encrptSignFlag = "1".equals(attachmentFse.getString(CmnConst.ENCRPT_SIGN)); |
| | | boolean needOnlineViewFlag = "1".equals(fse.getString(CmnConst.NEED_ONLINE_VIEW)) && "1".equals(viewOnlineSign); |
| | | if (needOnlineViewFlag && !realFileName.endsWith(".xlsx") && !realFileName.endsWith(".xls")) { |
| | | // 需要在线预览且转换之后才能在线预览 excel 文件不需要转换直接输出预览 |
| | | dir += File.separator + CmnConst.TRANSFER_DIR_NAME; |
| | | String clientType = SpringMVCContextHolder.getCurrentUser().getClientType(); |
| | | |
| | | String contentType = "multipart/form-data"; |
| | | boolean isExcel = realFileName.endsWith(".xlsx") || realFileName.endsWith(".xls"); |
| | | if (needOnlineViewFlag) { |
| | | //特殊处理: 如果客户端不是App 但预览的文件是Excel 直接返回excel源文件 content头标识是excel cheng 2025年2月11日10:41:41 |
| | | if (isExcel && !CoreConst.CLIENT_TYPE_APP.equals(clientType)) { |
| | | contentType = "application/vnd.ms-excel"; |
| | | } else { |
| | | dir += File.separator + CmnConst.TRANSFER_DIR_NAME; |
| | | } |
| | | } |
| | | |
| | | String path = dir + File.separator + fileName; |
| | |
| | | FTPService ftpService = new FTPService(); |
| | | logger.info("需要从附件服务器上取文件..."); |
| | | response.setHeader("Access-Control-Expose-Headers", "*"); |
| | | if (realFileName.endsWith(".xlsx") || realFileName.endsWith(".xls")) { |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | } else { |
| | | response.setContentType("multipart/form-data"); |
| | | } |
| | | |
| | | response.setContentType(contentType); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8")); |
| | | //设置头中的文件类型 |
| | | if (!needOnlineViewFlag && !encrptSignFlag) { |
| | |
| | | String localBasePath = Global.getSystemConfig("local.dir", ""); |
| | | path = localBasePath + File.separator + path; |
| | | File file = new File(path); |
| | | if (needOnlineViewFlag && file.exists() && CoreConst.CLIENT_TYPE_APP.equals(clientType)) { |
| | | //特殊处理: 是App 但预览的文件是Excel 需要将之前已转换为的文件删除掉重新转换(因转换后的格式不是pdf) |
| | | String changeTime = "2025-02-11 23:59:59"; |
| | | Date changeDate = DateUtil.parse(changeTime, "yyyy-MM-dd HH:mm:ss"); |
| | | long fileTime = file.lastModified(); |
| | | //如果时间是 2025年2月10日23:59:59,那么就重新转换 |
| | | //删除文件 |
| | | if (fileTime <= changeDate.getTime()) { |
| | | file.delete(); |
| | | } |
| | | } |
| | | if (needOnlineViewFlag && !file.exists()) { |
| | | // 若是预览,但是转换后的文件不存在,那么重新执行转换操作 |
| | | File sourceFile = fileUtils.getFile(false, attachmentFse.getString(CmnConst.ATTACHMENT_URL), fileName, encrptSignFlag); |
| | |
| | | byte[] b = new byte[1024]; |
| | | InputStream is = new FileInputStream(file); |
| | | response.setHeader("Access-Control-Expose-Headers", "*"); |
| | | if (realFileName.endsWith(".xlsx") || realFileName.endsWith(".xls")) { |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | } else { |
| | | response.setContentType("multipart/form-data"); |
| | | } |
| | | |
| | | response.setContentType(contentType); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8")); |
| | | response.setContentLengthLong(file.length()); |
| | | try (ServletOutputStream os = response.getOutputStream()) { |