|
|
|
|
@ -13,7 +13,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@ -89,6 +93,11 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
// 上传并返回新文件名称
|
|
|
|
|
String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
|
|
String url = serverConfig.getUrl() + fileName;
|
|
|
|
|
|
|
|
|
|
// 添加水印
|
|
|
|
|
String updatedFilePath = removePathBeforeSecondSlash(fileName);
|
|
|
|
|
String watermarkFilePath = addWatermark(filePath + updatedFilePath);
|
|
|
|
|
|
|
|
|
|
urls.add(url);
|
|
|
|
|
fileNames.add(fileName);
|
|
|
|
|
newFileNames.add(FileUtils.getName(fileName));
|
|
|
|
|
@ -98,6 +107,7 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
newPicRecard.setPicUrl(url);
|
|
|
|
|
newPicRecard.setCreateBy(getUsername());
|
|
|
|
|
newPicRecard.setMuId(picRecard.getMuId());
|
|
|
|
|
newPicRecard.setMuPath(picRecard.getMuPath());
|
|
|
|
|
newPicRecard.setWlsjId(picRecard.getWlsjId());
|
|
|
|
|
newPicRecard.setWlsjPath(picRecard.getWlsjPath());
|
|
|
|
|
daPicturesRecardService.insertDaPicturesRecard(newPicRecard);
|
|
|
|
|
@ -116,6 +126,36 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
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();
|
|
|
|
|
return ajax;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return AjaxResult.error(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 调用识别接口
|
|
|
|
|
@ -131,8 +171,9 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
files.add(file);
|
|
|
|
|
}
|
|
|
|
|
// TODO 调用第三方接口识别信息
|
|
|
|
|
//String result= CallThirdInterface.callThirdInterface1();
|
|
|
|
|
//String result= CallThirdInterface.callThirdInterface("url",files);
|
|
|
|
|
// TODO 存储识别后的信息
|
|
|
|
|
// TODO 根据业务类型存储识别后的信息
|
|
|
|
|
//daCzrkdjService.insertDaCzrkdj();
|
|
|
|
|
|
|
|
|
|
//修改图片信息记录表为已识别
|
|
|
|
|
@ -148,7 +189,74 @@ public class DangAnCollectController extends BaseController {
|
|
|
|
|
return AjaxResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除第二个斜杠之前的路径
|
|
|
|
|
* @param filePath
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String removePathBeforeSecondSlash(String filePath)
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
int index = -1;
|
|
|
|
|
for (int i = 0; i < filePath.length(); i++) {
|
|
|
|
|
if (filePath.charAt(i) == '/') {
|
|
|
|
|
count++;
|
|
|
|
|
if (count == 3) {
|
|
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
return filePath.substring(index);
|
|
|
|
|
}
|
|
|
|
|
return filePath;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 添加水印
|
|
|
|
|
* @param filePath
|
|
|
|
|
* @return
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
private String addWatermark(String filePath) throws IOException
|
|
|
|
|
{ //获取文件后缀
|
|
|
|
|
int indexNum = filePath.lastIndexOf(".");
|
|
|
|
|
String fileExtension = filePath.substring(indexNum+1);
|
|
|
|
|
|
|
|
|
|
BufferedImage image = ImageIO.read(new File(filePath));
|
|
|
|
|
/*int h = bufferedImage.getHeight();
|
|
|
|
|
int w = bufferedImage.getWidth();
|
|
|
|
|
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB );*/
|
|
|
|
|
|
|
|
|
|
// 创建Graphics对象,并设置水印文字的样式
|
|
|
|
|
Graphics2D g2d = (Graphics2D) image.getGraphics();
|
|
|
|
|
Font font = new Font("微软雅黑", Font.BOLD, 45);
|
|
|
|
|
g2d.setFont(font);
|
|
|
|
|
//g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); // 设置透明度为50%
|
|
|
|
|
Color watermarkColor = new Color(147, 144, 144, 35);
|
|
|
|
|
//Color watermarkColor = new Color(155, 213, 222, 57);
|
|
|
|
|
g2d.setColor(watermarkColor);
|
|
|
|
|
// 在右下角添加水印
|
|
|
|
|
String watermark = "我是水印我是水印";
|
|
|
|
|
|
|
|
|
|
//设置水印旋转角度(默认对角线角度)
|
|
|
|
|
double lengthOfDiagonal = Math.sqrt(image.getWidth() * image.getWidth() + image.getHeight() * image.getHeight());
|
|
|
|
|
double v = (Math.pow(image.getWidth(), 2) + Math.pow(lengthOfDiagonal, 2) - Math.pow(image.getHeight(), 2)) / (2 * image.getWidth() * lengthOfDiagonal);
|
|
|
|
|
double acos = Math.acos(v);
|
|
|
|
|
double myDegree = Math.toDegrees(acos);
|
|
|
|
|
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;
|
|
|
|
|
g2d.drawString(watermark, x, y);
|
|
|
|
|
|
|
|
|
|
// 保存添加水印后的图片,覆盖原始图片
|
|
|
|
|
File output = new File(filePath);
|
|
|
|
|
ImageIO.write(image, fileExtension, output);
|
|
|
|
|
g2d.dispose();
|
|
|
|
|
return filePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|