图片获取

devhuozheluoji
郭向斌 2 years ago
parent 569ba606d6
commit 1f816de796

@ -1,5 +1,6 @@
package org.jeecg.modules.api.controller;
import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -8,13 +9,18 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.ModuleType;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.*;
import org.jeecg.modules.message.entity.Req;
import org.jeecg.modules.ocr.entity.OcrIdentify;
import org.jeecg.modules.ocr.entity.OcrIdentifyDetail;
import org.jeecg.modules.ocr.entity.OcrRuleCheck;
@ -27,19 +33,32 @@ import org.jeecg.modules.ocr.utils.FileOUtils;
import org.jeecg.modules.ocr.utils.ImageUtils;
import org.jeecg.modules.ocr.dto.OcrIdentifyDTO;
import org.jeecg.modules.ocr.dto.OcrRuleCheckDTO;
import org.jeecg.modules.system.entity.SysFiles;
import org.jeecg.modules.system.service.ISysDictService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.io.*;
import java.net.URLEncoder;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Description
@ -66,6 +85,69 @@ public class ApiController {
@Value("${system.project.wlyCallback}")
private String wlyCallback;
@ApiOperation(value = "通用识别")
@RequestMapping("/getRequestIdsImage")
@Transactional
@ResponseBody
@AutoLog(value = "api接口-获取问题图片",logType = CommonConstant.LOG_TYPE_2,operateType=CommonConstant.OPERATE_TYPE_1)
public Result<?> getRequestIdsIamge(HttpServletRequest request,String dowPath,String zipPath, HttpServletResponse response) throws Exception {
String sss=dowPath;
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
params.setTitleRows(0);
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<Req> list = ExcelImportUtil.importExcel(file.getInputStream(), Req.class, params);
log.info("导入");
ArrayList<OcrIdentify> ocrIdentifies = new ArrayList<>();
for(Req s:list){
LambdaQueryWrapper<OcrIdentify> lambdaQueryWrapper=new LambdaQueryWrapper<>();
lambdaQueryWrapper.like(OcrIdentify::getRequestId,s.getRequestId());
log.info("查询数据:{}",s.getRequestId());
List<OcrIdentify> list1 = ocrIdentifyService.list(lambdaQueryWrapper);
log.info("查询数据:{}",list1);
ocrIdentifies.addAll(list1);
}
List<String> collect = ocrIdentifies.stream().map(OcrIdentify::getId).collect(Collectors.toList());
List<OcrIdentifyDetail> list2 = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().in(OcrIdentifyDetail::getIdentifyId, collect));
List<String> collect1 = list2.stream().map(OcrIdentifyDetail::getThumbnailImageUrl).distinct().collect(Collectors.toList());
for(String url:collect1){
File file2=new File(url);
String name = file2.getName();
String dow=dowPath+"/"+name;
File file3=new File(dow);
// if(!file3.exists()){
// file3.mkdir();
// }
try{
FileUtils.copyFile(file2,file3);
}catch (Exception e){
log.warn(e.getMessage());
}
}
File zip = ZipUtil.zip(sss, zipPath + "/" + new Date().getTime() + ".zip");
return Result.ok("文件导入成功!数据行数:" + list.size());
} catch (Exception e) {
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
String msg = e.getMessage();
log.error(msg, e);
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.OK();
}
@ApiOperation(value = "通用识别")
@RequestMapping("/identify")
@Transactional
@ResponseBody

@ -0,0 +1,17 @@
package org.jeecg.modules.message.entity;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
/**
* @Title:
* @Description:
* @Author
* @Date 2023-11-09 22:40
* @Version V1.0
*/
@Data
public class Req {
@Excel(name= "requestId")
String requestId;
}

@ -33,7 +33,8 @@ import java.util.stream.Collectors;
*/
@Configuration
@Slf4j
public class HandleCallbacklnit implements ApplicationRunner {
public class HandleCallbacklnit {
//public class HandleCallbacklnit implements ApplicationRunner {
@Resource
RedisUtil redisUtil;
@ -48,7 +49,7 @@ public class HandleCallbacklnit implements ApplicationRunner {
/**
* @param args
*/
@Override
// @Override
@Async
public void run(ApplicationArguments args) throws UnknownHostException {
log.info("---------------------回调任务开启{}---------------------",enableHandleTask);

@ -34,7 +34,8 @@ import java.util.List;
*/
@Configuration
@Slf4j
public class HandleTaskInit implements ApplicationRunner {
public class HandleTaskInit{
// implements ApplicationRunner {
@Resource
IOcrIdentifyService ocrIdentifyService;
@Resource
@ -48,7 +49,7 @@ public class HandleTaskInit implements ApplicationRunner {
@Value("${system.project.enableHandleTask}")
private boolean enableHandleTask;
@Override
// @Override
@Async
public void run(ApplicationArguments args) throws Exception {
if(enableHandleTask){

@ -1,5 +1,5 @@
server:
port: 8020
port: 8088
tomcat:
max-swallow-size: -1
error:
@ -152,6 +152,9 @@ spring:
# host: 47.103.213.109
port: 6379
password: ''
tess4j:
data-path: D:\workspace\ocr\data\tess4jdata
language: chi_sim
#mybatis plus 设置
mybatis-plus:
mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml

@ -3,4 +3,4 @@ spring:
name: jeecg-system
profiles:
# active: '@profile.name@'
active: dev
active: prod
Loading…
Cancel
Save