|
@@ -1,9 +1,11 @@
|
|
|
package com.gz.job;
|
|
package com.gz.job;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.ReUtil;
|
|
import cn.hutool.core.util.ReUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.gz.config.FileUploadConfig;
|
|
import com.gz.config.FileUploadConfig;
|
|
|
import com.gz.config.MountArchiveFileConfig;
|
|
import com.gz.config.MountArchiveFileConfig;
|
|
|
import com.gz.core.exception.BusinessException;
|
|
import com.gz.core.exception.BusinessException;
|
|
@@ -16,13 +18,20 @@ import com.gz.mapper.archive.ArchiveFileMapper;
|
|
|
import com.gz.mapper.archive.ArchiveMapper;
|
|
import com.gz.mapper.archive.ArchiveMapper;
|
|
|
import com.gz.mapper.archive.SecondaryArchiveMapper;
|
|
import com.gz.mapper.archive.SecondaryArchiveMapper;
|
|
|
import com.gz.mapper.system.ArchivesTreeMapper;
|
|
import com.gz.mapper.system.ArchivesTreeMapper;
|
|
|
|
|
+import com.gz.rvo.archive.ArchiveRVO;
|
|
|
|
|
+import com.gz.vo.rabbitmq.OcrEtlVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
+import tk.mybatis.mapper.entity.Example;
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 挂挡文件
|
|
* 挂挡文件
|
|
@@ -49,6 +58,18 @@ public class MountArchiveFileJob {
|
|
|
@Resource
|
|
@Resource
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
|
|
|
|
+ @Value("${upload-file.server-file-url-prefix}")
|
|
|
|
|
+ private String serverFileUrlPrefix;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${rabbitmq.data-exchange}")
|
|
|
|
|
+ private String dataExchangeName;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${rabbitmq.ocr.queue-binding-key}")
|
|
|
|
|
+ private String ocrBindingKey;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RabbitTemplate rabbitTemplate;
|
|
|
|
|
+
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
|
public void handelPDFJob() {
|
|
public void handelPDFJob() {
|
|
|
log.info("[归档任务]初始化PDF文件归档任务线程");
|
|
log.info("[归档任务]初始化PDF文件归档任务线程");
|
|
@@ -69,31 +90,34 @@ public class MountArchiveFileJob {
|
|
|
key = String.format(MountArchiveFileConfig.ARCHIVE_FILE_MOUNT_ERROR_FOMAT, pdf.getName());
|
|
key = String.format(MountArchiveFileConfig.ARCHIVE_FILE_MOUNT_ERROR_FOMAT, pdf.getName());
|
|
|
// 判断是否在错误队列 错误队列跳过
|
|
// 判断是否在错误队列 错误队列跳过
|
|
|
if (!stringRedisTemplate.hasKey(key)) {
|
|
if (!stringRedisTemplate.hasKey(key)) {
|
|
|
- ArchiveDTO archiveDTO = new ArchiveDTO();
|
|
|
|
|
|
|
+ // 案卷dto
|
|
|
|
|
+ ArchiveRVO archiveRVO = new ArchiveRVO();
|
|
|
|
|
+ // 卷内目录dto
|
|
|
SecondaryArchiveDTO secondaryArchiveDTO = new SecondaryArchiveDTO();
|
|
SecondaryArchiveDTO secondaryArchiveDTO = new SecondaryArchiveDTO();
|
|
|
// 专业档案卷内目录 档号正则
|
|
// 专业档案卷内目录 档号正则
|
|
|
if (ReUtil.isMatch(MountArchiveFileConfig.ZY_DH_RE, dh)) {
|
|
if (ReUtil.isMatch(MountArchiveFileConfig.ZY_DH_RE, dh)) {
|
|
|
secondaryArchiveDTO.setDh(dh);
|
|
secondaryArchiveDTO.setDh(dh);
|
|
|
secondaryArchiveDTO = secondaryArchiveMapper.selectOne(secondaryArchiveDTO);
|
|
secondaryArchiveDTO = secondaryArchiveMapper.selectOne(secondaryArchiveDTO);
|
|
|
- archiveDTO = archiveMapper.selectByPrimaryKey(secondaryArchiveDTO.getArchiveId());
|
|
|
|
|
|
|
+ archiveRVO = archiveMapper.selectByPk(secondaryArchiveDTO.getArchiveId());
|
|
|
} else {
|
|
} else {
|
|
|
- archiveDTO.setDh(dh);
|
|
|
|
|
- archiveDTO = archiveMapper.selectOne(archiveDTO);
|
|
|
|
|
|
|
+ archiveRVO.setDh(dh);
|
|
|
|
|
+ archiveRVO = archiveMapper.selectByDh(archiveRVO.getDh());
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- if (archiveDTO == null) {
|
|
|
|
|
|
|
+ if (archiveRVO == null) {
|
|
|
throw new BusinessException(CustomExceptionEnum.ARCHIVE_DATA_NOT_EXISTS);
|
|
throw new BusinessException(CustomExceptionEnum.ARCHIVE_DATA_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
- ArchivesTreeDTO parentMl = archivesTreeMapper.selectParentByCode(archiveDTO.getMl());
|
|
|
|
|
- String mlDirectory = (parentMl == null) ? archiveDTO.getMl() : parentMl.getCode() + "/" + archiveDTO.getMl();
|
|
|
|
|
- String finallyPath = "/" + archiveDTO.getQzh() + "/" + archiveDTO.getGdnd() + "/" + mlDirectory + "/" + archiveDTO.getBgqx() + "/" + archiveDTO.getDh() + "/pdf/";
|
|
|
|
|
- FileUtil.copy(pdf, new File(FileUploadConfig.ARCHIVE_FILE_ROOT_DIRECTORY + finallyPath + name), false);
|
|
|
|
|
|
|
+ ArchivesTreeDTO parentMl = archivesTreeMapper.selectParentByCode(archiveRVO.getMl());
|
|
|
|
|
+ String mlDirectory = (parentMl == null) ? archiveRVO.getMl() : parentMl.getCode() + "/" + archiveRVO.getMl();
|
|
|
|
|
+ String finallyPath = "/" + archiveRVO.getQzh() + "/" + archiveRVO.getGdnd() + "/" + mlDirectory + "/" + archiveRVO.getBgqx() + "/" + archiveRVO.getDh() + "/pdf/";
|
|
|
|
|
+ FileUtil.copy(pdf, new File(FileUploadConfig.ARCHIVE_FILE_ROOT_DIRECTORY + finallyPath + name), true);
|
|
|
log.debug("复制文件:[{}]成功", name);
|
|
log.debug("复制文件:[{}]成功", name);
|
|
|
// 删除扫描成功文件
|
|
// 删除扫描成功文件
|
|
|
if (!FileUtil.del(pdf)) {
|
|
if (!FileUtil.del(pdf)) {
|
|
|
throw new BusinessException(CustomExceptionEnum.DEL_ORIGINAL_FILE_ERROR);
|
|
throw new BusinessException(CustomExceptionEnum.DEL_ORIGINAL_FILE_ERROR);
|
|
|
}
|
|
}
|
|
|
ArchiveFileDTO archiveFileDTO = new ArchiveFileDTO();
|
|
ArchiveFileDTO archiveFileDTO = new ArchiveFileDTO();
|
|
|
- archiveFileDTO.setArchiveId(archiveDTO.getId());
|
|
|
|
|
|
|
+ archiveFileDTO.setArchiveId(archiveRVO.getId());
|
|
|
if (ObjectUtil.isNotNull(secondaryArchiveDTO)) {
|
|
if (ObjectUtil.isNotNull(secondaryArchiveDTO)) {
|
|
|
archiveFileDTO.setSecondaryArchiveId(secondaryArchiveDTO.getId());
|
|
archiveFileDTO.setSecondaryArchiveId(secondaryArchiveDTO.getId());
|
|
|
}
|
|
}
|
|
@@ -102,8 +126,19 @@ public class MountArchiveFileJob {
|
|
|
archiveFileDTO.setFileSize(FileUtil.size(pdf));
|
|
archiveFileDTO.setFileSize(FileUtil.size(pdf));
|
|
|
archiveFileDTO.setFilePath(finallyPath);
|
|
archiveFileDTO.setFilePath(finallyPath);
|
|
|
archiveFileDTO.setFileType(0);
|
|
archiveFileDTO.setFileType(0);
|
|
|
- archiveFileMapper.insertSelective(archiveFileDTO);
|
|
|
|
|
|
|
+ if (archiveFileMapper.selectOne(archiveFileDTO) == null) {
|
|
|
|
|
+ archiveFileMapper.insertSelective(archiveFileDTO);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("有文件记录跳过");
|
|
|
|
|
+ }
|
|
|
// TODO: 2021/3/17 发送rabbitmq 队列消息
|
|
// TODO: 2021/3/17 发送rabbitmq 队列消息
|
|
|
|
|
+ if (ObjectUtil.isNotNull(archiveRVO)) {
|
|
|
|
|
+ OcrEtlVO ocrBean = BeanUtil.copyProperties(archiveRVO, OcrEtlVO.class);
|
|
|
|
|
+ ocrBean.setFileUrl(serverFileUrlPrefix + archiveFileDTO.getFilePath() + "/" + archiveFileDTO.getFileName());
|
|
|
|
|
+ ocrBean.setSecondaryArchiveId(secondaryArchiveDTO.getId());
|
|
|
|
|
+ log.info("【ocr识别】发起识别队列,参数[{}]", JSON.toJSONString(ocrBean));
|
|
|
|
|
+ rabbitTemplate.convertAndSend(dataExchangeName, ocrBindingKey, JSON.toJSONString(ocrBean));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("挂载出现错误:", e);
|
|
log.error("挂载出现错误:", e);
|
|
@@ -119,4 +154,22 @@ public class MountArchiveFileJob {
|
|
|
}
|
|
}
|
|
|
}).start();
|
|
}).start();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// @PostConstruct
|
|
|
|
|
+ public void testOcr(){
|
|
|
|
|
+ // TODO: 2021/5/7 提交已经归档但是未ocr识别的历史数据进行ocr识别
|
|
|
|
|
+ Example example = new Example(ArchiveFileDTO.class);
|
|
|
|
|
+ example.setOrderByClause("id ASC");
|
|
|
|
|
+ List<ArchiveFileDTO> archiveFileDTOS = archiveFileMapper.selectByExample(example);
|
|
|
|
|
+ for (int i = 0; i < archiveFileDTOS.size(); i++) {
|
|
|
|
|
+ ArchiveFileDTO archiveFileDTO = archiveFileDTOS.get(i);
|
|
|
|
|
+ ArchiveRVO archiveRVO = archiveMapper.selectByPk(archiveFileDTO.getArchiveId());
|
|
|
|
|
+ OcrEtlVO ocrBean = BeanUtil.copyProperties(archiveRVO, OcrEtlVO.class);
|
|
|
|
|
+ ocrBean.setSecondaryArchiveId(archiveFileDTO.getSecondaryArchiveId());
|
|
|
|
|
+ ocrBean.setFileUrl(serverFileUrlPrefix + archiveFileDTO.getFilePath() + "/" + archiveFileDTO.getFileName());
|
|
|
|
|
+ log.info("【ocr识别】发起识别队列,参数[{}]", JSON.toJSONString(ocrBean));
|
|
|
|
|
+ rabbitTemplate.convertAndSend(dataExchangeName, ocrBindingKey, JSON.toJSONString(ocrBean));
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("发送完成");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|