合并南方医院需求

master
81383286@qq.com 4 years ago
commit 6b92035cbd

@ -69,6 +69,7 @@ public class LoginController {
if (null == powerUser) { if (null == powerUser) {
return "redirect:" + POWER_URLHEAD + "/login"; return "redirect:" + POWER_URLHEAD + "/login";
} }
powerUser.setUserName(userName);
//设置进session //设置进session
request.getSession().setAttribute("CURRENT_USER", powerUser); request.getSession().setAttribute("CURRENT_USER", powerUser);
request.getSession().setAttribute("power_menus", powerUser.getMenus()); request.getSession().setAttribute("power_menus", powerUser.getMenus());

@ -671,7 +671,9 @@ public class CommomSearchController {
String pdfName = "档案管理PDF"; String pdfName = "档案管理PDF";
//根据图片路径转换pdf //根据图片路径转换pdf
EmrPdfWaterSet emrPdfWaterSet = pdfWaterSetMapper.selectByPrimaryKey(1); EmrPdfWaterSet emrPdfWaterSet = pdfWaterSetMapper.selectByPrimaryKey(1);
img2PdfUtil.imageToPdf(response, scanPages, pdfName, emrPdfWaterSet); //定义第二文本水印 姓名 + 科室 + ip
EmrPdfWaterSet emrPdfWaterSet1 = commomService.getEmrPdfWaterSet(emrPdfWaterSet);
img2PdfUtil.imageToPdf(response, scanPages, pdfName, emrPdfWaterSet,emrPdfWaterSet1);
//移除缓存 //移除缓存
request.removeAttribute(mapKey); request.removeAttribute(mapKey);
} }

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.emr.annotation.OptionalLog; import com.emr.annotation.OptionalLog;
import com.emr.controller.FormTokenFlagUtil; import com.emr.controller.FormTokenFlagUtil;
import com.emr.dao.CommomMapper; import com.emr.dao.CommomMapper;
import com.emr.dao.EmrComomSetMapper;
import com.emr.dao.Emr_DictionaryMapper; import com.emr.dao.Emr_DictionaryMapper;
import com.emr.dao.approve.Emr_Apply_ApproveMapper; import com.emr.dao.approve.Emr_Apply_ApproveMapper;
import com.emr.dao.commomSearch.ScanPathMapper; import com.emr.dao.commomSearch.ScanPathMapper;
@ -12,10 +13,7 @@ import com.emr.dao.recordLock.Emr_LockMapper;
import com.emr.dao.templateSearch.Emr_CustomizeMapper; import com.emr.dao.templateSearch.Emr_CustomizeMapper;
import com.emr.dao.templateSearch.Emr_ModleMapper; import com.emr.dao.templateSearch.Emr_ModleMapper;
import com.emr.dao.templateSearch.Emr_Modle_RelatedMapper; import com.emr.dao.templateSearch.Emr_Modle_RelatedMapper;
import com.emr.entity.Emr_Dictionary; import com.emr.entity.*;
import com.emr.entity.Emr_Fun_Group_Distribution;
import com.emr.entity.Power_User;
import com.emr.entity.ResultUtil;
import com.emr.entity.approve.Emr_Apply_Approve; import com.emr.entity.approve.Emr_Apply_Approve;
import com.emr.entity.emrPdfWaterSet.EmrPdfWaterSet; import com.emr.entity.emrPdfWaterSet.EmrPdfWaterSet;
import com.emr.entity.recordLock.Emr_Lock; import com.emr.entity.recordLock.Emr_Lock;
@ -23,7 +21,6 @@ import com.emr.entity.templateSearch.Emr_Customize;
import com.emr.entity.templateSearch.Emr_Modle; import com.emr.entity.templateSearch.Emr_Modle;
import com.emr.entity.templateSearch.Emr_Modle_Check; import com.emr.entity.templateSearch.Emr_Modle_Check;
import com.emr.service.CommomService; import com.emr.service.CommomService;
import com.emr.service.approve.ApplyApproveService;
import com.emr.service.emrFunGroupDistribution.FunGroupDistributionService; import com.emr.service.emrFunGroupDistribution.FunGroupDistributionService;
import com.emr.service.emrLock.EmrLockServiceImpl; import com.emr.service.emrLock.EmrLockServiceImpl;
import com.emr.service.emrPrintOrDownLoadInfo.PrintOrDownLoadInfoService; import com.emr.service.emrPrintOrDownLoadInfo.PrintOrDownLoadInfoService;
@ -31,7 +28,6 @@ import com.emr.service.templateSearch.TemplateSearchService;
import com.emr.util.*; import com.emr.util.*;
import com.emr.vo.Msg; import com.emr.vo.Msg;
import com.emr.vo.commomSearch.CommomVo; import com.emr.vo.commomSearch.CommomVo;
import com.emr.vo.commomSearch.ScanAssortVo;
import com.emr.vo.commomSearch.ScanPathForPatientListVo; import com.emr.vo.commomSearch.ScanPathForPatientListVo;
import com.emr.vo.commomSearch.ScanPathVo; import com.emr.vo.commomSearch.ScanPathVo;
import com.emr.vo.templateSearch.Emr_Modle_RelatedVo; import com.emr.vo.templateSearch.Emr_Modle_RelatedVo;
@ -98,6 +94,10 @@ public class TemplateSearchController {
private PrintOrDownLoadInfoService printOrDownLoadInfoService; private PrintOrDownLoadInfoService printOrDownLoadInfoService;
@Autowired @Autowired
private EmrPdfWaterSetMapper pdfWaterSetMapper; private EmrPdfWaterSetMapper pdfWaterSetMapper;
@Autowired
private EmrComomSetMapper emrComomSetMapper;
@Autowired
private CommomService commomService;
/** /**
* @MethodName templateList * @MethodName templateList
@ -898,6 +898,7 @@ public class TemplateSearchController {
if (user.getRoleId() != 0) { if (user.getRoleId() != 0) {
distributions = funGroupDistributionService.selectUserIdsByTypeFlag("approve", user.getUserId()); distributions = funGroupDistributionService.selectUserIdsByTypeFlag("approve", user.getUserId());
} }
EmrComomSet emrComomSet = emrComomSetMapper.selectByPrimaryKey(1);
for (CommomVo commom : commomVos) { for (CommomVo commom : commomVos) {
commom.setLockOper(lockOper); commom.setLockOper(lockOper);
commom.setUnlockOper(unlockOper); commom.setUnlockOper(unlockOper);
@ -905,7 +906,9 @@ public class TemplateSearchController {
commom.setDownloadOper(downloadOper); commom.setDownloadOper(downloadOper);
commom.setEditOper(editOper); commom.setEditOper(editOper);
commom.setDelOper(delOper); commom.setDelOper(delOper);
if (null != distributions && !distributions.isEmpty() || user.getRoleId() == 0) { //判断是否是本科室
boolean isDeptShow = judgeThisDeptPatient(commom,emrComomSet.getIsDeptShow(),user.getRemark());
if (null != distributions && !distributions.isEmpty() || user.getRoleId() == 0 || isDeptShow) {
commom.setIsShowDetail(1); commom.setIsShowDetail(1);
} }
} }
@ -944,6 +947,33 @@ public class TemplateSearchController {
return sql; return sql;
} }
/**
* @Description: judgeThisDeptPatient
* @param: [commom]
* @return: boolean
* @author
* @createTime 2022/7/26 0:44
*/
private boolean judgeThisDeptPatient(CommomVo commom,Integer isDeptShow,String powerDepts) {
//查询是否需要属于本科室免申请直接查看
if(null != isDeptShow && isDeptShow == 1){
//获取出院科室
String disDept = commom.getDisDept();
if(StringUtils.isNoneBlank(powerDepts)){
//分割管辖科室名称
String[] powerDeptList = powerDepts.split(",");
for(String deptName : powerDeptList){
if(StringUtils.isNoneBlank(disDept) && disDept.equals(deptName)){
return true;
}
}
}
}
return false;
}
/** /**
* *
* @param sql * @param sql
@ -1291,7 +1321,8 @@ public class TemplateSearchController {
//emrPdfWaterSet设置启用下载的状态 //emrPdfWaterSet设置启用下载的状态
emrPdfWaterSet.setEffective(emrPdfWaterSet.getDownloadEffective()); emrPdfWaterSet.setEffective(emrPdfWaterSet.getDownloadEffective());
emrPdfWaterSet.setIsImg(emrPdfWaterSet.getDownloadIsImg()); emrPdfWaterSet.setIsImg(emrPdfWaterSet.getDownloadIsImg());
img2PdfUtil.imageToPdf(response, filePaths, pdfName, emrPdfWaterSet); EmrPdfWaterSet emrPdfWaterSet1 = commomService.getEmrPdfWaterSet(emrPdfWaterSet);
img2PdfUtil.imageToPdf(response, filePaths, pdfName, emrPdfWaterSet,emrPdfWaterSet1);
} }
} catch (Exception e) { } catch (Exception e) {
ExceptionPrintUtil.printException(e); ExceptionPrintUtil.printException(e);

@ -13,6 +13,16 @@ public class EmrComomSet implements Serializable {
private String newPicRoot; private String newPicRoot;
private int isDeptShow;
public int getIsDeptShow() {
return isDeptShow;
}
public void setIsDeptShow(int isDeptShow) {
this.isDeptShow = isDeptShow;
}
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public Integer getId() { public Integer getId() {

@ -20,10 +20,13 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -31,6 +34,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.net.InetAddress; import java.net.InetAddress;
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.List;
@ -162,6 +166,38 @@ public class CommomService {
return null; return null;
} }
public String getOperIp(){
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
// 获取访问真实IP
String ipAddress = request.getHeader("x-forwarded-for");
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
if("127.0.0.1".equals(ipAddress) || "0:0:0:0:0:0:0:1".equals(ipAddress)){
//根据网卡取本机配置的IP
InetAddress inet=null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
assert inet != null;
ipAddress= inet.getHostAddress();
}
}
//对于通过多个代理的情况第一个IP为客户端真实IP,多个IP按照','分割
if(ipAddress!=null && ipAddress.length()>15){ //"***.***.***.***".length() = 15
if(ipAddress.indexOf(",")>0){
ipAddress = ipAddress.substring(0,ipAddress.indexOf(","));
}
}
return ipAddress;
}
//脐血库显示pdf //脐血库显示pdf
public void showRecordContentBlood(String patientId, String scanPages, String sources, String flag, HttpServletResponse response,HttpServletRequest request) throws Exception { public void showRecordContentBlood(String patientId, String scanPages, String sources, String flag, HttpServletResponse response,HttpServletRequest request) throws Exception {
@ -209,6 +245,34 @@ public class CommomService {
} }
} }
/**
* @Description: getEmrPdfWaterSet + + ip
* @param: [emrPdfWaterSet]
* @return: com.emr.entity.emrPdfWaterSet.EmrPdfWaterSet
* @author
* @createTime 2022/7/26 1:15
*/
public EmrPdfWaterSet getEmrPdfWaterSet(EmrPdfWaterSet emrPdfWaterSet) {
EmrPdfWaterSet emrPdfWaterSet1 = new EmrPdfWaterSet();
BeanUtils.copyProperties(emrPdfWaterSet,emrPdfWaterSet1);
//定义第二水印文本
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//获取reuqest
HttpServletRequest request = attributes.getRequest();
Power_User user = (Power_User) request.getSession().getAttribute("CURRENT_USER");
String text = "";
if(StringUtils.isNotBlank(user.getUserPosition())){
text = user.getUserPosition();
}
if(StringUtils.isNotBlank(user.getRemark())){
text += " " + user.getRemark();
}
text += " " + getOperIp();
emrPdfWaterSet1.setText(text);
return emrPdfWaterSet1;
}
//南方医院显示图像 //南方医院显示图像
public void showRecordContentSouth(String patientId, String userName, String deptName, String scanPages, String sources, String flag, HttpServletResponse response) throws Exception { public void showRecordContentSouth(String patientId, String userName, String deptName, String scanPages, String sources, String flag, HttpServletResponse response) throws Exception {
String pdfName = "档案管理PDF"; String pdfName = "档案管理PDF";
@ -250,13 +314,9 @@ public class CommomService {
if (!filePaths.isEmpty()) { if (!filePaths.isEmpty()) {
//根据图片路径转换pdf //根据图片路径转换pdf
EmrPdfWaterSet emrPdfWaterSet = pdfWaterSetMapper.selectByPrimaryKey(1); EmrPdfWaterSet emrPdfWaterSet = pdfWaterSetMapper.selectByPrimaryKey(1);
InetAddress netAddress = InetAddress.getLocalHost(); //定义第二文本水印 姓名 + 科室 + ip
String ip = null; EmrPdfWaterSet emrPdfWaterSet1 = getEmrPdfWaterSet(emrPdfWaterSet);
if (null != netAddress) { img2PdfUtil.imageToPdf(response, filePaths, pdfName, emrPdfWaterSet,emrPdfWaterSet1);
ip = netAddress.getHostAddress();
}
emrPdfWaterSet.setText(userName + " " + ip);
img2PdfUtil.imageToPdf(response, filePaths, pdfName, emrPdfWaterSet);
} }
} }
} }
@ -470,7 +530,9 @@ public class CommomService {
//组织加水印后图片存放地址 //组织加水印后图片存放地址
String waterPicPath = waterPicRoot + nameList[i]; String waterPicPath = waterPicRoot + nameList[i];
if (!new File(waterPicPath).exists()) { if (!new File(waterPicPath).exists()) {
img2PdfUtil.addWatermarkPic1(new File(srcPath), emrPdfWaterSet, waterPicPath); //定义第二文本水印 姓名 + 科室 + ip
EmrPdfWaterSet emrPdfWaterSet1 = getEmrPdfWaterSet(emrPdfWaterSet);
img2PdfUtil.addWatermarkPic1(new File(srcPath), emrPdfWaterSet, waterPicPath,emrPdfWaterSet1);
//组织输出地址 //组织输出地址
} }
outSrc = EMRRECORDJSP + File.separator + "reload" + File.separator + patientId + File.separator + sourceList[i] + File.separator + nameList[i]; outSrc = EMRRECORDJSP + File.separator + "reload" + File.separator + patientId + File.separator + sourceList[i] + File.separator + nameList[i];
@ -644,7 +706,9 @@ public class CommomService {
//组织加水印后图片存放地址 //组织加水印后图片存放地址
String waterPicPath = waterPicRoot + nameList[i]; String waterPicPath = waterPicRoot + nameList[i];
if (!new File(waterPicPath).exists()) { if (!new File(waterPicPath).exists()) {
img2PdfUtil.addWatermarkPic1(new File(srcPath), emrPdfWaterSet, waterPicPath); //定义第二文本水印 姓名 + 科室 + ip
EmrPdfWaterSet emrPdfWaterSet1 = getEmrPdfWaterSet(emrPdfWaterSet);
img2PdfUtil.addWatermarkPic1(new File(srcPath), emrPdfWaterSet, waterPicPath,emrPdfWaterSet1);
} }
//组织输出地址 //组织输出地址
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + File.separator + 3 + File.separator + nameList[i]; outSrc = EMRRECORDJSP + "\\reload\\" + patientId + File.separator + 3 + File.separator + nameList[i];
@ -658,7 +722,8 @@ public class CommomService {
//组织加水印后图片存放地址 //组织加水印后图片存放地址
String waterPicPath = waterPicRoot + nameList[i]; String waterPicPath = waterPicRoot + nameList[i];
if (!new File(waterPicPath).exists()) { if (!new File(waterPicPath).exists()) {
img2PdfUtil.addWatermarkPic1(new File(srcPath), emrPdfWaterSet, waterPicPath); EmrPdfWaterSet emrPdfWaterSet1 = getEmrPdfWaterSet(emrPdfWaterSet);
img2PdfUtil.addWatermarkPic1(new File(srcPath), emrPdfWaterSet, waterPicPath,emrPdfWaterSet1);
} }
//组织输出地址 //组织输出地址
outSrc = EMRRECORDJSP + "\\reload\\" + patientId + File.separator + sourceList[i] + File.separator + nameList[i]; outSrc = EMRRECORDJSP + "\\reload\\" + patientId + File.separator + sourceList[i] + File.separator + nameList[i];

@ -85,7 +85,7 @@ public class PrintOrDownLoadInfoService {
obj.setOperType(operType); obj.setOperType(operType);
obj.setCreater(user.getUserName()); obj.setCreater(user.getUserName());
obj.setCreateTime(fmt.format(new Date())); obj.setCreateTime(fmt.format(new Date()));
obj.setIp(getOperIp()); obj.setIp(commomService.getOperIp());
obj.setScanPage(JSON.toJSONString(map)); obj.setScanPage(JSON.toJSONString(map));
obj.setPatientId(patientId); obj.setPatientId(patientId);
batchInsertList.add(obj); batchInsertList.add(obj);
@ -97,38 +97,7 @@ public class PrintOrDownLoadInfoService {
//获取操作人ip //获取操作人ip
private String getOperIp(){
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
// 获取访问真实IP
String ipAddress = request.getHeader("x-forwarded-for");
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
if("127.0.0.1".equals(ipAddress) || "0:0:0:0:0:0:0:1".equals(ipAddress)){
//根据网卡取本机配置的IP
InetAddress inet=null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
assert inet != null;
ipAddress= inet.getHostAddress();
}
}
//对于通过多个代理的情况第一个IP为客户端真实IP,多个IP按照','分割
if(ipAddress!=null && ipAddress.length()>15){ //"***.***.***.***".length() = 15
if(ipAddress.indexOf(",")>0){
ipAddress = ipAddress.substring(0,ipAddress.indexOf(","));
}
}
return ipAddress;
}
/** /**
* *
* */ * */

@ -37,7 +37,7 @@ public class img2PdfUtil {
final private static float A4_weight = 595; //标准A4的宽 final private static float A4_weight = 595; //标准A4的宽
final private static float A4_height = 842; //标准A4的高 final private static float A4_height = 842; //标准A4的高
public static void imageToPdf(HttpServletResponse response, List<String> filePaths, String pdfName, EmrPdfWaterSet pdfWaterSet) { public static void imageToPdf(HttpServletResponse response, List<String> filePaths, String pdfName, EmrPdfWaterSet pdfWaterSet,EmrPdfWaterSet pdfWaterSet1) {
Document document = new Document(PageSize.A4, 0, 0, 0, 0); //创建文档容器 Document document = new Document(PageSize.A4, 0, 0, 0, 0); //创建文档容器
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
//是否启用水印 //是否启用水印
@ -61,7 +61,7 @@ public class img2PdfUtil {
pdfWaterSet.getText(), pdfWaterSet.getTextX(), pdfWaterSet.getTextY(), pdfWaterSet.getText(), pdfWaterSet.getTextX(), pdfWaterSet.getTextY(),
pdfWaterSet.getTextColor(), pdfWaterSet.getTextSize(), pdfWaterSet.getTextRotation(), pdfWaterSet.getTextColor(), pdfWaterSet.getTextSize(), pdfWaterSet.getTextRotation(),
pdfWaterSet.getEffective(), pdfWaterSet.getIsImg(), pdfWaterSet.getImgFile(), pdfWaterSet.getImgWidth(), pdfWaterSet.getEffective(), pdfWaterSet.getIsImg(), pdfWaterSet.getImgFile(), pdfWaterSet.getImgWidth(),
pdfWaterSet.getImgHeight(), pdfWaterSet.getImgX(), pdfWaterSet.getImgY()); pdfWaterSet.getImgHeight(), pdfWaterSet.getImgX(), pdfWaterSet.getImgY(),pdfWaterSet1.getText());
} }
} catch (Exception e) { } catch (Exception e) {
ExceptionPrintUtil.printException(e); ExceptionPrintUtil.printException(e);
@ -184,7 +184,7 @@ public class img2PdfUtil {
} }
} }
public static String addWatermarkPic1(File srcImgFile, EmrPdfWaterSet pdfWaterSet, String outPath) { public static String addWatermarkPic1(File srcImgFile, EmrPdfWaterSet pdfWaterSet, String outPath,EmrPdfWaterSet pdfWaterSet1) {
java.awt.Image srcImg = null; java.awt.Image srcImg = null;
BufferedImage bufImg = null; BufferedImage bufImg = null;
Graphics2D g = null; Graphics2D g = null;
@ -216,7 +216,8 @@ public class img2PdfUtil {
g.setFont(font); //设置字体 g.setFont(font); //设置字体
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));//设置水印文字透明度 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));//设置水印文字透明度
g.rotate(Math.toRadians(degree), (double) bufImg.getWidth(), (double) bufImg.getHeight());//设置水印旋转 g.rotate(Math.toRadians(degree), (double) bufImg.getWidth(), (double) bufImg.getHeight());//设置水印旋转
g.drawString(pdfWaterSet.getText(), srcImg.getWidth(null) / 2 + pdfWaterSet.getTextX(), srcImg.getHeight(null) / 2 + (pdfWaterSet.getTextY() - 200));//画出水印,并设置水印位置 g.drawString(pdfWaterSet.getText(), srcImg.getWidth(null) / 2 + pdfWaterSet.getTextX() , srcImg.getHeight(null) / 2 + (pdfWaterSet.getTextY() - 300));//画出水印,并设置水印位置
g.drawString(pdfWaterSet1.getText(), srcImg.getWidth(null) / 2 + pdfWaterSet.getTextX() , srcImg.getHeight(null) / 2 + (pdfWaterSet.getTextY() -100));//画出水印,并设置水印位置
//System.out.println("画文字图片"+(end2-start2)/1000.0+"s"); //System.out.println("画文字图片"+(end2-start2)/1000.0+"s");
} }
//ByteArrayInputStream fis = new ByteArrayInputStream(imageToByteArr);//创建输入流对象 //ByteArrayInputStream fis = new ByteArrayInputStream(imageToByteArr);//创建输入流对象
@ -367,12 +368,135 @@ public class img2PdfUtil {
// 中间水印 // 中间水印
content.showTextAligned(Element.ALIGN_LEFT, text, textX, textY, textRotation); content.showTextAligned(Element.ALIGN_LEFT, text, textX, textY, textRotation);
// 底部水印 // 底部水印
/*for (int k = 0; k < text.length(); k++) { content.endText();
// 距离底边的距离 //第二水印
content.setTextRise(10); content.beginText();
// 将char转成字符串 //16进制颜色转color
content.showText(String.valueOf(text.charAt(k))); content.setColorFill(color);
}*/ // 设置字体及字号
content.setFontAndSize(font, textSize);
// 设置起始位置
content.setTextMatrix(textX, textY);
// 中间水印
content.showTextAligned(Element.ALIGN_LEFT, text, textX, textY, textRotation);
// 底部水印
content.endText();
}
}
} catch (IOException | DocumentException e) {
ExceptionPrintUtil.printException(e);
e.printStackTrace();
} finally {
if (null != stamper) {
try {
stamper.close();
} catch (DocumentException | IOException e) {
e.printStackTrace();
}
}
if (null != reader) {
reader.close();
}
}
}
public static void addWaterMark(ByteArrayOutputStream bos, HttpServletResponse response, int upOrUnder, float transparent, String text, int textX, int textY,
String textColor, int textSize, int textRotation, Short effective, Short isImg,
String imgFile, int imgWidth, int imgHeight, int imgX, int imgY,String text1) {
PdfReader reader = null;
PdfStamper stamper = null;
try {
reader = new PdfReader(bos.toByteArray());
// 加完水印的文件
if (null != response) {
stamper = new PdfStamper(reader, response.getOutputStream());
} else {
stamper = new PdfStamper(reader, bos);
}
// 设置字体
BaseFont font = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
// PDF总页数
int total = reader.getNumberOfPages() + 1;
// 循环对每页插入水印
PdfContentByte content;
PdfGState gs = new PdfGState();
for (int i = 1; i < total; i++) {
//upOrUnder = 1为在文本之上
if (upOrUnder == 1) {
// 水印在之前文本之上
content = stamper.getOverContent(i);
} else {
// 水印在文本之下
content = stamper.getUnderContent(i);
}
//设置填充字体不透明度为0.2f
gs.setFillOpacity(transparent);
content.setGState(gs);
// 图片水印
if (null != isImg && isImg == 1) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String tomcatPath = request.getSession().getServletContext().getRealPath("/");
String imgStr = tomcatPath + "static\\pdfWaterSet\\upload\\" + imgFile;
com.lowagie.text.Image image = null;
if (StringUtils.isNotBlank(imgStr) && new File(imgStr).isFile()) {
image = com.lowagie.text.Image.getInstance(imgStr);
//位置
image.setAbsolutePosition(imgX, imgY);
// 设置图片的显示大小
image.scaleToFit(imgWidth, imgHeight);
content.addImage(image);
}
}
// 文字水印
if (effective == 1 && StringUtils.isNotBlank(text)) {
content.beginText();
//16进制颜色转color
Color color = toColorFromString(textColor);
content.setColorFill(color);
// 设置字体及字号
content.setFontAndSize(font, textSize);
// 设置起始位置
content.setTextMatrix(textX, textY);
// 中间水印
content.showTextAligned(Element.ALIGN_LEFT, text, textX, textY, textRotation);
// 底部水印
content.endText();
//第二水印
content.beginText();
//16进制颜色转color
content.setColorFill(color);
// 设置字体及字号
content.setFontAndSize(font, textSize);
// 设置起始位置
content.setTextMatrix(textX, textY);
// 中间水印
content.showTextAligned(Element.ALIGN_LEFT, text, textX, textY, textRotation);
// 底部水印
content.endText();
}
if(StringUtils.isNotBlank(text1)){
content.beginText();
//16进制颜色转color
Color color = toColorFromString(textColor);
content.setColorFill(color);
// 设置字体及字号
content.setFontAndSize(font, textSize);
// 设置起始位置
content.setTextMatrix(textX, textY);
// 中间水印
content.showTextAligned(Element.ALIGN_LEFT, text1, textX, textY - 100, textRotation);
// 底部水印
content.endText();
//第二水印
content.beginText();
//16进制颜色转color
content.setColorFill(color);
// 设置字体及字号
content.setFontAndSize(font, textSize);
// 设置起始位置
content.setTextMatrix(textX, textY);
// 中间水印
content.showTextAligned(Element.ALIGN_LEFT, text, textX, textY, textRotation);
// 底部水印
content.endText(); content.endText();
} }
} }

@ -5,11 +5,12 @@
<id column="id" property="id" jdbcType="INTEGER" /> <id column="id" property="id" jdbcType="INTEGER" />
<result column="times" property="times" jdbcType="SMALLINT" /> <result column="times" property="times" jdbcType="SMALLINT" />
<result column="defaultDay" property="defaultDay" jdbcType="INTEGER" /> <result column="defaultDay" property="defaultDay" jdbcType="INTEGER" />
<result column="is_dept_show" property="isDeptShow" jdbcType="INTEGER" />
<result column="maxDay" property="maxDay" jdbcType="INTEGER" /> <result column="maxDay" property="maxDay" jdbcType="INTEGER" />
<result column="new_pic_root" property="newPicRoot" jdbcType="NVARCHAR" /> <result column="new_pic_root" property="newPicRoot" jdbcType="NVARCHAR" />
</resultMap> </resultMap>
<sql id="Base_Column_List" > <sql id="Base_Column_List" >
id, times, defaultDay, maxDay,new_pic_root id, times, defaultDay, maxDay,new_pic_root,is_dept_show
</sql> </sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select select

Loading…
Cancel
Save