|
|
package com.example.serviceImpl;
|
|
|
|
|
|
import com.example.db1.dao.ArchiveDetailDao;
|
|
|
import com.example.db1.dao.CommonTableDao;
|
|
|
import com.example.dto.UpIsPdfDto;
|
|
|
import com.example.service.QualityService;
|
|
|
import com.example.util.ListUtil;
|
|
|
import com.example.vo.ArchiveDetailVo;
|
|
|
import com.example.vo.QualityVo;
|
|
|
import io.swagger.annotations.ApiModelProperty;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.ListUtils;
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
import org.apache.pdfbox.text.PDFTextStripper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.management.remote.rmi._RMIConnection_Stub;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @ClassName QualityServiceImpl
|
|
|
* @Description 连州质检业务层
|
|
|
* @Author linjj
|
|
|
* @Date 2025/1/14 15:30
|
|
|
* @Version 1.0
|
|
|
*/
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class QualityServiceImpl implements QualityService {
|
|
|
|
|
|
@Autowired
|
|
|
private CommonTableDao commonTableDao;
|
|
|
@Autowired
|
|
|
private ArchiveDetailDao archiveDetailDao;
|
|
|
|
|
|
@Override
|
|
|
public Boolean Quality() {
|
|
|
try {
|
|
|
//查询所有需要质检的主键id
|
|
|
List<QualityVo> commonTableList = commonTableDao.getCommonTableId();
|
|
|
//masterIds集合
|
|
|
List<String> masterIdList = ListUtil.distinctSelect(commonTableList, QualityVo::getPatientId);
|
|
|
//每次取出100条
|
|
|
List<List<String>> batchList = ListUtils.partition(masterIdList, 100);
|
|
|
//记录CommonTable表中isPdf字段,1代表没有内容,0表示有内容
|
|
|
List<UpIsPdfDto> isPdfs = new ArrayList<>();
|
|
|
//循环执行所有批次
|
|
|
for (List<String> masterIds : batchList) {
|
|
|
//循环执行本次批次中所有的masterId
|
|
|
for (String masterId : masterIds) {
|
|
|
log.info("开始质检的id为:" + masterId);
|
|
|
UpIsPdfDto upIsPdfDto = new UpIsPdfDto();
|
|
|
//查询是否存在图像
|
|
|
List<String> pdfPaths = archiveDetailDao.getPdfPath(masterId);
|
|
|
//如果大于100条记录属于问题病案
|
|
|
if (pdfPaths.size() > 100) {
|
|
|
//记录CommonTable表中isPdf字段,1代表没有内容,0表示有内容
|
|
|
upIsPdfDto.setPatientId(masterId);
|
|
|
upIsPdfDto.setIsPdf(1);
|
|
|
isPdfs.add(upIsPdfDto);
|
|
|
log.info("病案主键id为:" + masterId + "文件里超过100条记录");
|
|
|
} else if (!pdfPaths.isEmpty() && pdfPaths.size() < 100) {
|
|
|
//查询所有文件是否可以正常使用返回false为pdf存在问题
|
|
|
if (!isPDFValid(pdfPaths)) {
|
|
|
//记录CommonTable表中isPdf字段,1代表没有内容,0表示有内容
|
|
|
upIsPdfDto.setPatientId(masterId);
|
|
|
upIsPdfDto.setIsPdf(1);
|
|
|
isPdfs.add(upIsPdfDto);
|
|
|
log.info("病案主键id为:" + masterId + "没有文件图像异常");
|
|
|
} else {
|
|
|
//记录CommonTable表中isPdf字段,1代表没有内容,0表示有内容
|
|
|
upIsPdfDto.setPatientId(masterId);
|
|
|
upIsPdfDto.setIsPdf(0);
|
|
|
isPdfs.add(upIsPdfDto);
|
|
|
}
|
|
|
} else if (pdfPaths.isEmpty()) {
|
|
|
//记录CommonTable表中isPdf字段,1代表没有内容,0表示有内容
|
|
|
upIsPdfDto.setPatientId(masterId);
|
|
|
upIsPdfDto.setIsPdf(1);
|
|
|
isPdfs.add(upIsPdfDto);
|
|
|
log.info("病案主键id为:" + masterId + "没有文件图像信息");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//修改CommonTable表中isPdf字段
|
|
|
commonTableDao.updateIsPDFByIds(isPdfs);
|
|
|
log.info("执行完成:" + masterIds.size() + "条数据");
|
|
|
//清空isPdfs中数据
|
|
|
isPdfs.clear();
|
|
|
}
|
|
|
log.info("质检完成");
|
|
|
} catch (Exception e) {
|
|
|
log.error("系统异常处理" + e, e.getMessage());
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @description: 质检方法
|
|
|
* @params: filePath
|
|
|
* @return: boolean
|
|
|
* @author linjj
|
|
|
* @date: 2025/1/14 16:12
|
|
|
*/
|
|
|
public boolean isPDFValid(List<String> filePaths) {
|
|
|
for (String filePath : filePaths) {
|
|
|
File file = new File(filePath);
|
|
|
if (!file.exists()) {
|
|
|
return false;
|
|
|
}
|
|
|
try (PDDocument document = PDDocument.load(file)) {
|
|
|
// 检查PDF文件的页数
|
|
|
int numberOfPages = document.getNumberOfPages();
|
|
|
if (numberOfPages <= 0) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 尝试读取每一页的内容
|
|
|
PDFTextStripper pdfTextStripper = new PDFTextStripper();
|
|
|
for (int i = 0; i < numberOfPages; i++) {
|
|
|
String text = pdfTextStripper.getText(document);
|
|
|
if (text == null || text.isEmpty()) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
}
|