|
@@ -27,7 +27,9 @@ import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
import com.qmth.teachcloud.common.service.BasicAttachmentService;
|
|
import com.qmth.teachcloud.common.service.BasicAttachmentService;
|
|
import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
|
|
+import com.qmth.teachcloud.common.util.FileStoreUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -36,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
@@ -71,6 +74,9 @@ public class BasicTemplateServiceImpl extends ServiceImpl<BasicTemplateMapper, B
|
|
@Resource
|
|
@Resource
|
|
DictionaryConfig dictionaryConfig;
|
|
DictionaryConfig dictionaryConfig;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ FileStoreUtil fileStoreUtil;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public IPage<TemplateDto> list(Boolean enable, String type, String name, Long startTime, Long endTime, Integer pageNumber, Integer pageSize) {
|
|
public IPage<TemplateDto> list(Boolean enable, String type, String name, Long startTime, Long endTime, Integer pageNumber, Integer pageSize) {
|
|
Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
@@ -211,34 +217,75 @@ public class BasicTemplateServiceImpl extends ServiceImpl<BasicTemplateMapper, B
|
|
pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
|
|
pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
|
|
String pdfDirName = pdfStringJoiner.toString();
|
|
String pdfDirName = pdfStringJoiner.toString();
|
|
|
|
|
|
- String destUrl = null;
|
|
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
|
- destUrl = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + pdfDirName;
|
|
|
|
- } else {
|
|
|
|
- destUrl = dictionaryConfig.fssPublicDomain().getConfig() + File.separator + pdfDirName;
|
|
|
|
|
|
+ File file = null;
|
|
|
|
+ try {
|
|
|
|
+ file = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
|
|
|
|
+ String destUrl = file.getPath();
|
|
|
|
+ // 签到表
|
|
|
|
+ if (ClassifyEnum.SIGN.equals(classifyEnum)) {
|
|
|
|
+ if (StringUtils.isBlank(basicTemplate.getPreviewPath())) {
|
|
|
|
+ JSONObject json = PdfFillUtils.parseSignTempData(basicTemplate.getDisplayRange(), destUrl);
|
|
|
|
+ json = this.getPreviewPath(json, pdfDirName, file);
|
|
|
|
+ basicTemplate.setPreviewPath(JSON.toJSONString(json));
|
|
|
|
+ basicTemplateMapper.updateById(basicTemplate);
|
|
|
|
+ }
|
|
|
|
+ return basicTemplate.getPreviewPath() == null ? null : teachcloudCommonService.filePreview(basicTemplate.getPreviewPath());
|
|
|
|
+ } else if (ClassifyEnum.PACKAGE.equals(classifyEnum)) {
|
|
|
|
+ if (StringUtils.isBlank(basicTemplate.getPreviewPath())) {
|
|
|
|
+ JSONObject json = PdfFillUtils.packageTempData(basicTemplate.getDisplayRange(), destUrl);
|
|
|
|
+ json = this.getPreviewPath(json, pdfDirName, file);
|
|
|
|
+ basicTemplate.setPreviewPath(JSON.toJSONString(json));
|
|
|
|
+ basicTemplateMapper.updateById(basicTemplate);
|
|
|
|
+ }
|
|
|
|
+ return basicTemplate.getPreviewPath() == null ? null : teachcloudCommonService.filePreview(basicTemplate.getPreviewPath());
|
|
|
|
+ } else if (ClassifyEnum.CHECK_IN.equals(classifyEnum)) {
|
|
|
|
+ BasicAttachment attachment = basicAttachmentService.getById(basicTemplate.getAttachmentId());
|
|
|
|
+ return attachment == null ? null : teachcloudCommonService.filePreview(attachment.getPath());
|
|
|
|
+ } else {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("不支持当前模板预览");
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ if (Objects.nonNull(file)) {
|
|
|
|
+ file.delete();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
|
|
- // 签到表
|
|
|
|
- if (ClassifyEnum.SIGN.equals(classifyEnum)) {
|
|
|
|
- if (StringUtils.isBlank(basicTemplate.getPreviewPath())) {
|
|
|
|
- JSONObject json = PdfFillUtils.parseSignTempData(basicTemplate.getDisplayRange(), destUrl);
|
|
|
|
- basicTemplate.setPreviewPath(JSON.toJSONString(json));
|
|
|
|
- basicTemplateMapper.updateById(basicTemplate);
|
|
|
|
- }
|
|
|
|
- return basicTemplate.getPreviewPath() == null ? null : teachcloudCommonService.filePreview(basicTemplate.getPreviewPath());
|
|
|
|
- } else if (ClassifyEnum.PACKAGE.equals(classifyEnum)) {
|
|
|
|
- if (StringUtils.isBlank(basicTemplate.getPreviewPath())) {
|
|
|
|
- JSONObject json = PdfFillUtils.packageTempData(basicTemplate.getDisplayRange(), destUrl);
|
|
|
|
- basicTemplate.setPreviewPath(JSON.toJSONString(json));
|
|
|
|
- basicTemplateMapper.updateById(basicTemplate);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取预览路径
|
|
|
|
+ *
|
|
|
|
+ * @param json
|
|
|
|
+ * @param pdfDirName
|
|
|
|
+ * @param file
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ private JSONObject getPreviewPath(JSONObject json, String pdfDirName, File file) throws Exception {
|
|
|
|
+ boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
|
+ if (Objects.nonNull(json) && !StringUtils.isBlank(json.getString(SystemConstant.PATH))) {
|
|
|
|
+ if (oss) {
|
|
|
|
+ fileStoreUtil.ossUpload(pdfDirName, file, DigestUtils.md5Hex(new FileInputStream(file)), fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
|
|
|
|
+ json.put(SystemConstant.PATH, pdfDirName);
|
|
|
|
+ } else {
|
|
|
|
+ if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
|
+ String destUrl = dictionaryConfig.fssLocalPdfDomain().getConfig() + File.separator + pdfDirName;
|
|
|
|
+ File newFile = new File(destUrl);
|
|
|
|
+ if (!newFile.exists()) {
|
|
|
|
+ newFile.getParentFile().mkdirs();
|
|
|
|
+ newFile.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ FileUtils.copyFile(file, newFile);
|
|
|
|
+ json.put(SystemConstant.PATH, destUrl);
|
|
|
|
+ } else {
|
|
|
|
+ fileStoreUtil.ossUpload(pdfDirName, file, DigestUtils.md5Hex(new FileInputStream(file)), fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
|
|
|
|
+ json.put(SystemConstant.PATH, pdfDirName);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return basicTemplate.getPreviewPath() == null ? null : teachcloudCommonService.filePreview(basicTemplate.getPreviewPath());
|
|
|
|
- } else if (ClassifyEnum.CHECK_IN.equals(classifyEnum)) {
|
|
|
|
- BasicAttachment attachment = basicAttachmentService.getById(basicTemplate.getAttachmentId());
|
|
|
|
- return attachment == null ? null : teachcloudCommonService.filePreview(attachment.getPath());
|
|
|
|
- } else {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("不支持当前模板预览");
|
|
|
|
}
|
|
}
|
|
|
|
+ return json;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|