采购信息生成PDF(2023年2月18日)

product
chuang 2 years ago
parent a8164ce17c
commit 13f8fda108

@ -0,0 +1,117 @@
package jnpf.mobilePort.utils;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* @Author: WangChuang
* @Date: 18/2/2023 1:50
* @Description //注释:
* fileMultipartFileMockMultipartFile
* * spring-test
* * MultipartFile
* * MockMultipartFile
* @Version 1.0
*/
public class MultipartFileDto implements MultipartFile {
private final String name;
private String originalFilename;
private String contentType;
private final byte[] content;
/**
* Create a new MultipartFileDto with the given content.
* @param name the name of the file
* @param content the content of the file
*/
public MultipartFileDto(String name, byte[] content) {
this(name, "", null, content);
}
/**
* Create a new MultipartFileDto with the given content.
* @param name the name of the file
* @param contentStream the content of the file as stream
* @throws IOException if reading from the stream failed
*/
public MultipartFileDto(String name, InputStream contentStream) throws IOException {
this(name, "", null, FileCopyUtils.copyToByteArray(contentStream));
}
/**
* Create a new MultipartFileDto with the given content.
* @param name the name of the file
* @param originalFilename the original filename (as on the client's machine)
* @param contentType the content type (if known)
* @param content the content of the file
*/
public MultipartFileDto(String name, String originalFilename, String contentType, byte[] content) {
this.name = name;
this.originalFilename = (originalFilename != null ? originalFilename : "");
this.contentType = contentType;
this.content = (content != null ? content : new byte[0]);
}
/**
* Create a new MultipartFileDto with the given content.
* @param name the name of the file
* @param originalFilename the original filename (as on the client's machine)
* @param contentType the content type (if known)
* @param contentStream the content of the file as stream
* @throws IOException if reading from the stream failed
*/
public MultipartFileDto(String name, String originalFilename, String contentType, InputStream contentStream)
throws IOException {
this(name, originalFilename, contentType, FileCopyUtils.copyToByteArray(contentStream));
}
@Override
public String getName() {
return this.name;
}
@Override
public String getOriginalFilename() {
return this.originalFilename;
}
@Override
public String getContentType() {
return this.contentType;
}
@Override
public boolean isEmpty() {
return (this.content.length == 0);
}
@Override
public long getSize() {
return this.content.length;
}
@Override
public byte[] getBytes() throws IOException {
return this.content;
}
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(this.content);
}
@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
FileCopyUtils.copy(this.content, dest);
}
}

@ -1,11 +0,0 @@
package jnpf.mobilePort.utils;
/**
* @Author: WangChuang
* @Date: 17/2/2023 5:48
* @Description //注释:
* @Version 1.0
*/
public class WBigDecimalUtils {
}

@ -7,8 +7,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.config.ConfigValueUtil;
import jnpf.mobilePort.entity.PurchaseOrderVO;
import jnpf.mobilePort.utils.ExportPdf;
import jnpf.mobilePort.utils.MultipartFileDto;
import jnpf.permission.model.authorize.AuthorizeConditionModel;
import jnpf.permission.service.AuthorizeService;
import jnpf.purchaseorder.entity.*;
@ -19,15 +21,16 @@ import jnpf.purchaseorder.service.*;
import jnpf.util.ServletUtil;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import org.apache.http.entity.ContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.*;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.net.URLEncoder;
@ -73,6 +76,8 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
@Resource
private PurchaseorderitemMapper purchaseorderitemMapper;
@Resource
private ConfigValueUtil configValueUtil;
@Override
public ResponseEntity<byte[]> getPdfInfo(){
PurchaseorderPagination pagination = new PurchaseorderPagination();
@ -93,7 +98,7 @@ if (pMap!=null&&pMap.size()>0){
map.put("contractNo", pVO.getContractNo());
map.put("contractCode",pVO.getContractCode());
map.put("supplierName", pVO.getSupplierName());
map.put("documentNo",pVO.getDocumentNo());
List<Purchaseorder_item0Model> list = pVO.getPurchaseorder_item0List();
Integer settlement=0;
BigDecimal settlementSum = new BigDecimal(settlement);
@ -118,11 +123,27 @@ if (pMap!=null&&pMap.size()>0){
out = exportPdf.createPdf(map, "test.ftl", "/templates/export");
bytes = out.toByteArray();
String fileName="测试.pdf";
String fileName="废钢采购订单("+map.get("supplierName")+")("+map.get("creatorTime")+").pdf";
fileName = URLEncoder.encode(fileName, "utf-8");
headers = new HttpHeaders();
headers.add("Content-Disposition",
"attachment; filename=" + fileName);
// 存在本地文件中
InputStream inputStream = new ByteArrayInputStream(bytes);
MultipartFile file = new MultipartFileDto(ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);
String templateFilePath = configValueUtil.getTemplateFilePath();
// FileUtil.upFile(file, templateFilePath+"/wc/", fileName);
try {
File f = new File(templateFilePath+"/wc/", fileName);
//将上传的文件存储到指定位置
file.transferTo(f);
}catch (Exception e){
e.printStackTrace();
}
//"attachment; filename=" + new String(fileName.getBytes("gbk"), StandardCharsets.ISO_8859_1));
} catch (Exception e) {
log.error("导出pdf失败:{}", e);

@ -30,9 +30,9 @@
<p style="font-weight: bold">业务部门:${name!""}</p>
<table border="1" cellspacing="0" width="100%">
<tr bgcolor="#6495ed" style="line-height: 44px" >
<td colspan="2" rowspan="2">订单日期</td>
<td colspan="3" rowspan="2">${creatorTime!""}</td>
<td colspan="4" rowspan="2">对方合同编号</td>
<td colspan="1" rowspan="2">订单日期</td>
<td colspan="5" rowspan="2">${creatorTime!""}</td>
<td colspan="3" rowspan="2">对方合同编号</td>
<td colspan="5" rowspan="2">${contractNo!""}</td>
<td colspan="4" rowspan="2">合同编号</td>
<td colspan="5" rowspan="2">${contractCode!""}</td>
@ -42,21 +42,21 @@
</tr>
<tr bgcolor="#6495ed" style="line-height: 44px">
<td colspan="2" rowspan="2">供货单位</td>
<td colspan="21" rowspan="2">${supplierName!""}</td>
<td colspan="1" rowspan="2">供货单位</td>
<td colspan="22" rowspan="2">${supplierName!""}</td>
</tr>
<tr bgcolor="#6495ed" style="">
</tr>
<tr bgcolor="#6495ed" style="line-height: 22px">
<td colspan="4">订单号</td>
<td colspan="3">订单号</td>
<td colspan="1">行号</td>
<td colspan="7">物料名称、规格型号</td>
<td colspan="5">物料名称、规格型号</td>
<td colspan="2">数量</td>
<td colspan="2">单位</td>
<td colspan="3">单价(含税)</td>
<td colspan="3">金额(含税)</td>
<td colspan="1">税率(含税)</td>
<td colspan="1">税率</td>
</tr>
<tr>
@ -68,29 +68,34 @@
<#if reportData??>
<#if reportData_index == 0>
<tr bgcolor="#6495ed" style="line-height: 22px">
<td colspan="4">${reportData.documentNo!""}</td>
<td colspan="1">${reportData_index+1!""}</td>
<td colspan="7">${reportData.materialName!""}</td>
<td colspan="2">${reportData.settlement!""}</td>
<td colspan="2">${reportData.unit!""}</td>
<td colspan="3">${reportData.price!""}</td>
<td colspan="3">${reportData.amount!""}</td>
<td colspan="1">${reportData.rate!""}</td>
<td colspan="3">${documentNo!""}</td>
<td colspan="1" style="text-align: center">${reportData_index+1!""}</td>
<td colspan="5">${reportData.materialName!""}</td>
<td colspan="2" style="text-align: center">${reportData.settlement!""}</td>
<td colspan="2" style="text-align: center">${reportData.unit!""}</td>
<td colspan="3" style="text-align: center">${reportData.price!""}</td>
<td colspan="3" style="text-align: center">${reportData.amount!""}</td>
<td colspan="1" style="text-align: center">${reportData.rate!""}</td>
</tr>
<tr>
</tr>
</#if>
</#if>
</#list>
</#if>
<tr bgcolor="#6495ed" style="line-height: 22px">
<td colspan="4">合计</td>
<td colspan="3">合计</td>
<td colspan="1"></td>
<td colspan="7"></td>
<td colspan="2">${settlementSum!""}</td>
<td colspan="5"></td>
<td colspan="2" style="text-align: center">${settlementSum!""}</td>
<td colspan="2"></td>
<td colspan="3"></td>
<td colspan="3">${amountSum!""}</td>
<td colspan="3" style="text-align: center">${amountSum!""}</td>
<td colspan="1"></td>
</tr>

Loading…
Cancel
Save