增加处理联众图像逻辑

master
linjj 9 months ago
parent 51b49d5410
commit 2c0510d325

@ -189,4 +189,14 @@ public interface CommomMapper {
Integer getIsExistFileName(String fileName); Integer getIsExistFileName(String fileName);
List<Map<String, Object>> queryFileManage(); 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.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.List;
import java.util.concurrent.*; import java.util.concurrent.*;
/** /**
@ -421,10 +423,10 @@ public class CommomService {
HttpServletRequest request = attributes.getRequest(); HttpServletRequest request = attributes.getRequest();
Power_User user; Power_User user;
Object currentUser = request.getSession().getAttribute("CURRENT_USER"); Object currentUser = request.getSession().getAttribute("CURRENT_USER");
if(ObjectUtils.isEmpty(currentUser)){ if (ObjectUtils.isEmpty(currentUser)) {
ServletContext context = request.getServletContext(); ServletContext context = request.getServletContext();
user = (Power_User)context.getAttribute("CURRENT_USER"); user = (Power_User) context.getAttribute("CURRENT_USER");
}else{ } else {
//查询通过审批且未过期的patientId集合 //查询通过审批且未过期的patientId集合
user = (Power_User) currentUser; user = (Power_User) currentUser;
} }
@ -698,13 +700,15 @@ public class CommomService {
// 从session获取用户名 // 从session获取用户名
Power_User user; Power_User user;
Object currentUser = request.getSession().getAttribute("CURRENT_USER"); Object currentUser = request.getSession().getAttribute("CURRENT_USER");
if(ObjectUtils.isEmpty(currentUser)){ if (ObjectUtils.isEmpty(currentUser)) {
ServletContext context = request.getServletContext(); ServletContext context = request.getServletContext();
user = (Power_User)context.getAttribute("CURRENT_USER"); user = (Power_User) context.getAttribute("CURRENT_USER");
}else{ } else {
//查询通过审批且未过期的patientId集合 //查询通过审批且未过期的patientId集合
user = (Power_User) currentUser; user = (Power_User) currentUser;
} }
//查询是否为联众数据
List<String> source = commomMapper.getSourceBypatientId(patientId);
List<String> outs = new LinkedList<>(); List<String> outs = new LinkedList<>();
if (StringUtils.isNotBlank(names)) { if (StringUtils.isNotBlank(names)) {
String[] rootPathList = rootPaths.split(","); String[] rootPathList = rootPaths.split(",");
@ -719,6 +723,34 @@ public class CommomService {
//获取是否打印用户信息 //获取是否打印用户信息
Short userEffective = emrPdfWaterSet.getUserEffective(); Short userEffective = emrPdfWaterSet.getUserEffective();
Integer roleId = user.getRoleId(); 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++) { for (int i = 0; i < nameList.length; i++) {
//定义图片根目录地址 //定义图片根目录地址
String rootPath = ""; String rootPath = "";
@ -751,14 +783,7 @@ public class CommomService {
} else { } else {
//需要水印 //需要水印
//组织加水印后图片存放目录 //组织加水印后图片存放目录
String waterPicRoot = WATERPICPATH + patientId + File.separator + sourceList[i] + File.separator;; 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/
// }
//目录不存在则创建 //目录不存在则创建
if (!new File(waterPicRoot).isDirectory()) { if (!new File(waterPicRoot).isDirectory()) {
new File(waterPicRoot).mkdirs(); new File(waterPicRoot).mkdirs();
@ -781,7 +806,7 @@ public class CommomService {
}else{ }else{
outSrc = EMRRECORDJSP + File.separator + root + "/jiashi/reload/" + patientId + File.separator + sourceList[i] + File.separator + nameList[i]; outSrc = EMRRECORDJSP + File.separator + root + "/jiashi/reload/" + patientId + File.separator + sourceList[i] + File.separator + nameList[i];
}*/ }*/
if(srcPath.contains(linuxPath)){ if (srcPath.contains(linuxPath)) {
root = "picShare"; root = "picShare";
} }
outSrc = EMRRECORDJSP + File.separator + root + "/jiashi/reload/" + patientId + File.separator + sourceList[i] + File.separator + nameList[i]; outSrc = EMRRECORDJSP + File.separator + root + "/jiashi/reload/" + patientId + File.separator + sourceList[i] + File.separator + nameList[i];
@ -810,55 +835,6 @@ public class CommomService {
root = selectRootByNotWater(WATERTIFTOJPGPATH); root = selectRootByNotWater(WATERTIFTOJPGPATH);
outSrc = EMRRECORDJSP + File.separator + root + "/jiashi/tifToJpgLoad/" + format1 + ".jpg"; outSrc = EMRRECORDJSP + File.separator + root + "/jiashi/tifToJpgLoad/" + format1 + ".jpg";
} else { } 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("\\\\", "/"); String driveLetterPath = srcPath.replaceAll("\\\\", "/");
if (driveLetterPath.startsWith("/")) { if (driveLetterPath.startsWith("/")) {
//截取字符串为磁盘路径 //截取字符串为磁盘路径
@ -870,10 +846,10 @@ public class CommomService {
//获取盘符并转换映射地址的头部地址 //获取盘符并转换映射地址的头部地址
root = selectRootByNotWater(driveLetterPath); root = selectRootByNotWater(driveLetterPath);
if (root == null) { if (root == null) {
if(srcPath.contains(linuxPath)){ if (srcPath.contains(linuxPath)) {
srcPath = srcPath.replace(linuxPath, "picShare"); srcPath = srcPath.replace(linuxPath, "picShare");
outSrc = EMRRECORDJSP + File.separator + srcPath; outSrc = EMRRECORDJSP + File.separator + srcPath;
}else{ } else {
outSrc = srcPath; outSrc = srcPath;
} }
} else { } else {
@ -946,6 +922,7 @@ public class CommomService {
return null; return null;
} }
} }
public String processImagePath(String rootPath, String name, String source, Power_User user, EmrPdfWaterSet emrPdfWaterSet, String patientId, String mapKey) throws IOException { public String processImagePath(String rootPath, String name, String source, Power_User user, EmrPdfWaterSet emrPdfWaterSet, String patientId, String mapKey) throws IOException {
return "processed_" + name; // 示例返回值 return "processed_" + name; // 示例返回值
@ -1127,6 +1104,54 @@ public class CommomService {
return outs; 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;
}
/** /**
* *
* *
@ -1230,10 +1255,10 @@ public class CommomService {
try { try {
String osName = System.getProperty("os.name").toLowerCase(); String osName = System.getProperty("os.name").toLowerCase();
String costPath =""; String costPath = "";
if (osName.contains("linux")) { if (osName.contains("linux")) {
costPath = linuxPath + File.separator + "cost"; costPath = linuxPath + File.separator + "cost";
}else{ } else {
costPath = costPdfPath; costPath = costPdfPath;
} }
//解析压缩包文件上传并解压返回存放pdf的全路径 //解析压缩包文件上传并解压返回存放pdf的全路径
@ -1301,14 +1326,14 @@ public class CommomService {
t_scan_assort.setSource((short) 1); t_scan_assort.setSource((short) 1);
//根据病人id病案分段id图片名称判断病案分段图片是否已存在 //根据病人id病案分段id图片名称判断病案分段图片是否已存在
List<T_Scan_Assort> assorts = scanAssortService.getAssortListByPatientAssortPage(commomVo.getPatientId(), zd_assort.getAssortId(),picNameList.get(k)); List<T_Scan_Assort> assorts = scanAssortService.getAssortListByPatientAssortPage(commomVo.getPatientId(), zd_assort.getAssortId(), picNameList.get(k));
if (assorts != null && assorts.size() > 0) { if (assorts != null && assorts.size() > 0) {
continue; continue;
} }
insertList.add(t_scan_assort); insertList.add(t_scan_assort);
} }
//批量新增图片记录 //批量新增图片记录
if(!CollectionUtils.isEmpty(insertList)){ if (!CollectionUtils.isEmpty(insertList)) {
scanAssortService.SimpleInsert(insertList); scanAssortService.SimpleInsert(insertList);
} }
} }

@ -1621,4 +1621,10 @@
b.scan_page scanPage 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 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>
<select id="getSourceBypatientId" resultType="java.lang.String">
select source from commomtable where patient_id = #{patientId} AND source='lz'
</select>
</mapper> </mapper>
Loading…
Cancel
Save