提交生成合同
This commit is contained in:
		| @@ -1,114 +1,158 @@ | ||||
| package com.ruoyi.custom.domain; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
| import com.ruoyi.common.annotation.Excel; | ||||
| import com.ruoyi.common.core.domain.BaseEntity; | ||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
|  | ||||
| /** | ||||
|  * 合同对象 sys_contract | ||||
|  *  | ||||
|  * | ||||
|  * @author wonder | ||||
|  * @date 2020-10-23 | ||||
|  */ | ||||
| public class SysContract extends BaseEntity | ||||
| { | ||||
| public class SysContract extends BaseEntity { | ||||
|     private static final long serialVersionUID = 1L; | ||||
|  | ||||
|     /** 合同编号 */ | ||||
|     /** | ||||
|      * 合同编号 | ||||
|      */ | ||||
|     @Excel(name = "合同编号") | ||||
|     private Long id; | ||||
|  | ||||
|     /** 客户姓名 */ | ||||
|     /** | ||||
|      * 客户姓名 | ||||
|      */ | ||||
|     @Excel(name = "客户姓名") | ||||
|     private String name; | ||||
|  | ||||
|     /** 电话 */ | ||||
|     /** | ||||
|      * 客户身份证 | ||||
|      */ | ||||
|     private String cusId; | ||||
|  | ||||
|     /** | ||||
|      * 电话 | ||||
|      */ | ||||
|     @Excel(name = "电话") | ||||
|     private String phone; | ||||
|  | ||||
|     /** 服务时间 */ | ||||
|     /** | ||||
|      * 服务时间 | ||||
|      */ | ||||
|     @Excel(name = "服务时间") | ||||
|     private Integer serveTime; | ||||
|  | ||||
|     /** 金额 */ | ||||
|     /** | ||||
|      * 金额 | ||||
|      */ | ||||
|     @Excel(name = "金额") | ||||
|     private BigDecimal amount; | ||||
|  | ||||
|     /** 文件路径 */ | ||||
|     private String amountUpper; | ||||
|  | ||||
|     /** | ||||
|      * 文件路径 | ||||
|      */ | ||||
|     @Excel(name = "文件路径") | ||||
|     private String path; | ||||
|  | ||||
|     public void setId(Long id)  | ||||
|     { | ||||
|     /** | ||||
|      * 合同状态 | ||||
|      * 0-未签订;1-已签订 | ||||
|      */ | ||||
|     private int Status; | ||||
|  | ||||
|     public Long getId() { | ||||
|         return id; | ||||
|     } | ||||
|  | ||||
|     public void setId(Long id) { | ||||
|         this.id = id; | ||||
|     } | ||||
|  | ||||
|     public Long getId()  | ||||
|     { | ||||
|         return id; | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|     public void setName(String name)  | ||||
|     { | ||||
|  | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
|     public String getName()  | ||||
|     { | ||||
|         return name; | ||||
|     public String getPhone() { | ||||
|         return phone; | ||||
|     } | ||||
|     public void setPhone(String phone)  | ||||
|     { | ||||
|  | ||||
|     public void setPhone(String phone) { | ||||
|         this.phone = phone; | ||||
|     } | ||||
|  | ||||
|     public String getPhone()  | ||||
|     { | ||||
|         return phone; | ||||
|     public Integer getServeTime() { | ||||
|         return serveTime; | ||||
|     } | ||||
|     public void setServeTime(Integer serveTime)  | ||||
|     { | ||||
|  | ||||
|     public void setServeTime(Integer serveTime) { | ||||
|         this.serveTime = serveTime; | ||||
|     } | ||||
|  | ||||
|     public Integer getServeTime()  | ||||
|     { | ||||
|         return serveTime; | ||||
|     public BigDecimal getAmount() { | ||||
|         return amount; | ||||
|     } | ||||
|     public void setAmount(BigDecimal amount)  | ||||
|     { | ||||
|  | ||||
|     public String getAmountUpper() { | ||||
|         return amountUpper; | ||||
|     } | ||||
|  | ||||
|     public void setAmountUpper(String amountUpper) { | ||||
|         this.amountUpper = amountUpper; | ||||
|     } | ||||
|  | ||||
|     public void setAmount(BigDecimal amount) { | ||||
|         this.amount = amount; | ||||
|     } | ||||
|  | ||||
|     public BigDecimal getAmount()  | ||||
|     { | ||||
|         return amount; | ||||
|     public String getPath() { | ||||
|         return path; | ||||
|     } | ||||
|     public void setPath(String path)  | ||||
|     { | ||||
|  | ||||
|     public void setPath(String path) { | ||||
|         this.path = path; | ||||
|     } | ||||
|  | ||||
|     public String getPath()  | ||||
|     { | ||||
|         return path; | ||||
|     public int getStatus() { | ||||
|         return Status; | ||||
|     } | ||||
|  | ||||
|     public void setStatus(int status) { | ||||
|         Status = status; | ||||
|     } | ||||
|  | ||||
|     public String getCusId() { | ||||
|         return cusId; | ||||
|     } | ||||
|  | ||||
|     public void setCusId(String cusId) { | ||||
|         this.cusId = cusId; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | ||||
|             .append("id", getId()) | ||||
|             .append("name", getName()) | ||||
|             .append("phone", getPhone()) | ||||
|             .append("serveTime", getServeTime()) | ||||
|             .append("amount", getAmount()) | ||||
|             .append("path", getPath()) | ||||
|             .append("createBy", getCreateBy()) | ||||
|             .append("createTime", getCreateTime()) | ||||
|             .append("updateBy", getUpdateBy()) | ||||
|             .append("updateTime", getUpdateTime()) | ||||
|             .append("remark", getRemark()) | ||||
|             .toString(); | ||||
|         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) | ||||
|                 .append("id", getId()) | ||||
|                 .append("name", getName()) | ||||
|                 .append("cusId", getCusId()) | ||||
|                 .append("status", getStatus()) | ||||
|                 .append("phone", getPhone()) | ||||
|                 .append("serveTime", getServeTime()) | ||||
|                 .append("amount", getAmount()) | ||||
|                 .append("path", getPath()) | ||||
|                 .append("createBy", getCreateBy()) | ||||
|                 .append("createTime", getCreateTime()) | ||||
|                 .append("updateBy", getUpdateBy()) | ||||
|                 .append("updateTime", getUpdateTime()) | ||||
|                 .append("remark", getRemark()) | ||||
|                 .toString(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -58,4 +58,6 @@ public interface ISysContractService | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteSysContractById(Long id); | ||||
|  | ||||
|     public int signContract(SysContract sysContract); | ||||
| } | ||||
|   | ||||
| @@ -1,96 +1,147 @@ | ||||
| package com.ruoyi.custom.service.impl; | ||||
|  | ||||
| import java.util.List; | ||||
| import com.itextpdf.text.Document; | ||||
| import com.itextpdf.text.DocumentException; | ||||
| import com.itextpdf.text.pdf.*; | ||||
| import com.ruoyi.common.utils.DateUtils; | ||||
| import com.ruoyi.custom.domain.SysContract; | ||||
| import com.ruoyi.custom.mapper.SysContractMapper; | ||||
| import com.ruoyi.custom.service.ISysContractService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
| import com.ruoyi.custom.mapper.SysContractMapper; | ||||
| import com.ruoyi.custom.domain.SysContract; | ||||
| import com.ruoyi.custom.service.ISysContractService; | ||||
|  | ||||
| import java.io.ByteArrayOutputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.util.List; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * 合同Service业务层处理 | ||||
|  *  | ||||
|  * | ||||
|  * @author wonder | ||||
|  * @date 2020-10-23 | ||||
|  */ | ||||
| @Service | ||||
| public class SysContractServiceImpl implements ISysContractService  | ||||
| { | ||||
| public class SysContractServiceImpl implements ISysContractService { | ||||
|     @Autowired | ||||
|     private SysContractMapper sysContractMapper; | ||||
|  | ||||
|     /** | ||||
|      * 查询合同 | ||||
|      *  | ||||
|      * | ||||
|      * @param id 合同ID | ||||
|      * @return 合同 | ||||
|      */ | ||||
|     @Override | ||||
|     public SysContract selectSysContractById(Long id) | ||||
|     { | ||||
|     public SysContract selectSysContractById(Long id) { | ||||
|         return sysContractMapper.selectSysContractById(id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询合同列表 | ||||
|      *  | ||||
|      * | ||||
|      * @param sysContract 合同 | ||||
|      * @return 合同 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<SysContract> selectSysContractList(SysContract sysContract) | ||||
|     { | ||||
|     public List<SysContract> selectSysContractList(SysContract sysContract) { | ||||
|         return sysContractMapper.selectSysContractList(sysContract); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 新增合同 | ||||
|      *  | ||||
|      * | ||||
|      * @param sysContract 合同 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int insertSysContract(SysContract sysContract) | ||||
|     { | ||||
|     public int insertSysContract(SysContract sysContract) { | ||||
|         sysContract.setId(DateUtils.getNowDate().getTime()); | ||||
|         sysContract.setCreateTime(DateUtils.getNowDate()); | ||||
|         return sysContractMapper.insertSysContract(sysContract); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改合同 | ||||
|      *  | ||||
|      * | ||||
|      * @param sysContract 合同 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int updateSysContract(SysContract sysContract) | ||||
|     { | ||||
|     public int updateSysContract(SysContract sysContract) { | ||||
|         sysContract.setUpdateTime(DateUtils.getNowDate()); | ||||
|         return sysContractMapper.updateSysContract(sysContract); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 批量删除合同 | ||||
|      *  | ||||
|      * | ||||
|      * @param ids 需要删除的合同ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteSysContractByIds(Long[] ids) | ||||
|     { | ||||
|     public int deleteSysContractByIds(Long[] ids) { | ||||
|         return sysContractMapper.deleteSysContractByIds(ids); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除合同信息 | ||||
|      *  | ||||
|      * | ||||
|      * @param id 合同ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteSysContractById(Long id) | ||||
|     { | ||||
|     public int deleteSysContractById(Long id) { | ||||
|         return sysContractMapper.deleteSysContractById(id); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public int signContract(SysContract sysContract) { | ||||
|         String templatePath = "/Users/wonder/Documents/Workspaces/java/RuoYi-Vue/running/pdf/contract.pdf"; | ||||
|         String filePath = "/Users/wonder/Documents/Workspaces/java/RuoYi-Vue/running" + sysContract.getPath(); | ||||
|         PdfReader reader; | ||||
|         FileOutputStream out; | ||||
|         ByteArrayOutputStream bos; | ||||
|         PdfStamper stamper; | ||||
|  | ||||
|         try { | ||||
|             out = new FileOutputStream(filePath);// 输出流到新的pdf,没有b2.pdf时会创建 | ||||
|             reader = new PdfReader(templatePath);// 读取pdf模板 | ||||
|             bos = new ByteArrayOutputStream(); | ||||
|             stamper = new PdfStamper(reader, bos); | ||||
|             AcroFields form = stamper.getAcroFields(); | ||||
|  | ||||
|             form.setField("name", sysContract.getName()); | ||||
|             form.setField("phone", sysContract.getName()); | ||||
|             form.setField("money", sysContract.getAmount().toString()); | ||||
|             form.setField("moneyUpper", sysContract.getAmountUpper()); | ||||
|             form.setField("date", sysContract.getName()); | ||||
|             form.setField("cusId", sysContract.getCusId()); | ||||
|  | ||||
|  | ||||
|             stamper.setFormFlattening(true);// 如果为false那么生成的PDF文件还能编辑,一定要设为true | ||||
|             stamper.close(); | ||||
|  | ||||
|             Document doc = new Document(); | ||||
|  | ||||
|             PdfCopy copy = new PdfCopy(doc, out); | ||||
|             doc.open(); | ||||
|             PdfImportedPage importPage = null; | ||||
|             for (int i = 1; i <= reader.getNumberOfPages(); i++) { | ||||
|                 importPage = copy | ||||
|                         .getImportedPage(new PdfReader(bos.toByteArray()), i); | ||||
|                 copy.addPage(importPage); | ||||
|             } | ||||
|             doc.close(); | ||||
|         } catch (FileNotFoundException e) { | ||||
|             e.printStackTrace(); | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|         } catch (DocumentException e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         return 0; | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user