|
|
|
|
@ -8,8 +8,11 @@ import com.da.common.utils.file.FileUtils;
|
|
|
|
|
import com.da.dangan.domain.DaPicturesRecard;
|
|
|
|
|
import com.da.dangan.service.IDaCzrkdjService;
|
|
|
|
|
import com.da.dangan.service.IDaPicturesRecardService;
|
|
|
|
|
import com.da.dangan.util.CallThirdInterface;
|
|
|
|
|
import com.da.framework.config.ServerConfig;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
@ -38,14 +41,15 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
private IDaCzrkdjService daCzrkdjService;
|
|
|
|
|
|
|
|
|
|
private static final String FILE_DELIMETER = ",";
|
|
|
|
|
@Value("${ocr.url}")
|
|
|
|
|
private String url;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上传(单个)
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/save")
|
|
|
|
|
public AjaxResult save(@RequestPart("file")MultipartFile file, @RequestPart("picRecard")DaPicturesRecard picRecard)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
public AjaxResult save(@RequestPart("file") MultipartFile file, @RequestPart("picRecard") DaPicturesRecard picRecard) {
|
|
|
|
|
try {
|
|
|
|
|
// 上传文件路径
|
|
|
|
|
String filePath = RuoYiConfig.getUploadPath();
|
|
|
|
|
// 上传并返回新文件名称
|
|
|
|
|
@ -57,15 +61,13 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
picRecard.setCreateBy(getUsername());
|
|
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
|
|
daPicturesRecardService.insertDaPicturesRecard(picRecard);
|
|
|
|
|
ajax.put("data",picRecard);
|
|
|
|
|
ajax.put("data", picRecard);
|
|
|
|
|
/*ajax.put("url", url);
|
|
|
|
|
ajax.put("fileName", fileName);
|
|
|
|
|
ajax.put("newFileName", FileUtils.getName(fileName));
|
|
|
|
|
ajax.put("originalFilename", file.getOriginalFilename());*/
|
|
|
|
|
return ajax;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -74,10 +76,8 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
* 通用上传(单个/多个)
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/saves")
|
|
|
|
|
public AjaxResult saves(@RequestPart("files")MultipartFile[] files,@RequestPart("picRecard") DaPicturesRecard picRecard) throws Exception
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{ //数据存储
|
|
|
|
|
public AjaxResult saves(@RequestPart("files") MultipartFile[] files, @RequestPart("picRecard") DaPicturesRecard picRecard) throws Exception {
|
|
|
|
|
try { //数据存储
|
|
|
|
|
List<DaPicturesRecard> picRecards = new ArrayList<>();
|
|
|
|
|
// 上传文件路径
|
|
|
|
|
String filePath = RuoYiConfig.getUploadPath();
|
|
|
|
|
@ -85,8 +85,7 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
List<String> fileNames = new ArrayList<String>();
|
|
|
|
|
List<String> newFileNames = new ArrayList<String>();
|
|
|
|
|
List<String> originalFilenames = new ArrayList<String>();
|
|
|
|
|
for (MultipartFile file : files)
|
|
|
|
|
{
|
|
|
|
|
for (MultipartFile file : files) {
|
|
|
|
|
//
|
|
|
|
|
DaPicturesRecard newPicRecard = new DaPicturesRecard();
|
|
|
|
|
|
|
|
|
|
@ -95,8 +94,8 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
String url = serverConfig.getUrl() + fileName;
|
|
|
|
|
|
|
|
|
|
// 添加水印
|
|
|
|
|
String updatedFilePath = removePathBeforeSecondSlash(fileName);
|
|
|
|
|
String watermarkFilePath = addWatermark(filePath + updatedFilePath);
|
|
|
|
|
/*String updatedFilePath = removePathBeforeSecondSlash(fileName);
|
|
|
|
|
String watermarkFilePath = addWatermark(filePath + updatedFilePath);*/
|
|
|
|
|
|
|
|
|
|
urls.add(url);
|
|
|
|
|
fileNames.add(fileName);
|
|
|
|
|
@ -110,6 +109,7 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
newPicRecard.setMuPath(picRecard.getMuPath());
|
|
|
|
|
newPicRecard.setWlsjId(picRecard.getWlsjId());
|
|
|
|
|
newPicRecard.setWlsjPath(picRecard.getWlsjPath());
|
|
|
|
|
newPicRecard.setYwType(picRecard.getYwType());
|
|
|
|
|
daPicturesRecardService.insertDaPicturesRecard(newPicRecard);
|
|
|
|
|
picRecards.add(newPicRecard);
|
|
|
|
|
}
|
|
|
|
|
@ -118,66 +118,36 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
|
|
|
|
|
ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
|
|
|
|
|
ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));*/
|
|
|
|
|
ajax.put("data",picRecards);
|
|
|
|
|
return ajax;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 测试添加水印
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/tests")
|
|
|
|
|
public AjaxResult tests(MultipartFile[] files) throws Exception
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{ //数据存储
|
|
|
|
|
List<DaPicturesRecard> picRecards = new ArrayList<>();
|
|
|
|
|
// 上传文件路径
|
|
|
|
|
String filePath = RuoYiConfig.getUploadPath();
|
|
|
|
|
for (MultipartFile file : files)
|
|
|
|
|
{
|
|
|
|
|
// 上传并返回新文件名称
|
|
|
|
|
String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
|
|
String url = serverConfig.getUrl() + fileName;
|
|
|
|
|
// 添加水印
|
|
|
|
|
String updatedFilePath = removePathBeforeSecondSlash(fileName);
|
|
|
|
|
String watermarkFilePath = addWatermark(filePath + updatedFilePath);
|
|
|
|
|
}
|
|
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
|
|
ajax.put("data", picRecards);
|
|
|
|
|
return ajax;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 调用识别接口
|
|
|
|
|
* 调用ocr识别接口——识别单张图片为一条记录
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/recongnize")
|
|
|
|
|
public AjaxResult recognize(@RequestBody DaPicturesRecard[] picRecards){
|
|
|
|
|
public AjaxResult recognize(@RequestBody DaPicturesRecard[] picRecards) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
//获取所有的文件
|
|
|
|
|
List<File> files = new ArrayList<>();
|
|
|
|
|
for (DaPicturesRecard picRecard : picRecards) {
|
|
|
|
|
File file = new File(picRecard.getPicUrl());
|
|
|
|
|
String path = getPath(picRecard.getPicUrl());
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
files.add(file);
|
|
|
|
|
}
|
|
|
|
|
// TODO 调用第三方接口识别信息
|
|
|
|
|
//String result= CallThirdInterface.callThirdInterface1();
|
|
|
|
|
//String result= CallThirdInterface.callThirdInterface("url",files);
|
|
|
|
|
String result = CallThirdInterface.callThirdInterface(url, files, "option1");
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
// TODO 根据业务类型存储识别后的信息
|
|
|
|
|
//daCzrkdjService.insertDaCzrkdj();
|
|
|
|
|
|
|
|
|
|
//修改图片信息记录表为已识别
|
|
|
|
|
for(DaPicturesRecard picRecard:picRecards){
|
|
|
|
|
//识别成功的图片 ,修改图片信息记录表为已识别
|
|
|
|
|
for (DaPicturesRecard picRecard : picRecards) {
|
|
|
|
|
picRecard.setRecognize("1");
|
|
|
|
|
daPicturesRecardService.updateDaPicturesRecard(picRecard);
|
|
|
|
|
}
|
|
|
|
|
@ -185,17 +155,68 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AjaxResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 图片批量识别处理进度
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/progress")
|
|
|
|
|
public ResponseEntity<Double> getProgress() {
|
|
|
|
|
|
|
|
|
|
//调用第三方进度条接口
|
|
|
|
|
|
|
|
|
|
// 返回进度值,例如:0.5代表50%
|
|
|
|
|
return ResponseEntity.ok(0.5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 测试第三方接口
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/test")
|
|
|
|
|
public String test(@RequestParam("files[]") MultipartFile[] files, @RequestParam("fileType") String fileType) throws Exception {
|
|
|
|
|
List<File> fileList = new ArrayList<>();
|
|
|
|
|
for (MultipartFile multipartFile : files) {
|
|
|
|
|
// 使用multipartFile的transferTo方法保存到临时文件
|
|
|
|
|
File file = new File(multipartFile.getOriginalFilename());
|
|
|
|
|
multipartFile.transferTo(file);
|
|
|
|
|
fileList.add(file);
|
|
|
|
|
}
|
|
|
|
|
String result = CallThirdInterface.callThirdInterface(url, fileList, fileType);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 测试添加水印
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/test_water")
|
|
|
|
|
public AjaxResult tests(MultipartFile[] files) throws Exception {
|
|
|
|
|
try { //数据存储
|
|
|
|
|
List<DaPicturesRecard> picRecards = new ArrayList<>();
|
|
|
|
|
// 上传文件路径
|
|
|
|
|
String filePath = RuoYiConfig.getUploadPath();
|
|
|
|
|
for (MultipartFile file : files) {
|
|
|
|
|
// 上传并返回新文件名称
|
|
|
|
|
String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
|
|
String url = serverConfig.getUrl() + fileName;
|
|
|
|
|
// 添加水印
|
|
|
|
|
String updatedFilePath = removePathBeforeSecondSlash(fileName);
|
|
|
|
|
String watermarkFilePath = addWatermark(filePath + updatedFilePath);
|
|
|
|
|
}
|
|
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
|
|
return ajax;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除第二个斜杠之前的路径
|
|
|
|
|
*
|
|
|
|
|
* @param filePath
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String removePathBeforeSecondSlash(String filePath)
|
|
|
|
|
{
|
|
|
|
|
private String removePathBeforeSecondSlash(String filePath) {
|
|
|
|
|
int count = 0;
|
|
|
|
|
int index = -1;
|
|
|
|
|
for (int i = 0; i < filePath.length(); i++) {
|
|
|
|
|
@ -212,16 +233,17 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
}
|
|
|
|
|
return filePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加水印
|
|
|
|
|
*
|
|
|
|
|
* @param filePath
|
|
|
|
|
* @return
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
private String addWatermark(String filePath) throws IOException
|
|
|
|
|
{ //获取文件后缀
|
|
|
|
|
private String addWatermark(String filePath) throws IOException { //获取文件后缀
|
|
|
|
|
int indexNum = filePath.lastIndexOf(".");
|
|
|
|
|
String fileExtension = filePath.substring(indexNum+1);
|
|
|
|
|
String fileExtension = filePath.substring(indexNum + 1);
|
|
|
|
|
|
|
|
|
|
BufferedImage image = ImageIO.read(new File(filePath));
|
|
|
|
|
/*int h = bufferedImage.getHeight();
|
|
|
|
|
@ -247,8 +269,8 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
g2d.rotate(-Math.toRadians(myDegree), (double) image.getWidth() / 2, (double) image.getHeight() / 2);
|
|
|
|
|
|
|
|
|
|
//设置水印位置
|
|
|
|
|
int x = (image.getWidth() - g2d.getFontMetrics().stringWidth(watermark)) /2;
|
|
|
|
|
int y = image.getHeight()/2;
|
|
|
|
|
int x = (image.getWidth() - g2d.getFontMetrics().stringWidth(watermark)) / 2;
|
|
|
|
|
int y = image.getHeight() / 2;
|
|
|
|
|
g2d.drawString(watermark, x, y);
|
|
|
|
|
|
|
|
|
|
// 保存添加水印后的图片,覆盖原始图片
|
|
|
|
|
@ -258,5 +280,11 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
return filePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getPath(String path) {
|
|
|
|
|
String profile = RuoYiConfig.getUploadPath();
|
|
|
|
|
int i = path.indexOf("upload");
|
|
|
|
|
String filePath = profile + path.substring(i + 6);
|
|
|
|
|
return filePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|