Commit c00e10f5 authored by hongguangwu's avatar hongguangwu

MVP1.7.15-优化

parent 11395b13
...@@ -3197,10 +3197,9 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T ...@@ -3197,10 +3197,9 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
} }
excelVOTemp.put(excel.getRowIndex().toString(), excel.getEmpIdcard()); excelVOTemp.put(excel.getRowIndex().toString(), excel.getEmpIdcard());
// 初始化派单 和 社保公积金查询信息 // 初始化派单 和 社保公积金查询信息
initEducation(null, excel, empVo);
dispatch = getDispatchInfo(empVo, excel, socialFund, setInfoVo, user); dispatch = getDispatchInfo(empVo, excel, socialFund, setInfoVo, user);
//派单学历无值时,如果档案有值直接取值档案 2024-08-21 fxj
initEducation(null, excel, empVo);
if (Common.isEmpty(dispatch.getDispatchItem())) { if (Common.isEmpty(dispatch.getDispatchItem())) {
errorMessageList.add(new ErrorMessage(excel.getRowIndex(), MsgUtils.getMessage(ErrorCodes.EMP_DISPATCH_ITEM_EMPTY_EXISTS))); errorMessageList.add(new ErrorMessage(excel.getRowIndex(), MsgUtils.getMessage(ErrorCodes.EMP_DISPATCH_ITEM_EMPTY_EXISTS)));
continue; continue;
......
...@@ -1042,7 +1042,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1042,7 +1042,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取流异常"); return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取流异常");
} }
// 添加电子章 完成后关闭所有流 // 添加电子章 完成后关闭所有流
excelMergeImage.addPictureToExcel(inputStream, inStream, fileOUt, 0, type); //excelMergeImage.addPictureToExcel(inputStream, inStream, fileOUt, 0, type);
outFile = new File(tempPath); outFile = new File(tempPath);
inputStreamOut = new FileInputStream(outFile); inputStreamOut = new FileInputStream(outFile);
// 转换成图片 完成后清理流 // 转换成图片 完成后清理流
...@@ -1050,7 +1050,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1050,7 +1050,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
backLog.setType(CommonConstants.SEVEN_INT); backLog.setType(CommonConstants.SEVEN_INT);
backLog.setSocialId(searchVo.getSocialId()); backLog.setSocialId(searchVo.getSocialId());
R<String> ulrR = excelToImage.excelToImg(searchVo.getSocialId(), ossUtil, tSocialFriendBackLogService R<String> ulrR = excelToImage.excelToImg(searchVo.getSocialId(), ossUtil, tSocialFriendBackLogService
, inputStreamOut, socialFriendConfig, restTemplate, backLog); , inputStream, socialFriendConfig, restTemplate, backLog, inStream);
tSocialFriendBackLogService.save(backLog); tSocialFriendBackLogService.save(backLog);
return ulrR; return ulrR;
} catch (Exception e) { } catch (Exception e) {
...@@ -1082,10 +1082,10 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1082,10 +1082,10 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
FileOutputStream fileOUt, FileOutputStream fileOUt,
InputStream inStream, InputStream inStream,
FileInputStream inputStreamOut) throws IOException { FileInputStream inputStreamOut) throws IOException {
if (inputFile.exists()) { if (inputFile != null && inputFile.exists()) {
inputFile.delete(); inputFile.delete();
} }
if (tempFile.exists()) { if (tempFile != null && tempFile.exists()) {
tempFile.delete(); tempFile.delete();
} }
if (outFile != null && outFile.exists()) { if (outFile != null && outFile.exists()) {
...@@ -1290,19 +1290,12 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1290,19 +1290,12 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
} }
File inputFile = null; File inputFile = null;
File tempFile = null;
File outFile = null;
FileInputStream inputStream = null; FileInputStream inputStream = null;
FileOutputStream fileOUt = null;
InputStream inStream = null; InputStream inStream = null;
FileInputStream inputStreamOut = null;
try { try {
//读取文件 生成电子章 //读取文件 生成电子章
inputFile = new File(filePath); inputFile = new File(filePath);
inputStream = new FileInputStream(inputFile); inputStream = new FileInputStream(inputFile);
String tempPath = projectRoot + "//temp_" + fileName;
tempFile = new File(tempPath);
fileOUt = new FileOutputStream(tempFile);
if (Common.isEmpty(url)) { if (Common.isEmpty(url)) {
return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取URL异常"); return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取URL异常");
...@@ -1311,11 +1304,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1311,11 +1304,7 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
if (Common.isEmpty(inStream)) { if (Common.isEmpty(inStream)) {
return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取流异常"); return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取流异常");
} }
// 添加电子章 完成后关闭所有流
excelMergeImage.addPictureToExcel(inputStream, inStream, fileOUt, CommonConstants.ZERO_INT, String.valueOf(type));
outFile = new File(tempPath);
inputStreamOut = new FileInputStream(outFile);
// 转换成图片 完成后清理流 // 转换成图片 完成后清理流
TSocialFriendBackLog backLog = new TSocialFriendBackLog(); TSocialFriendBackLog backLog = new TSocialFriendBackLog();
backLog.setSocialId(vo.getSocialId()); backLog.setSocialId(vo.getSocialId());
...@@ -1323,14 +1312,14 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1323,14 +1312,14 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
backLog.setCreateTime(LocalDateTime.now()); backLog.setCreateTime(LocalDateTime.now());
R<String> ulrR = excelToImage.excelToImg(vo.getSocialId(), ossUtil, tSocialFriendBackLogService R<String> ulrR = excelToImage.excelToImg(vo.getSocialId(), ossUtil, tSocialFriendBackLogService
, inputStreamOut, socialFriendConfig, restTemplate, backLog); , inputStream, socialFriendConfig, restTemplate, backLog, inStream);
tSocialFriendBackLogService.save(backLog); tSocialFriendBackLogService.save(backLog);
return ulrR; return ulrR;
} catch (Exception e) { } catch (Exception e) {
return R.failed("税友附件生成异常:" + e.getMessage()); return R.failed("税友附件生成异常:" + e.getMessage());
} finally { } finally {
// 清理文件 // 清理文件
finallyClose(inputFile, tempFile, outFile, inputStream, fileOUt, inStream, inputStreamOut); finallyClose(inputFile, null, null, inputStream, null, inStream, null);
} }
} catch (Exception e) { } catch (Exception e) {
if (excelWriter != null) { if (excelWriter != null) {
...@@ -1749,7 +1738,8 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1749,7 +1738,8 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取流异常"); return R.failed(CommonConstants.RESULT_DATA_FAIL + ":电子印章OSS获取流异常");
} }
// 添加电子章 完成后关闭所有流 // 添加电子章 完成后关闭所有流
excelMergeImage.addPictureToExcel(inputStream, inStream, fileOUt, 0, type); // ——在excel生成图片后加章,在excelToImg方法里 完成后关闭所有流
//excelMergeImage.addPictureToExcel(inputStream, inStream, fileOUt, 0, type);
outFile = new File(tempPath); outFile = new File(tempPath);
inputStreamOut = new FileInputStream(outFile); inputStreamOut = new FileInputStream(outFile);
// 转换成图片 完成后清理流 // 转换成图片 完成后清理流
...@@ -1757,8 +1747,10 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1757,8 +1747,10 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
backLog.setSocialId(searchVo.getSocialId()); backLog.setSocialId(searchVo.getSocialId());
backLog.setType(CommonConstants.SIX_INT); backLog.setType(CommonConstants.SIX_INT);
backLog.setCreateTime(LocalDateTime.now()); backLog.setCreateTime(LocalDateTime.now());
//R<String> ulrR = excelToImage.excelToImg(searchVo.getSocialId(), ossUtil, tSocialFriendBackLogService
// , inputStreamOut, socialFriendConfig, restTemplate, backLog, inStream);
R<String> ulrR = excelToImage.excelToImg(searchVo.getSocialId(), ossUtil, tSocialFriendBackLogService R<String> ulrR = excelToImage.excelToImg(searchVo.getSocialId(), ossUtil, tSocialFriendBackLogService
, inputStreamOut, socialFriendConfig, restTemplate, backLog); , inputStream, socialFriendConfig, restTemplate, backLog, inStream);
tSocialFriendBackLogService.save(backLog); tSocialFriendBackLogService.save(backLog);
return ulrR; return ulrR;
} catch (Exception e) { } catch (Exception e) {
......
...@@ -15,6 +15,7 @@ import org.springframework.stereotype.Component; ...@@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -46,7 +47,7 @@ public class ExcelToImage { ...@@ -46,7 +47,7 @@ public class ExcelToImage {
public R<String> excelToImg(String socialId, OSSUtil ossUtil, TSocialFriendBackLogService tSocialFriendBackLogService public R<String> excelToImg(String socialId, OSSUtil ossUtil, TSocialFriendBackLogService tSocialFriendBackLogService
,InputStream inputStream , SocialFriendConfig socialFriendConfig ,InputStream inputStream , SocialFriendConfig socialFriendConfig
, RestTemplate restTemplate, TSocialFriendBackLog backLog){ , RestTemplate restTemplate, TSocialFriendBackLog backLog, InputStream zhangStream){
backLog.setLogInfo("开始转换excel为图片"); backLog.setLogInfo("开始转换excel为图片");
if (null == inputStream || null == socialFriendConfig){ if (null == inputStream || null == socialFriendConfig){
return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagParamError); return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagParamError);
...@@ -67,7 +68,8 @@ public class ExcelToImage { ...@@ -67,7 +68,8 @@ public class ExcelToImage {
if (file.exists()){ if (file.exists()){
// file 压缩到1M以内 // file 压缩到1M以内
backLog.setLogInfo("压缩大小前"); backLog.setLogInfo("压缩大小前");
file = compressImage(file, projectRoot); // 压缩并加章
file = compressImage(file, projectRoot, zhangStream);
backLog.setLogInfo("压缩大小后"); backLog.setLogInfo("压缩大小后");
String key = System.currentTimeMillis() + file.getName(); String key = System.currentTimeMillis() + file.getName();
byte[] fileContent = Files.readAllBytes(file.toPath()); byte[] fileContent = Files.readAllBytes(file.toPath());
...@@ -131,14 +133,17 @@ public class ExcelToImage { ...@@ -131,14 +133,17 @@ public class ExcelToImage {
} }
//压缩文件到指定大小 //压缩文件到指定大小
private File compressImage(File originalFile, String projectRoot) throws IOException { private File compressImage(File originalFile, String projectRoot, InputStream zhangStream) throws IOException {
BufferedImage image = ImageIO.read(originalFile); BufferedImage image = ImageIO.read(originalFile);
// 新: 加盖公章
BufferedImage sealedImage = addSealToImage(image, zhangStream);
ImageIO.write(sealedImage, "png", originalFile);
int quality = 100; // 从100%开始 int quality = 100; // 从100%开始
File compressedFile = new File(projectRoot, TO_IMAGE_TEMP); File compressedFile = new File(projectRoot, TO_IMAGE_TEMP);
int maxSize = 1024 * 1024; int maxSize = 1024 * 1024;
while (originalFile.length() > maxSize && quality > 10) { while (originalFile.length() > maxSize && quality > 10) {
quality -= 5; quality -= 5;
ImageIO.write(image, "png", compressedFile); ImageIO.write(sealedImage, "png", compressedFile);
if (compressedFile.length() < maxSize) { if (compressedFile.length() < maxSize) {
originalFile.delete(); originalFile.delete();
compressedFile.renameTo(originalFile); compressedFile.renameTo(originalFile);
...@@ -149,6 +154,40 @@ public class ExcelToImage { ...@@ -149,6 +154,40 @@ public class ExcelToImage {
return originalFile; return originalFile;
} }
private BufferedImage addSealToImage(BufferedImage image, InputStream sealImagePath) throws IOException {
BufferedImage seal = ImageIO.read(sealImagePath);
// 设置公章目标大小
int targetWidth = 200; // 宽度
int targetHeight = 200; // 高度
// 创建缩放后的公章图像
Image scaledSeal = seal.getScaledInstance(targetWidth, targetHeight, Image.SCALE_SMOOTH);
BufferedImage resizedSeal = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = resizedSeal.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(scaledSeal, 0, 0, null);
g2d.dispose();
// 合成最终图像
BufferedImage combined = new BufferedImage(
image.getWidth(),
image.getHeight(),
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = combined.createGraphics();
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.drawImage(image, 0, 0, null);
// 设置公章位置(左上角)
int x = 50;
int y = 50;
g.drawImage(resizedSeal, x, y, null);
g.dispose();
return combined;
}
public R<URL> excelToImg(InputStream inputStream ,OSSUtil ossUtil){ public R<URL> excelToImg(InputStream inputStream ,OSSUtil ossUtil){
if (null == inputStream || null == ossUtil){ if (null == inputStream || null == ossUtil){
return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagParamError); return R.failed(CommonConstants.RESULT_DATA_FAIL+toImagParamError);
......
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
if( MOD(SUBSTRING(s.EMP_IDCARD,if(LENGTH(s.EMP_IDCARD) = 18,17,15),1),2)=0,'女','男') if( MOD(SUBSTRING(s.EMP_IDCARD,if(LENGTH(s.EMP_IDCARD) = 18,17,15),1),2)=0,'女','男')
) empSex,'√' dui,'×' cuo,DATE_FORMAT(a.AUDIT_TIME,'%Y-%m-%d') auditDay ) empSex,'√' dui,'×' cuo,DATE_FORMAT(a.AUDIT_TIME,'%Y-%m-%d') auditDay
,shh.AUDIT_USER_NAME auditUserName,shh.HANDLE_USER_NAME handleUserName ,shh.AUDIT_USER_NAME auditUserName,shh.HANDLE_USER_NAME handleUserName
,DATE_FORMAT(s.SOCIAL_REDUCE_DATE,'%Y-%m') socialReduceDate ,DATE_FORMAT(a.SOCIAL_REDUCE_DATE,'%Y-%m') socialReduceDate
,if( LENGTH(s.EMP_IDCARD) NOT IN (15, 18),'-',if(LENGTH(s.EMP_IDCARD) = 18,CONCAT(SUBSTRING(s.EMP_IDCARD,7,4),'-',SUBSTRING(s.EMP_IDCARD,11,2)) ,if( LENGTH(s.EMP_IDCARD) NOT IN (15, 18),'-',if(LENGTH(s.EMP_IDCARD) = 18,CONCAT(SUBSTRING(s.EMP_IDCARD,7,4),'-',SUBSTRING(s.EMP_IDCARD,11,2))
,CONCAT('19',SUBSTRING(s.EMP_IDCARD,7,2),'-',SUBSTRING(s.EMP_IDCARD,9,2)))) birthMonth ,CONCAT('19',SUBSTRING(s.EMP_IDCARD,7,2),'-',SUBSTRING(s.EMP_IDCARD,9,2)))) birthMonth
,concat(ifnull(DATE_FORMAT(a.CONTRACT_START,"%Y%m%d"),''),'-',ifnull(DATE_FORMAT(a.CONTRACT_END,"%Y%m%d"),'')) workDate ,concat(ifnull(DATE_FORMAT(a.CONTRACT_START,"%Y%m%d"),''),'-',ifnull(DATE_FORMAT(a.CONTRACT_END,"%Y%m%d"),'')) workDate
...@@ -299,7 +299,7 @@ ...@@ -299,7 +299,7 @@
if( MOD(SUBSTRING(s.EMP_IDCARD,if(LENGTH(s.EMP_IDCARD) = 18,17,15),1),2)=0,'女','男') if( MOD(SUBSTRING(s.EMP_IDCARD,if(LENGTH(s.EMP_IDCARD) = 18,17,15),1),2)=0,'女','男')
) empSex,'√' dui,'×' cuo,DATE_FORMAT(a.AUDIT_TIME,'%Y-%m-%d') auditDay ) empSex,'√' dui,'×' cuo,DATE_FORMAT(a.AUDIT_TIME,'%Y-%m-%d') auditDay
,shh.AUDIT_USER_NAME auditUserName,shh.HANDLE_USER_NAME handleUserName ,shh.AUDIT_USER_NAME auditUserName,shh.HANDLE_USER_NAME handleUserName
,DATE_FORMAT(s.SOCIAL_REDUCE_DATE,'%Y-%m') socialReduceDate ,DATE_FORMAT(a.SOCIAL_REDUCE_DATE,'%Y-%m') socialReduceDate
,if( LENGTH(s.EMP_IDCARD) NOT IN (15, 18),'-',if(LENGTH(s.EMP_IDCARD) = 18,CONCAT(SUBSTRING(s.EMP_IDCARD,7,4),'-',SUBSTRING(s.EMP_IDCARD,11,2)) ,if( LENGTH(s.EMP_IDCARD) NOT IN (15, 18),'-',if(LENGTH(s.EMP_IDCARD) = 18,CONCAT(SUBSTRING(s.EMP_IDCARD,7,4),'-',SUBSTRING(s.EMP_IDCARD,11,2))
,CONCAT('19',SUBSTRING(s.EMP_IDCARD,7,2),'-',SUBSTRING(s.EMP_IDCARD,9,2)))) birthMonth ,CONCAT('19',SUBSTRING(s.EMP_IDCARD,7,2),'-',SUBSTRING(s.EMP_IDCARD,9,2)))) birthMonth
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment