|
|
@ -2,6 +2,12 @@ package org.jeecg.modules.apiService.impl; |
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
import com.itextpdf.text.Document; |
|
|
|
|
|
import com.itextpdf.text.DocumentException; |
|
|
|
|
|
import com.itextpdf.text.Image; |
|
|
|
|
|
import com.itextpdf.text.PageSize; |
|
|
|
|
|
import com.itextpdf.text.pdf.PdfWriter; |
|
|
|
|
|
import org.icepdf.core.util.GraphicsRenderingHints; |
|
|
import org.jeecg.common.api.vo.Result; |
|
|
import org.jeecg.common.api.vo.Result; |
|
|
import org.jeecg.config.shiro.ShiroRealm; |
|
|
import org.jeecg.config.shiro.ShiroRealm; |
|
|
import org.jeecg.modules.apiBean.PageBean; |
|
|
import org.jeecg.modules.apiBean.PageBean; |
|
|
@ -12,12 +18,21 @@ import org.jeecg.modules.employAuthenticationPerson.entity.EmployAuthenticationP |
|
|
import org.jeecg.modules.employAuthenticationPerson.service.IEmployAuthenticationPersonService; |
|
|
import org.jeecg.modules.employAuthenticationPerson.service.IEmployAuthenticationPersonService; |
|
|
import org.jeecg.modules.employContract.entity.EmployContract; |
|
|
import org.jeecg.modules.employContract.entity.EmployContract; |
|
|
import org.jeecg.modules.employContract.service.IEmployContractService; |
|
|
import org.jeecg.modules.employContract.service.IEmployContractService; |
|
|
|
|
|
import org.jeecg.modules.employContractTemplate.entity.EmployContractTemplate; |
|
|
|
|
|
import org.jeecg.modules.employContractTemplate.service.IEmployContractTemplateService; |
|
|
import org.jeecg.modules.employResume.entity.EmployResume; |
|
|
import org.jeecg.modules.employResume.entity.EmployResume; |
|
|
import org.jeecg.modules.employResume.service.IEmployResumeService; |
|
|
import org.jeecg.modules.employResume.service.IEmployResumeService; |
|
|
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember; |
|
|
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import sun.misc.BASE64Encoder; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
|
|
import java.awt.image.RenderedImage; |
|
|
|
|
|
import java.io.*; |
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class ContractServiceImpl implements ContractService { |
|
|
public class ContractServiceImpl implements ContractService { |
|
|
@ -27,6 +42,9 @@ public class ContractServiceImpl implements ContractService { |
|
|
@Resource |
|
|
@Resource |
|
|
private ShiroRealm shiroRealm; |
|
|
private ShiroRealm shiroRealm; |
|
|
|
|
|
|
|
|
|
|
|
//电子合同模板表 |
|
|
|
|
|
@Resource |
|
|
|
|
|
private IEmployContractTemplateService employContractTemplateService; |
|
|
|
|
|
|
|
|
//电子合同表 |
|
|
//电子合同表 |
|
|
@Resource |
|
|
@Resource |
|
|
@ -61,23 +79,39 @@ public class ContractServiceImpl implements ContractService { |
|
|
//组装查询条件 |
|
|
//组装查询条件 |
|
|
if("0".equals(role)){ |
|
|
if("0".equals(role)){ |
|
|
//用户为个人 |
|
|
//用户为个人 |
|
|
query.eq(EmployContract::getPersonId, hanHaiMember.getId()); |
|
|
|
|
|
|
|
|
query.eq(EmployContract::getEmployeeId, hanHaiMember.getId()); |
|
|
}else if("1".equals(role)){ |
|
|
}else if("1".equals(role)){ |
|
|
//用户为企业 |
|
|
//用户为企业 |
|
|
query.eq(EmployContract::getBossId, hanHaiMember.getId()); |
|
|
query.eq(EmployContract::getBossId, hanHaiMember.getId()); |
|
|
}else { |
|
|
}else { |
|
|
return Result.error("角色类型输入错误,电子合同列表查询失败"); |
|
|
return Result.error("角色类型输入错误,电子合同列表查询失败"); |
|
|
} |
|
|
} |
|
|
if(null != employContract.getSignCompany()){ |
|
|
|
|
|
query.eq(EmployContract::getSignCompany, employContract.getSignCompany()); |
|
|
|
|
|
|
|
|
if(null != employContract.getBossStatus()){ |
|
|
|
|
|
query.eq(EmployContract::getBossStatus, employContract.getBossStatus()); |
|
|
} |
|
|
} |
|
|
if(null != employContract.getSignPerson()){ |
|
|
|
|
|
query.eq(EmployContract::getSignPerson, employContract.getSignPerson()); |
|
|
|
|
|
|
|
|
if(null != employContract.getEmployeeStatus()){ |
|
|
|
|
|
query.eq(EmployContract::getEmployeeStatus, employContract.getEmployeeStatus()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//获取电子合同信息 |
|
|
//获取电子合同信息 |
|
|
Page<EmployContract> pageList = query.page(page); |
|
|
Page<EmployContract> pageList = query.page(page); |
|
|
|
|
|
|
|
|
|
|
|
//电子合同补充公司名称 |
|
|
|
|
|
for (EmployContract record : pageList.getRecords()) { |
|
|
|
|
|
EmployAhthenticationCompany company = ahthenticationCompanyService |
|
|
|
|
|
.lambdaQuery() |
|
|
|
|
|
.eq(EmployAhthenticationCompany::getUserId, record.getBossId()) |
|
|
|
|
|
.one(); |
|
|
|
|
|
record.setCompanyName(company.getCompanyName()); |
|
|
|
|
|
|
|
|
|
|
|
//补充招聘者实名信息 |
|
|
|
|
|
EmployAuthenticationPerson person = authenticationPersonService |
|
|
|
|
|
.lambdaQuery() |
|
|
|
|
|
.eq(EmployAuthenticationPerson::getUserId, record.getEmployeeId()) |
|
|
|
|
|
.one(); |
|
|
|
|
|
record.setEmployeeName(person.getName()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return Result.OK("电子合同列表", pageList); |
|
|
return Result.OK("电子合同列表", pageList); |
|
|
}catch (Exception e){ |
|
|
}catch (Exception e){ |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
@ -88,7 +122,7 @@ public class ContractServiceImpl implements ContractService { |
|
|
|
|
|
|
|
|
//电子合同-获取电子合同详情 |
|
|
//电子合同-获取电子合同详情 |
|
|
@Override |
|
|
@Override |
|
|
public Result<?> queryContracById(String token, String contractId) { |
|
|
|
|
|
|
|
|
public Result<?> queryContractById(String token, String contractId) { |
|
|
//权限验证 |
|
|
//权限验证 |
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
|
|
|
@ -98,6 +132,20 @@ public class ContractServiceImpl implements ContractService { |
|
|
.eq(EmployContract::getId, contractId) |
|
|
.eq(EmployContract::getId, contractId) |
|
|
.one(); |
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
//补充公司名称 |
|
|
|
|
|
EmployAhthenticationCompany company = ahthenticationCompanyService |
|
|
|
|
|
.lambdaQuery() |
|
|
|
|
|
.eq(EmployAhthenticationCompany::getUserId, one.getBossId()) |
|
|
|
|
|
.one(); |
|
|
|
|
|
one.setCompanyName(company.getCompanyName()); |
|
|
|
|
|
|
|
|
|
|
|
//补充招聘者实名信息 |
|
|
|
|
|
EmployAuthenticationPerson person = authenticationPersonService |
|
|
|
|
|
.lambdaQuery() |
|
|
|
|
|
.eq(EmployAuthenticationPerson::getUserId, one.getEmployeeId()) |
|
|
|
|
|
.one(); |
|
|
|
|
|
one.setEmployeeName(person.getName()); |
|
|
|
|
|
|
|
|
return Result.OK("电子合同详情", one); |
|
|
return Result.OK("电子合同详情", one); |
|
|
}catch (Exception e){ |
|
|
}catch (Exception e){ |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
@ -106,48 +154,338 @@ public class ContractServiceImpl implements ContractService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//添加电子合同信息 |
|
|
//添加电子合同信息 |
|
|
public Result<?> addContract(String token, String resumeId) { |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Result<?> addContract(String token, EmployContract contract) { |
|
|
//权限验证 |
|
|
//权限验证 |
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
//返回信息 |
|
|
//返回信息 |
|
|
String message = "电子合同添加失败!"; |
|
|
String message = "电子合同添加失败!"; |
|
|
//电子合同对象 |
|
|
|
|
|
EmployContract contract = new EmployContract(); |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
try{ |
|
|
//获取招聘者id |
|
|
|
|
|
|
|
|
//执行合同添加操作 |
|
|
contract.setBossId(hanHaiMember.getId()); |
|
|
contract.setBossId(hanHaiMember.getId()); |
|
|
|
|
|
boolean result = employContractService.save(contract); |
|
|
|
|
|
if(result){ |
|
|
|
|
|
return Result.OK("电子合同添加成功"); |
|
|
|
|
|
}else { |
|
|
|
|
|
return Result.error("电子合同添加失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//获取招聘者实名公司名称 |
|
|
|
|
|
EmployAhthenticationCompany company = ahthenticationCompanyService |
|
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("电子合同添加失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//修改电子合同信息 |
|
|
|
|
|
@Override |
|
|
|
|
|
public Result<?> updateContract(String token, EmployContract contract) { |
|
|
|
|
|
//权限验证 |
|
|
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
//返回信息 |
|
|
|
|
|
String message = "电子合同修改失败!"; |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
//执行合同添加操作 |
|
|
|
|
|
boolean result = employContractService.updateById(contract); |
|
|
|
|
|
if(result){ |
|
|
|
|
|
return Result.OK("电子合同修改成功"); |
|
|
|
|
|
}else { |
|
|
|
|
|
return Result.error("电子合同修改失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("电子合同修改失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//修改电子合同信息 |
|
|
|
|
|
@Override |
|
|
|
|
|
public Result<?> deleteContract(String token, String contractId) { |
|
|
|
|
|
//权限验证 |
|
|
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
//返回信息 |
|
|
|
|
|
String message = "电子合同删除失败!"; |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
//执行合同添加操作 |
|
|
|
|
|
boolean result = employContractService.removeById(contractId); |
|
|
|
|
|
if(result){ |
|
|
|
|
|
return Result.OK("电子合同删除成功"); |
|
|
|
|
|
}else { |
|
|
|
|
|
return Result.error("电子合同删除失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("电子合同删除失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*********************************************电子合同模板***********************************************************/ |
|
|
|
|
|
//电子合同模板-获取电子合同模板列表 |
|
|
|
|
|
@Override |
|
|
|
|
|
public Result<?> queryContractTemplateList(String token, PageBean pageBean) { |
|
|
|
|
|
//权限验证 |
|
|
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
//分页 |
|
|
|
|
|
Page<EmployContractTemplate> page = new Page<EmployContractTemplate>(pageBean.getPageNo(), pageBean.getPageSize()); |
|
|
|
|
|
LambdaQueryChainWrapper<EmployContractTemplate> query = employContractTemplateService |
|
|
.lambdaQuery() |
|
|
.lambdaQuery() |
|
|
.eq(EmployAhthenticationCompany::getUserId, hanHaiMember.getId()) |
|
|
|
|
|
.one(); |
|
|
|
|
|
contract.setNameA(company.getCompanyName()); |
|
|
|
|
|
|
|
|
.eq(EmployContractTemplate::getUserId, hanHaiMember.getId()); |
|
|
|
|
|
|
|
|
//获取求职者id |
|
|
|
|
|
EmployResume resume = employResumeService.getById(resumeId); |
|
|
|
|
|
contract.setPersonId(resume.getUserId()); |
|
|
|
|
|
|
|
|
//组装查询条件 |
|
|
|
|
|
query.eq(EmployContractTemplate::getUserId, hanHaiMember.getId()); |
|
|
|
|
|
|
|
|
//获取实名用户姓名 |
|
|
|
|
|
EmployAuthenticationPerson person = authenticationPersonService |
|
|
|
|
|
|
|
|
//获取电子合同信息 |
|
|
|
|
|
Page<EmployContractTemplate> pageList = query.page(page); |
|
|
|
|
|
|
|
|
|
|
|
return Result.OK("电子合同列表", pageList); |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("电子合同列表查询失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//电子合同模板-获取电子合同模板详情 |
|
|
|
|
|
@Override |
|
|
|
|
|
public Result<?> queryContractTemplateById(String token, String contractTemplateId) { |
|
|
|
|
|
//权限验证 |
|
|
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
EmployContractTemplate one = employContractTemplateService |
|
|
.lambdaQuery() |
|
|
.lambdaQuery() |
|
|
.eq(EmployAuthenticationPerson::getUserId, resume.getUserId()) |
|
|
|
|
|
|
|
|
.eq(EmployContractTemplate::getId, contractTemplateId) |
|
|
.one(); |
|
|
.one(); |
|
|
contract.setNameB(person.getName()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result.OK("电子合同模板详情", one); |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("电子合同模板详情查询失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//添加电子合同模板信息 |
|
|
|
|
|
public Result<?> addContractTemplate(String token, EmployContractTemplate template) { |
|
|
|
|
|
//权限验证 |
|
|
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
//返回信息 |
|
|
|
|
|
String message = "电子合同模板添加失败!"; |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
//执行合同添加操作 |
|
|
//执行合同添加操作 |
|
|
boolean result = employContractService.save(contract); |
|
|
|
|
|
|
|
|
template.setUserId(hanHaiMember.getId()); |
|
|
|
|
|
boolean result = employContractTemplateService.save(template); |
|
|
if(result){ |
|
|
if(result){ |
|
|
return Result.OK("电子合同添加成功"); |
|
|
|
|
|
|
|
|
return Result.OK("电子合同模板添加成功"); |
|
|
}else { |
|
|
}else { |
|
|
return Result.error("电子合同添加失败"); |
|
|
|
|
|
|
|
|
return Result.error("电子合同模板添加失败"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
}catch (Exception e){ |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
return Result.error("电子合同添加失败"); |
|
|
|
|
|
|
|
|
return Result.error("电子合同模板添加失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//修改电子合同模板信息 |
|
|
|
|
|
public Result<?> updateContractTemplate(String token, EmployContractTemplate template) { |
|
|
|
|
|
//权限验证 |
|
|
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
//返回信息 |
|
|
|
|
|
String message = "电子合同模板修改失败!"; |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
//执行合同添加操作 |
|
|
|
|
|
boolean result = employContractTemplateService.updateById(template); |
|
|
|
|
|
if(result){ |
|
|
|
|
|
return Result.OK("电子合同模板修改成功"); |
|
|
|
|
|
}else { |
|
|
|
|
|
return Result.error("电子合同模板修改失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("电子合同模板修改失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//删除电子合同模板信息 |
|
|
|
|
|
@Override |
|
|
|
|
|
public Result<?> deleteContractTemplate(String token, String templateId) { |
|
|
|
|
|
//权限验证 |
|
|
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
//返回信息 |
|
|
|
|
|
String message = "电子合同模板删除失败!"; |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
//执行合同添加操作 |
|
|
|
|
|
boolean result = employContractTemplateService.removeById(templateId); |
|
|
|
|
|
if(result){ |
|
|
|
|
|
return Result.OK("电子合同模板删除成功"); |
|
|
|
|
|
}else { |
|
|
|
|
|
return Result.error("电子合同模板删除失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("电子合同模板删除失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*********************************************图片与pdf互转*********************************************************/ |
|
|
|
|
|
//pdf转图片base64(一张pdf转成多个base64图片) |
|
|
|
|
|
@Override |
|
|
|
|
|
public Result<?> pdf2imagebase64(String pdfPath){ |
|
|
|
|
|
|
|
|
|
|
|
//String pdfPath = "F:\\upload\\test_1736767131255.pdf";//pdf文件路径 |
|
|
|
|
|
//获取当前时间 |
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); |
|
|
|
|
|
Date now = new Date(); |
|
|
|
|
|
String formattedDate = sdf.format(now); |
|
|
|
|
|
System.out.println(formattedDate); |
|
|
|
|
|
String imagePath = "F:\\temp\\";//图片文件路径 |
|
|
|
|
|
String fileName = formattedDate +"image_";//图片文件名字 |
|
|
|
|
|
|
|
|
|
|
|
//文件流对象 |
|
|
|
|
|
InputStream in = null; |
|
|
|
|
|
|
|
|
|
|
|
List<String> pathList = new ArrayList<>();//图片路径列表 |
|
|
|
|
|
List<String> codeList = new ArrayList<>();//base64列表 |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
org.icepdf.core.pobjects.Document document = new org.icepdf.core.pobjects.Document(); |
|
|
|
|
|
document.setFile(pdfPath); |
|
|
|
|
|
float scale = 2.5f;//缩放比例 |
|
|
|
|
|
float rotation = 0f;//旋转角度 |
|
|
|
|
|
|
|
|
|
|
|
//pdf转图片 |
|
|
|
|
|
for (int i = 0; i < document.getNumberOfPages(); i++) { |
|
|
|
|
|
BufferedImage image = (BufferedImage) |
|
|
|
|
|
document.getPageImage(i, GraphicsRenderingHints.SCREEN, org.icepdf.core.pobjects.Page.BOUNDARY_CROPBOX, rotation, scale); |
|
|
|
|
|
RenderedImage rendImage = image; |
|
|
|
|
|
File fileDir = new File(imagePath); |
|
|
|
|
|
if (!fileDir.exists()) { |
|
|
|
|
|
fileDir.mkdirs(); |
|
|
|
|
|
} |
|
|
|
|
|
String imgName = fileName + i + ".png";//图片名称 |
|
|
|
|
|
String filePath = imagePath + imgName;//图片文件路径 |
|
|
|
|
|
File file = new File(filePath); |
|
|
|
|
|
ImageIO.write(rendImage, "png", file); |
|
|
|
|
|
image.flush(); |
|
|
|
|
|
pathList.add(filePath); |
|
|
|
|
|
} |
|
|
|
|
|
document.dispose();//关闭流 |
|
|
|
|
|
|
|
|
|
|
|
//图片转base64 |
|
|
|
|
|
for (String path : pathList) { |
|
|
|
|
|
String imgFile = path;// 待处理的图片 |
|
|
|
|
|
|
|
|
|
|
|
byte[] data = null; |
|
|
|
|
|
String encode = null; // 返回Base64编码过的字节数组字符串 |
|
|
|
|
|
BASE64Encoder encoder = new BASE64Encoder();// 对字节数组Base64编码 |
|
|
|
|
|
|
|
|
|
|
|
// 读取图片字节数组 |
|
|
|
|
|
in = new FileInputStream(imgFile); |
|
|
|
|
|
data = new byte[in.available()]; |
|
|
|
|
|
in.read(data); |
|
|
|
|
|
encode = encoder.encode(data); |
|
|
|
|
|
codeList.add(encode); |
|
|
|
|
|
} |
|
|
|
|
|
return Result.OK("pdf转图片base64成功", codeList); |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("pdf转图片base64失败", codeList); |
|
|
|
|
|
}finally { |
|
|
|
|
|
try{ |
|
|
|
|
|
if(null != in){ |
|
|
|
|
|
in.close();//关闭文件流 |
|
|
|
|
|
} |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("pdf转图片base64失败", codeList); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//图片转pdf |
|
|
|
|
|
public Result<?> image2pdf(String images){ |
|
|
|
|
|
|
|
|
|
|
|
//获取当前时间 |
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); |
|
|
|
|
|
Date now = new Date(); |
|
|
|
|
|
String formattedDate = sdf.format(now); |
|
|
|
|
|
System.out.println(formattedDate); |
|
|
|
|
|
|
|
|
|
|
|
//String images = "F:\\temp\\image_0.png;F:\\temp\\image_1.png;F:\\temp\\image_2.png";//图片文件地址 |
|
|
|
|
|
String pdfPath = "F:\\temp\\"+formattedDate+".pdf"; // 输出pdf文件路径 |
|
|
|
|
|
String[] imageList = images.split(";"); |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
ArrayList<String> imageUrllist = new ArrayList<String>(); //图片list集合 |
|
|
|
|
|
for (int i=0; i<imageList.length; i++) { |
|
|
|
|
|
imageUrllist.add(imageList[i]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
File file = Pdf(imageUrllist, pdfPath);//生成pdf |
|
|
|
|
|
file.createNewFile(); |
|
|
|
|
|
|
|
|
|
|
|
return Result.OK("图片转pdf成功", pdfPath); |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
|
|
|
|
return Result.error("图片转pdf失败", pdfPath); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
//生成pdf |
|
|
|
|
|
public static File Pdf(ArrayList<String> imageUrllist, String mOutputPdfFileName) { |
|
|
|
|
|
Document doc = new Document(PageSize.A4, 0, 0, 0, 0); //new一个pdf文档 |
|
|
|
|
|
try { |
|
|
|
|
|
PdfWriter.getInstance(doc, new FileOutputStream(mOutputPdfFileName)); //pdf写入 |
|
|
|
|
|
doc.open();//打开文档 |
|
|
|
|
|
for (int i = 0; i < imageUrllist.size(); i++) { //循环图片List,将图片加入到pdf中 |
|
|
|
|
|
doc.newPage(); //在pdf创建一页 |
|
|
|
|
|
Image png1 = Image.getInstance(imageUrllist.get(i)); //通过文件路径获取image |
|
|
|
|
|
float heigth = png1.getHeight(); |
|
|
|
|
|
float width = png1.getWidth(); |
|
|
|
|
|
int percent = getPercent2(heigth, width); |
|
|
|
|
|
png1.setAlignment(Image.MIDDLE); |
|
|
|
|
|
png1.scalePercent(percent + 3);// 表示是原来图像的比例; |
|
|
|
|
|
doc.add(png1); |
|
|
|
|
|
} |
|
|
|
|
|
doc.close(); |
|
|
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} catch (DocumentException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
File mOutputPdfFile = new File(mOutputPdfFileName); //输出流 |
|
|
|
|
|
if (!mOutputPdfFile.exists()) { |
|
|
|
|
|
mOutputPdfFile.deleteOnExit(); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
return mOutputPdfFile; //反回文件输出流 |
|
|
|
|
|
} |
|
|
|
|
|
public static int getPercent2(float h, float w) { |
|
|
|
|
|
int p = 0; |
|
|
|
|
|
float p2 = 0.0f; |
|
|
|
|
|
p2 = 530 / w * 100; |
|
|
|
|
|
p = Math.round(p2); |
|
|
|
|
|
return p; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |