增加处理联众图像逻辑

master
linjj 9 months ago
parent 51b49d5410
commit 2c0510d325

@ -189,4 +189,14 @@ public interface CommomMapper {
Integer getIsExistFileName(String fileName);
List<Map<String, Object>> queryFileManage();
/**
* @Author: linjj
* @Description:
* @DateTime: 2025/7/17` 11:29
* @Params: patientId
* @Return String
*/
List<String> getSourceBypatientId(String patientId);
}

@ -42,12 +42,14 @@ import javax.imageio.ImageIO;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.concurrent.*;
/**
@ -705,6 +707,8 @@ public class CommomService {
//查询通过审批且未过期的patientId集合
user = (Power_User) currentUser;
}
//查询是否为联众数据
List<String> source = commomMapper.getSourceBypatientId(patientId);
List<String> outs = new LinkedList<>();
if (StringUtils.isNotBlank(names)) {
String[] rootPathList = rootPaths.split(",");
@ -719,6 +723,34 @@ public class CommomService {
//获取是否打印用户信息
Short userEffective = emrPdfWaterSet.getUserEffective();
Integer roleId = user.getRoleId();
//<-------------------------------------------------判断是否为联众数据,不为空就为联众数据单独处理联众图像逻辑------------------------------------------------------>
if (!ObjectUtils.isEmpty(source)) {
for (int i = 0; i < nameList.length; i++) {
//目录
String rootPath = rootPathList[0];
//原图片地址
String srcPath = rootPath + File.separator + nameList[i];
//处理后的图片存在目录
String waterPicRoot = WATERPICPATH + patientId + File.separator + sourceList[i] + File.separator;
//目录不存在则创建
if (!new File(waterPicRoot).isDirectory()) {
new File(waterPicRoot).mkdirs();
}
//组织修改背景后图片存放地址
String waterPicPath = waterPicRoot + nameList[i];
//图像处理
waterLz(srcPath,waterPicPath);
//获取盘符
String root = selectRootByNotWater(WATERPICPATH);
//组织http地址
String outSrc = EMRRECORDJSP + File.separator + root + "/jiashi/reload/" + patientId + File.separator + sourceList[i] + File.separator + nameList[i];
outs.add(outSrc);
Integer value = Math.round((i + 1) * 100 / nameList.length);
printLoadingMap.put(mapKey, value);
return outs;
}
}
//<-------------------------------------------------单独处理联众图像逻辑------------------------------------------------------>
for (int i = 0; i < nameList.length; i++) {
//定义图片根目录地址
String rootPath = "";
@ -751,14 +783,7 @@ public class CommomService {
} else {
//需要水印
//组织加水印后图片存放目录
String waterPicRoot = WATERPICPATH + patientId + File.separator + sourceList[i] + File.separator;;
// if(srcPath.contains("/mnt/share") || srcPath.contains("/data")){
// waterPicRoot = "/data/jiashi/reload/"+ patientId + File.separator + sourceList[i] + File.separator;
// //waterPicRoot = "/mnt/share/jiashi/reload/"+ patientId + File.separator + sourceList[i] + File.separator;//D:/jiashi/reload/patientId/1/
// }else{
// waterPicRoot = WATERPICPATH + patientId + File.separator + sourceList[i] + File.separator;//D:/jiashi/reload/patientId/1/
// }
String waterPicRoot = WATERPICPATH + patientId + File.separator + sourceList[i] + File.separator;
//目录不存在则创建
if (!new File(waterPicRoot).isDirectory()) {
new File(waterPicRoot).mkdirs();
@ -810,55 +835,6 @@ public class CommomService {
root = selectRootByNotWater(WATERTIFTOJPGPATH);
outSrc = EMRRECORDJSP + File.separator + root + "/jiashi/tifToJpgLoad/" + format1 + ".jpg";
} else {
/*String driveLetterPath = srcPath.replaceAll("\\\\", "/");
if (driveLetterPath.startsWith("/")) {
String imageIpPath = "";//获取srcPath图像路径的ip
String localIP = getLocalIPAddress();//获取本机ip
//截取字符串为磁盘路径
int thirdBackslashIndex = driveLetterPath.indexOf('/', driveLetterPath.indexOf('/', driveLetterPath.indexOf('/') + 1) + 1);
if (thirdBackslashIndex != -1) {
imageIpPath = driveLetterPath.substring(2, thirdBackslashIndex);
driveLetterPath = driveLetterPath.substring(thirdBackslashIndex + 1);
}
//将原图片地址转换成映射地址
//获取盘符并转换映射地址的头部地址
root = selectRootByNotWater(driveLetterPath);
// 判断IP是否一致
if (imageIpPath.equals(localIP)) {
if (root == null) {
if(srcPath.contains(linuxPath)){
srcPath = srcPath.replace(linuxPath, "picShare");
outSrc = EMRRECORDJSP + File.separator + srcPath;
}else{
outSrc = srcPath;
}
} else {
//获取盘符后面的地址
picPath = driveLetterPath.substring(driveLetterPath.indexOf('/'));
outSrc = EMRRECORDJSP + File.separator + root + picPath;
}
} else {
if (root == null) {
if(srcPath.contains(linuxPath)){
srcPath = srcPath.replace(linuxPath, "picShare");
outSrc = EMRRECORDJSP + File.separator + srcPath;
}else{
outSrc = "http://" + imageIpPath + ":" + httpMapPort + File.separator + driveLetterPath;
}
} else {
//获取盘符后面的地址
picPath = driveLetterPath.substring(driveLetterPath.indexOf('/'));
outSrc = "http://" + imageIpPath + ":" + httpMapPort + File.separator + root + picPath;
}
}
} else {
root = selectRootByNotWater(driveLetterPath);
//获取盘符后面的地址
String str1 = driveLetterPath.substring(0, driveLetterPath.indexOf("/"));
picPath = driveLetterPath.substring(str1.length() + 1, driveLetterPath.length());
outSrc = EMRRECORDJSP + File.separator + root + picPath;
}*/
String driveLetterPath = srcPath.replaceAll("\\\\", "/");
if (driveLetterPath.startsWith("/")) {
//截取字符串为磁盘路径
@ -946,6 +922,7 @@ public class CommomService {
return null;
}
}
public String processImagePath(String rootPath, String name, String source, Power_User user, EmrPdfWaterSet emrPdfWaterSet, String patientId, String mapKey) throws IOException {
return "processed_" + name; // 示例返回值
@ -1127,6 +1104,54 @@ public class CommomService {
return outs;
}
/**
* @Author: linjj
* @Description:
* @DateTime: 2025/7/17 14:13
* @Params:
* @Return
*/
private boolean waterLz(String srcPath,String waterPicPath) {
try {
// 读取图像
File inputFile = new File(srcPath);
BufferedImage inputImage = ImageIO.read(inputFile);
// 转换为灰度图像
BufferedImage grayImage = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Graphics g = grayImage.getGraphics();
g.drawImage(inputImage, 0, 0, null);
g.dispose();
// 二值化处理
BufferedImage binaryImage = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_BYTE_BINARY);
for (int y = 0; y < grayImage.getHeight(); y++) {
for (int x = 0; x < grayImage.getWidth(); x++) {
int gray = grayImage.getRGB(x, y) & 0xFF;
// 设置阈值,根据文字深浅给阈值
if (gray < 200) {
binaryImage.setRGB(x, y, Color.BLACK.getRGB());
} else {
binaryImage.setRGB(x, y, Color.WHITE.getRGB());
}
}
}
// 创建一个新的白色背景图像
BufferedImage whiteImage = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_INT_RGB);
whiteImage.createGraphics().fillRect(0, 0, whiteImage.getWidth(), whiteImage.getHeight());
// 将二值化图像绘制到白色背景上
Graphics2D g2d = whiteImage.createGraphics();
g2d.drawImage(binaryImage, 0, 0, null);
g2d.dispose();
// 保存处理后的图像
File outputFile = new File(waterPicPath);
ImageIO.write(whiteImage, "jpg", outputFile);
System.out.println("图像处理完成并保存。");
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
/**
*
*

@ -1621,4 +1621,10 @@
b.scan_page scanPage
from commomtable a join t_scan_assort b on a.patient_id = b.patient_id join zd_assort c on b.assort_id = c.assort_id
</select>
<select id="getSourceBypatientId" resultType="java.lang.String">
select source from commomtable where patient_id = #{patientId} AND source='lz'
</select>
</mapper>
Loading…
Cancel
Save