|
@@ -11,7 +11,6 @@ import com.qmth.distributed.print.business.entity.SysUser;
|
|
|
import com.qmth.distributed.print.business.enums.UploadFileEnum;
|
|
|
import com.qmth.distributed.print.business.mapper.BasicAttachmentMapper;
|
|
|
import com.qmth.distributed.print.business.service.BasicAttachmentService;
|
|
|
-import com.qmth.distributed.print.business.util.FileMd5Util;
|
|
|
import com.qmth.distributed.print.business.util.OssUtil;
|
|
|
import com.qmth.distributed.print.business.util.ServletUtil;
|
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
@@ -30,7 +29,9 @@ import org.springframework.util.FileCopyUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -166,14 +167,13 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
|
|
|
*
|
|
|
* @param fileName
|
|
|
* @param htmlContent
|
|
|
- * @param schoolId
|
|
|
* @param userId
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long schoolId, Long userId) throws IOException {
|
|
|
+ public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId) throws IOException {
|
|
|
BasicAttachment basicAttachment = null;
|
|
|
try {
|
|
|
byte[] bytes = htmlContent.getBytes();
|
|
@@ -185,18 +185,18 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
|
|
|
stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
|
|
|
}
|
|
|
stringJoiner.add(UploadFileEnum.HTML.getTitle()).add(File.separator)
|
|
|
- .add(String.valueOf(schoolId)).add(File.separator)
|
|
|
.add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
.add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
.add(String.format("%02d", nowTime.getDayOfMonth()));
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- stringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(File.separator).add(fileName).add(SystemConstant.HTML_PREFIX);
|
|
|
- //计算html文件md5
|
|
|
- String fileMd5 = FileMd5Util.pathMd5(stringJoiner.toString());
|
|
|
+ stringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.HTML_PREFIX);
|
|
|
+ String fileMd5 = null;
|
|
|
if (oss) {//上传至oss\
|
|
|
String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
|
|
|
ossUtil.ossUpload(dirName, htmlContent);
|
|
|
+ byte[] data = ossUtil.ossDownload(dirName);
|
|
|
+ fileMd5 = DigestUtils.md5Hex(new ByteArrayInputStream(data));
|
|
|
jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
jsonObject.put(SystemConstant.PATH, dirName);
|
|
|
} else {//上传至服务器
|
|
@@ -206,6 +206,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
|
|
|
finalFile.createNewFile();
|
|
|
}
|
|
|
FileCopyUtils.copy(bytes, new File(stringJoiner.toString()));
|
|
|
+ fileMd5 = DigestUtils.md5Hex(new FileInputStream(stringJoiner.toString()));
|
|
|
jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
jsonObject.put(SystemConstant.PATH, stringJoiner.toString());
|
|
|
}
|