文档库--ocr识别调取已入库文件分页

This commit is contained in:
zhn
2022-02-28 15:37:17 +08:00
parent b829bf977a
commit 7caf351292
5 changed files with 153 additions and 24 deletions
@@ -117,6 +117,20 @@ public class BussDocumentLibraryEOController extends JeroController<BussDocument
return Result.OK(infoPage);
}
/**
* ocr识别调取已入库文件
* @param parameter
* @return
*/
@AutoLog(value = "ocr识别调取已入库文件分页")
@ApiOperation(value="ocr识别调取已入库文件", notes="ocr识别调取已入库文件")
@PostMapping(value = "/ocrPageInfo")
@ResponseBody
public Result<?> ocrPageInfo(@RequestBody Map<String,Object> parameter) {
IPage infoPage = bussDocumentLibraryEOService.ocrPageInfo(parameter);
return Result.OK(infoPage);
}
/**
* 列表查询
*
@@ -55,5 +55,17 @@ public interface BussDocumentLibraryEOMapper extends BaseMapper<BussDocumentLibr
@Param("field") String field,
@Param("condition") String condition);
/**
* ocr识别调取已入库文件分页
*
* @param page
* @param field
* @param condition
* @return
*/
IPage ocrPageInfo(@Param("page") IPage page,
@Param("field") String field,
@Param("condition") String condition);
}
@@ -54,5 +54,10 @@
select ${field} from buss_document_library
${condition}
</select>
<!--ocr识别调取已入库文件分页-->
<select id="ocrPageInfo" resultType="java.util.LinkedHashMap">
select ${field}
${condition}
</select>
</mapper>
@@ -110,6 +110,13 @@ public interface IBussDocumentLibraryEOService extends IService<BussDocumentLibr
*/
IPage replacePageInfo(Map<String,Object> parameter);
/**
* ocr识别调取已入库文件分页
* @param parameter
* @return
*/
IPage ocrPageInfo(Map<String,Object> parameter);
/**
* 添加收藏
* @param id
@@ -801,6 +801,93 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
return infoPage;
}
/**
* ocr识别调取已入库文件分页
*
* @param parameter
* @return
*/
public IPage ocrPageInfo(Map<String, Object> parameter) {
//需要查询的字段
List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList("1");
fieldList = fieldList.stream().filter(e -> FieldTypeEnum.FILE.getValue().equals(e.getFieldShowType())).collect(Collectors.toList());
List<String> fileFieldList = fieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
//查询字段
StringBuilder fieldSb = new StringBuilder();
StringBuilder join = new StringBuilder();
int i = 1;
if (ObjectUtils.isNotEmpty(fileFieldList)) {
for (String fileField : fileFieldList) {
fieldSb.append("bdl." + fileField + ",");
if (i == 1) {
join.append(" on of.connect_id = bdl." + fileField);
i++;
continue;
}
join.append(" or of.connect_id = bdl." + fileField);
}
}
String fieldStr = fieldSb.substring(0, fieldSb.length() - 1);
String field = " bdl.id,bdl.serial_number,bdl.title,bdl.state,of.file_name,of.connect_id," + fieldStr
+ " from oss_file of join buss_document_library bdl" + join.toString();
//查询条件
StringBuilder conditionSb = new StringBuilder("where 1 = 1");
//编码
String serialNumber = (String) parameter.get("serialNumber");
//标题
String title = (String) parameter.get("title");
if (StringUtils.isNotBlank(serialNumber)) {
conditionSb.append(" and " + "serial_number" + " like concat(concat('%','" + serialNumber + "'),'%')");
}
if (StringUtils.isNotBlank(title)) {
conditionSb.append(" and " + "title" + " like concat(concat('%','" + title + "'),'%')");
}
conditionSb.append(" order by bdl.create_time desc");
int pageNo = Integer.parseInt(parameter.get("pageNo").toString());
int pageSize = Integer.parseInt(parameter.get("pageSize").toString());
IPage page = new Page(pageNo, pageSize);
IPage infoPage = bussDocumentLibraryEOMapper.ocrPageInfo(page, field, conditionSb.toString());
List records = infoPage.getRecords();
//数据字典
List<SysDictItem> sysDictItems = sysDictItemServiceImpl.selectItemsAll();
//下拉选处理数据字典
for (Object record : records) {
Map<String, Object> record1 = (Map) record;
String key = "";
for (Map.Entry<String, Object> entry : record1.entrySet()) {
//状态数据字典
if ("state".equals(entry.getKey())) {
List<SysDictItem> stateList = sysDictItems.stream()
.filter(e -> StringUtils.isNotBlank(e.getDictCode()) && e.getDictCode().equals("state"))
.collect(Collectors.toList());
List<SysDictItem> state = stateList.stream().filter(e -> e.getItemValue().equals(entry.getValue())).collect(Collectors.toList());
if (state.size() != 0) {
entry.setValue(state.get(0).getItemText());
}
}
//添加文本信息
String connectId = (String) record1.get("connect_id");
if (connectId.equals(entry.getValue())) {
key = entry.getKey();
}
}
String finalKey = key;
List<OnlCgformField> onlCgformFieldList = fieldList.stream().filter(e -> e.getDbFieldName().equals(finalKey)).collect(Collectors.toList());
record1.put("text_info", onlCgformFieldList.get(0).getDbFieldTxt());
}
return infoPage;
}
public IPage getInfoPage(Map<String, Object> parameter) {
//需要查询的字段
List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList("1");
@@ -921,6 +1008,9 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
*/
private void collectAndSubscribe(List<Map> records, List<String> idList) {
//收藏
if (idList.size() == 0) {
return;
}
LambdaQueryWrapper<OnlCgformCollection> wrapper = new LambdaQueryWrapper<>();
wrapper.in(OnlCgformCollection::getDocumentId, idList);
List<OnlCgformCollection> collectList = iOnlCgformCollectionService.list(wrapper);
@@ -1092,7 +1182,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
&& !"sys_org_code".equals(e.getDbFieldName())
&& !"warn_flag".equals(e.getDbFieldName())).collect(Collectors.toList());
//只导出数据时,过滤掉文件类型
if(!"file".equals(flag)){
if (!"file".equals(flag)) {
fieldListTemp = fieldListTemp.stream().filter(e -> !FieldTypeEnum.FILE.getValue().equals(e.getFieldShowType())).collect(Collectors.toList());
}
headerFieldList = fieldListTemp.stream().map(OnlCgformField::getDbFieldTxt).collect(Collectors.toList());
@@ -1118,15 +1208,15 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
// 创建数据
createDatas(workbook, sheet, datas, header, fieldListTemp);
if(!"file".equals(flag)){
if (!"file".equals(flag)) {
//不带文件导出
os = response.getOutputStream();
workbook.write(os);
os.flush();
}else{
} else {
String path = uploadpath + "/tempZip";
File fileTemp = new File(path);
if (fileTemp.exists()){
if (fileTemp.exists()) {
fileTemp.delete();
}
fileTemp.mkdirs();
@@ -1142,34 +1232,34 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
List<String> fileFieldList = onlCgformFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
for (Map<String, Object> data : datas) {
if(StringUtils.isBlank((String) data.get("serial_number"))){
if (StringUtils.isBlank((String) data.get("serial_number"))) {
continue;
}
String fileNowPath = uploadpath + "/tempZip/" + (String) data.get("serial_number");
File file = new File(fileNowPath);
if (file.exists()){
if (file.exists()) {
file.delete();
}
file.mkdirs();
List<String> valueList = new ArrayList<>();
for (String field : fileFieldList) {
String value = (String) data.get(field);
if(StringUtils.isNotBlank(value)){
if (StringUtils.isNotBlank(value)) {
valueList.add(value);
}
}
//每一个编号下的所有的文件
if(valueList.size()!= 0){
if (valueList.size() != 0) {
List<OSSFile> fileInfosList = iOSSFileService.getFileInfosByConnectId(StringUtils.join(valueList, ","));
for (OSSFile ossFile : fileInfosList) {
String url = ossFile.getUrl();
copyFile(url, fileNowPath+ "/"+ossFile.getFileName());
copyFile(url, fileNowPath + "/" + ossFile.getFileName());
}
}
}
ZipUtil.zip(path,path+".zip");
ZipUtil.zip(path, path + ".zip");
//文件
FileInputStream fis = new FileInputStream(path+".zip");
FileInputStream fis = new FileInputStream(path + ".zip");
os = response.getOutputStream();
int len = 0;
@@ -1202,14 +1292,14 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
for (Map<String, Object> data : datas) {
for (OnlCgformField onlCgformField : fileFieldList) {
String value = (String) data.get(onlCgformField.getDbFieldName());
if(StringUtils.isNotBlank(value)){
if (StringUtils.isNotBlank(value)) {
connectIdList.add(value);
}
}
}
//所有的文件信息
List<OSSFile> fileInfos = new ArrayList<>();
if(connectIdList.size() != 0){
if (connectIdList.size() != 0) {
fileInfos = iOSSFileService.getFileInfosByConnectId(StringUtils.join(connectIdList, ","));
}
@@ -1233,20 +1323,20 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
if (ObjectUtils.isNotEmpty(data.get(onlCgformField.getDbFieldName()))) {
value = sdf.format(data.get(onlCgformField.getDbFieldName()));
}
}else if(FieldTypeEnum.FILE.getValue().equals(onlCgformField.getFieldShowType())){
} else if (FieldTypeEnum.FILE.getValue().equals(onlCgformField.getFieldShowType())) {
//处理文件名称(由connect_id转化为文件名)
if(fileInfos.size() != 0){
if (fileInfos.size() != 0) {
List<OSSFile> ossFileList = fileInfos.stream()
.filter(e -> e.getConnectId().equals(data.get(onlCgformField.getDbFieldName())))
.collect(Collectors.toList());
if(ossFileList.size()!= 0){
if (ossFileList.size() != 0) {
List<String> fileNameList = ossFileList.stream().map(OSSFile::getFileName).collect(Collectors.toList());
value = StringUtils.join(fileNameList,",");
}else{
value = StringUtils.join(fileNameList, ",");
} else {
value = "";
}
}
}else {
} else {
value = (String) data.get(onlCgformField.getDbFieldName());
}
row.createCell(sheetNum).setCellValue(value);
@@ -1300,6 +1390,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
/**
* 带文件导出
*
* @param map
* @param response
* @param request
@@ -1308,7 +1399,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
public void exportZip(Map<String, Object> map,
HttpServletResponse response,
HttpServletRequest request) {
exportExcel(map,response,request);
exportExcel(map, response, request);
}
@@ -1476,15 +1567,15 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
public static void copyFile(String oldFile, String newFile) throws IOException {
File file2 = new File(newFile);
if(!file2.exists()){
if (!file2.exists()) {
file2.createNewFile();
}
// file2.mkdir();
File temp = new File(oldFile );
File temp = new File(oldFile);
if (temp.isFile()) {
try(FileInputStream in = new FileInputStream(temp);
FileOutputStream ou = new FileOutputStream(newFile);) {
try (FileInputStream in = new FileInputStream(temp);
FileOutputStream ou = new FileOutputStream(newFile);) {
byte[] bs = new byte[1024];
int count = 0;