采购信息生成PDF

product
chuang 2 years ago
parent 5581a01ccc
commit 7945bc8d91

@ -4,21 +4,17 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import jnpf.base.ActionResult; import jnpf.base.ActionResult;
import jnpf.contractfile.model.contractfile.ContractFileListQueryModel; import jnpf.contractfile.model.contractfile.ContractFileListQueryModel;
import jnpf.mobilePort.utils.ExportPdf; import jnpf.purchaseorder.service.PurchaseorderitemService;
import jnpf.util.JsonUtil; import jnpf.util.JsonUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.ByteArrayOutputStream; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
@Slf4j @Slf4j
@RestController @RestController
@ -26,43 +22,46 @@ import java.util.Map;
@RequestMapping("/api/info") @RequestMapping("/api/info")
public class MobilePortController { public class MobilePortController {
@Resource
private PurchaseorderitemService purchaseorderitemService;
@GetMapping(value = "/exportPdf", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) @GetMapping(value = "/exportPdf", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<byte[]> exportBillInfo() { public ResponseEntity<byte[]> exportBillInfo() {
byte[] bytes = null; // byte[] bytes = null;
HttpHeaders headers = null; // HttpHeaders headers = null;
ByteArrayOutputStream out=null; // ByteArrayOutputStream out=null;
try { // try {
ExportPdf exportPdf = new ExportPdf(); // ExportPdf exportPdf = new ExportPdf();
//渲染模板参数 // //渲染模板参数
Map map=new HashMap(); // Map map=new HashMap();
map.put("title","标题"); // map.put("title","标题");
map.put("name", "老王"); // map.put("name", "老王");
//repotData自己加测试数据 // //repotData自己加测试数据
map.put("repotData", new ArrayList<>()); // map.put("repotData", new ArrayList<>());
//
out= exportPdf.createPdf(map, "test.ftl", "/templates/export"); // out= exportPdf.createPdf(map, "test.ftl", "/templates/export");
bytes = out.toByteArray(); // bytes = out.toByteArray();
String fileName="测试.pdf"; // String fileName="测试.pdf";
fileName = URLEncoder.encode(fileName, "utf-8"); // fileName = URLEncoder.encode(fileName, "utf-8");
headers = new HttpHeaders(); // headers = new HttpHeaders();
headers.add("Content-Disposition", // headers.add("Content-Disposition",
"attachment; filename=" + fileName); // "attachment; filename=" + fileName);
//"attachment; filename=" + new String(fileName.getBytes("gbk"), StandardCharsets.ISO_8859_1)); // //"attachment; filename=" + new String(fileName.getBytes("gbk"), StandardCharsets.ISO_8859_1));
} catch (Exception e) { // } catch (Exception e) {
log.error("导出pdf失败:{}", e); // log.error("导出pdf失败:{}", e);
// throw new SubBusinessException(ErrorCode.FILE_DOWNLOAD_ERROR, "导出pdf失败!"); //// throw new SubBusinessException(ErrorCode.FILE_DOWNLOAD_ERROR, "导出pdf失败!");
//
}finally { // }finally {
if (null!=out){ // if (null!=out){
try { // try {
out.close(); // out.close();
} catch (IOException e) { // } catch (IOException e) {
log.error("out close error:{}", e); // log.error("out close error:{}", e);
} // }
} // }
} // }
return new ResponseEntity<>(bytes, headers, HttpStatus.OK); // return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
return purchaseorderitemService.getPdfInfo();
} }

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

@ -9,6 +9,8 @@ import jnpf.purchaseorder.entity.CollectionpoEntity;
import jnpf.purchaseorder.entity.PurchaseorderitemEntity; import jnpf.purchaseorder.entity.PurchaseorderitemEntity;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import jnpf.purchaseorder.model.purchaseorder.PurchaseorderPagination; import jnpf.purchaseorder.model.purchaseorder.PurchaseorderPagination;
import org.springframework.http.ResponseEntity;
import java.util.*; import java.util.*;
/** /**
* *
@ -19,6 +21,7 @@ import java.util.*;
* 2023-02-01 * 2023-02-01
*/ */
public interface PurchaseorderitemService extends IService<PurchaseorderitemEntity> { public interface PurchaseorderitemService extends IService<PurchaseorderitemEntity> {
public ResponseEntity<byte[]> getPdfInfo();
List<PurchaseOrderVO> getPMap(PurchaseorderPagination purchaseorderPagination); List<PurchaseOrderVO> getPMap(PurchaseorderPagination purchaseorderPagination);

@ -8,22 +8,33 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.mobilePort.entity.PurchaseOrderVO; import jnpf.mobilePort.entity.PurchaseOrderVO;
import jnpf.mobilePort.utils.ExportPdf;
import jnpf.permission.model.authorize.AuthorizeConditionModel; import jnpf.permission.model.authorize.AuthorizeConditionModel;
import jnpf.permission.service.AuthorizeService; import jnpf.permission.service.AuthorizeService;
import jnpf.purchaseorder.entity.*; import jnpf.purchaseorder.entity.*;
import jnpf.purchaseorder.mapper.PurchaseorderitemMapper; import jnpf.purchaseorder.mapper.PurchaseorderitemMapper;
import jnpf.purchaseorder.model.purchaseorder.PurchaseorderPagination; import jnpf.purchaseorder.model.purchaseorder.PurchaseorderPagination;
import jnpf.purchaseorder.model.purchaseorder.Purchaseorder_item0Model;
import jnpf.purchaseorder.service.*; import jnpf.purchaseorder.service.*;
import jnpf.util.ServletUtil; import jnpf.util.ServletUtil;
import jnpf.util.StringUtil; import jnpf.util.StringUtil;
import jnpf.util.UserProvider; import jnpf.util.UserProvider;
import org.springframework.beans.factory.annotation.Autowired; 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.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* *
@ -62,6 +73,75 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
@Resource @Resource
private PurchaseorderitemMapper purchaseorderitemMapper; private PurchaseorderitemMapper purchaseorderitemMapper;
@Override
public ResponseEntity<byte[]> getPdfInfo(){
PurchaseorderPagination pagination = new PurchaseorderPagination();
pagination.setDocumentNo("cgdj2023020300000001");
List<PurchaseOrderVO> pMap = this.getPMap(pagination);
if (pMap!=null&&pMap.size()>0){
PurchaseOrderVO pVO = pMap.get(0);
byte[] bytes = null;
HttpHeaders headers = null;
ByteArrayOutputStream out=null;
try {
ExportPdf exportPdf = new ExportPdf();
//渲染模板参数
Map map=new HashMap();
map.put("title","济钢城市矿产科技有限公司");
map.put("name", "城市矿产再生资源事业部");
map.put("creatorTime", pVO.getCreatorTime());
map.put("contractNo", pVO.getContractNo());
map.put("contractCode",pVO.getContractCode());
map.put("supplierName", pVO.getSupplierName());
List<Purchaseorder_item0Model> list = pVO.getPurchaseorder_item0List();
Integer settlement=0;
BigDecimal settlementSum = new BigDecimal(settlement);
Integer amount=0;
BigDecimal amountSum = new BigDecimal(amount);
for (int i = 0; i < list.size(); i++) {
Purchaseorder_item0Model model = list.get(i);
settlementSum=settlementSum.add(new BigDecimal(model.getSettlement())) ;
amountSum=amountSum.add(new BigDecimal(model.getAmount()));
model.setSettlement(new BigDecimal(model.getSettlement()).setScale(2,BigDecimal.ROUND_HALF_DOWN).toString());
model.setPrice(new BigDecimal(model.getPrice()).setScale(2,BigDecimal.ROUND_HALF_DOWN).toString());
model.setAmount(new BigDecimal(model.getAmount()).setScale(2,BigDecimal.ROUND_HALF_DOWN).toString());
}
map.put("settlementSum",settlementSum.setScale(2,BigDecimal.ROUND_HALF_DOWN).toString());
map.put("amountSum",amountSum.setScale(2,BigDecimal.ROUND_HALF_DOWN).toString() );
map.put("reportList", list);
System.out.println(map.toString());
System.out.println("AAAAAAAAAAAAAAAAAAAAAA ");
//repotData自己加测试数据
out= exportPdf.createPdf(map, "test.ftl", "/templates/export");
bytes = out.toByteArray();
String fileName="测试.pdf";
fileName = URLEncoder.encode(fileName, "utf-8");
headers = new HttpHeaders();
headers.add("Content-Disposition",
"attachment; filename=" + fileName);
//"attachment; filename=" + new String(fileName.getBytes("gbk"), StandardCharsets.ISO_8859_1));
} catch (Exception e) {
log.error("导出pdf失败:{}", e);
// throw new SubBusinessException(ErrorCode.FILE_DOWNLOAD_ERROR, "导出pdf失败!");
}finally {
if (null!=out){
try {
out.close();
} catch (IOException e) {
log.error("out close error:{}", e);
}
}
}
return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
}
return null;
}
@Override @Override
public List<PurchaseOrderVO> getPMap(PurchaseorderPagination purchaseorderPagination) { public List<PurchaseOrderVO> getPMap(PurchaseorderPagination purchaseorderPagination) {
// QueryWrapper<PurchaseorderitemEntity> wrapper = new QueryWrapper<>(); // QueryWrapper<PurchaseorderitemEntity> wrapper = new QueryWrapper<>();
@ -417,24 +497,28 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
queryWrapper.lambda().eq(Purchaseorder_item0Entity::getPurchaseorderId, id); queryWrapper.lambda().eq(Purchaseorder_item0Entity::getPurchaseorderId, id);
return purchaseorder_item0Service.list(queryWrapper); return purchaseorder_item0Service.list(queryWrapper);
} }
@Override @Override
public List<Invoices_item0itemEntity> GetInvoices_item0itemList(String id){ public List<Invoices_item0itemEntity> GetInvoices_item0itemList(String id){
QueryWrapper<Invoices_item0itemEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<Invoices_item0itemEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Invoices_item0itemEntity::getInvoicesId, id); queryWrapper.lambda().eq(Invoices_item0itemEntity::getInvoicesId, id);
return invoices_item0itemService.list(queryWrapper); return invoices_item0itemService.list(queryWrapper);
} }
@Override @Override
public List<PaymentitemEntity> GetPaymentitemList(String id){ public List<PaymentitemEntity> GetPaymentitemList(String id){
QueryWrapper<PaymentitemEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<PaymentitemEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(PaymentitemEntity::getPaymentno, id); queryWrapper.lambda().eq(PaymentitemEntity::getPaymentno, id);
return paymentitemService.list(queryWrapper); return paymentitemService.list(queryWrapper);
} }
@Override @Override
public List<PurchasebackitemEntity> GetPurchasebackitemList(String id){ public List<PurchasebackitemEntity> GetPurchasebackitemList(String id){
QueryWrapper<PurchasebackitemEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<PurchasebackitemEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(PurchasebackitemEntity::getPurchaseOrderId, id); queryWrapper.lambda().eq(PurchasebackitemEntity::getPurchaseOrderId, id);
return purchasebackitemService.list(queryWrapper); return purchasebackitemService.list(queryWrapper);
} }
@Override @Override
public List<CollectionpoEntity> GetCollectionitemList(String id){ public List<CollectionpoEntity> GetCollectionitemList(String id){
QueryWrapper<CollectionpoEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<CollectionpoEntity> queryWrapper = new QueryWrapper<>();

@ -15,19 +15,19 @@
<result property="supplierName" column="supplierName"/> <result property="supplierName" column="supplierName"/>
<!-- 订单号 --> <!-- 订单号 -->
<result property="documentNo" column="documentNo"/> <result property="documentNo" column="documentNo"/>
<collection property="purchaseorder_item0List"> <collection property="purchaseorder_item0List" javaType="List" ofType="jnpf.purchaseorder.model.purchaseorder.Purchaseorder_item0Model">
<!-- `物料名称、规格型号`--> <!-- `物料名称、规格型号`-->
<result property="materialName" column="materialName"/> <result property="materialName" column="materialName"/>
<!-- 税率--> <!-- 税率-->
<result property="rate" column="rate"/> <result property="rate" column="rate1"/>
<!-- 单价--> <!-- 单价-->
<result property="price" column="price"/> <result property="price" column="price1"/>
<!-- 数量--> <!-- 数量-->
<result property="settlement" column="settlement"/> <result property="settlement" column="settlement1"/>
<!-- 单位--> <!-- 单位-->
<result property="unit" column="unit"/> <result property="unit" column="unit1"/>
<!-- 金额--> <!-- 金额-->
<result property="amount" column="amount"/> <result property="amount" column="amount1"/>
</collection> </collection>
</resultMap> </resultMap>
@ -37,7 +37,7 @@
FROM FROM
( (
SELECT SELECT
a.*, a.DOCUMENT_NO,
a.creator_user_name AS `creatorUserName`, a.creator_user_name AS `creatorUserName`,
a.creator_time AS `creatorTime`, a.creator_time AS `creatorTime`,
a.contract_no AS `contractNo`, a.contract_no AS `contractNo`,
@ -59,11 +59,11 @@
WHEN '4' THEN WHEN '4' THEN
3 ELSE b.unit 3 ELSE b.unit
END END
) AS `rate`, ) AS `rate1`,
AVG( b.price ) AS `price`, AVG( b.price ) AS `price1`,
SUM( b.settlement ) AS `settlement`, SUM( b.settlement ) AS `settlement1`,
( CASE b.unit WHEN 0 THEN '吨' ELSE '千克' END ) AS `unit`, ( CASE b.unit WHEN 0 THEN '吨' ELSE '千克' END ) AS `unit1`,
SUM( b.amount ) `amount` SUM( b.amount ) `amount1`
FROM FROM
jg_purchaseorder AS a jg_purchaseorder AS a
LEFT JOIN jg_purchaseorder_item0 AS b ON a.id = b.purchaseorder_id LEFT JOIN jg_purchaseorder_item0 AS b ON a.id = b.purchaseorder_id

@ -7,8 +7,7 @@
</title> </title>
<style> <style>
body { body {
font-family: SimSun; font-family: SimSun;}
transform: rotate(90deg); height: 100vw; width: 100vh; transform-origin: 0% 100%; top: -100vw; }
tr{ tr{
font-size: 12px; font-size: 12px;
@ -18,38 +17,38 @@
</style> </style>
</head> </head>
<body> <body>
<div class='wrapper'>
<div id="caption" class="msg">
<h2 style="text-align: center">${title!""}</h2>
<br/> <br/>
<br/> <br/>
<p style="font-weight: bold">业务部门:${name!""}</p>
<#--<p style="text-indent: 2em">用户名称:</p>-->
<br/> <br/>
<br/> <br/>
<p style="font-weight: bold">集合:</p> <br/>
<br/>
<h1 style="text-align: center">${title!""}</h1>
<p style="font-weight: bold">业务部门:${name!""}</p>
<table border="1" cellspacing="0" width="100%"> <table border="1" cellspacing="0" width="100%">
<tr bgcolor="#6495ed" style="line-height: 80px" > <tr bgcolor="#6495ed" style="line-height: 44px" >
<td colspan="2" rowspan="2">订单日期</td> <td colspan="2" rowspan="2">订单日期</td>
<td colspan="3" rowspan="2">2022-12-02</td> <td colspan="3" rowspan="2">${creatorTime!""}</td>
<td colspan="4" rowspan="2">对方合同编号</td> <td colspan="4" rowspan="2">对方合同编号</td>
<td colspan="5" rowspan="2">对方合同编号</td> <td colspan="5" rowspan="2">${contractNo!""}</td>
<td colspan="4" rowspan="2">合同编号</td> <td colspan="4" rowspan="2">合同编号</td>
<td colspan="5" rowspan="2">合同编号</td> <td colspan="5" rowspan="2">${contractCode!""}</td>
</tr> </tr>
<tr bgcolor="#6495ed" style=""> <tr bgcolor="#6495ed" style="">
</tr> </tr>
<tr bgcolor="#6495ed" style="line-height: 80px"> <tr bgcolor="#6495ed" style="line-height: 44px">
<td colspan="2" rowspan="2">供货单位</td> <td colspan="2" rowspan="2">供货单位</td>
<td colspan="21" rowspan="2">2022-12-02</td> <td colspan="21" rowspan="2">${supplierName!""}</td>
</tr> </tr>
<tr bgcolor="#6495ed" style=""> <tr bgcolor="#6495ed" style="">
</tr> </tr>
<tr bgcolor="#6495ed" style="line-height: 40px"> <tr bgcolor="#6495ed" style="line-height: 22px">
<td colspan="4">订单号</td> <td colspan="4">订单号</td>
<td colspan="1">行号</td> <td colspan="1">行号</td>
<td colspan="7">物料名称、规格型号</td> <td colspan="7">物料名称、规格型号</td>
@ -64,63 +63,39 @@
</tr> </tr>
<#if reportList?? && (reportList?size>0)>
<tr bgcolor="#6495ed" style="line-height: 40px"> <#list reportList as reportData>
<td colspan="4">订单号</td> <#if reportData??>
<td colspan="1">行号</td> <#if reportData_index == 0>
<td colspan="7">废钢</td> <tr bgcolor="#6495ed" style="line-height: 22px">
<td colspan="2">数量</td> <td colspan="4">${reportData.documentNo!""}</td>
<td colspan="2">吨</td> <td colspan="1">${reportData_index+1!""}</td>
<td colspan="3">单价</td> <td colspan="7">${reportData.materialName!""}</td>
<td colspan="3">金额</td> <td colspan="2">${reportData.settlement!""}</td>
<td colspan="1">税率</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>
</tr> </tr>
<tr bgcolor="#6495ed" style="line-height: 40px"> </#if>
</#if>
</#list>
</#if>
<tr bgcolor="#6495ed" style="line-height: 22px">
<td colspan="4">合计</td> <td colspan="4">合计</td>
<td colspan="1"></td> <td colspan="1"></td>
<td colspan="7"></td> <td colspan="7"></td>
<td colspan="2">数量</td> <td colspan="2">${settlementSum!""}</td>
<td colspan="2"></td> <td colspan="2"></td>
<td colspan="3"></td> <td colspan="3"></td>
<td colspan="3">金额</td> <td colspan="3">${amountSum!""}</td>
<td colspan="1"></td> <td colspan="1"></td>
</tr> </tr>
<#-- <#if reportList?? && (reportList?size>0)>-->
<#-- <#list reportList as reportData>-->
<#-- <#if reportData??>-->
<#-- <#if reportData_index == 0>-->
<#-- <tr style="page-break-inside: avoid;page-break-after: auto;">-->
<#-- <td width="10%" style="word-break: break-all;word-wrap: break-word">${reportData.column1!""}</td>-->
<#-- <td width="15%" style="word-break: break-all;word-wrap: break-word">${reportData.column2!""}</td>-->
<#-- <td width="10%" style="word-break: break-all;word-wrap: break-word">${reportData.column3!""}</td>-->
<#-- <td width="25%" style="word-break: break-all;word-wrap: break-word">${reportData.column4!""}</td>-->
<#-- <td width="20%" style="word-break: break-all;word-wrap: break-word">${reportData.column5!""}</td>-->
<#-- <td width="10%" style="word-break: break-all;word-wrap: break-word">${reportData.column6!""}</td>-->
<#-- <td width="10%" style="word-break: break-all;word-wrap: break-word">${reportData.column7!""}</td>-->
<#-- </tr>-->
<#-- <#else >-->
<#-- <#assign preData=reportList[reportData_index-1] />-->
<#-- <tr style="page-break-inside: avoid;page-break-after: auto;">-->
<#-- <td width="10%" style="word-break: break-all;word-wrap: break-word">${reportData.column1!""}</td>-->
<#-- <td width="15%" style="word-break: break-all;word-wrap: break-word">${reportData.column2!""}</td>-->
<#-- <td width="10%" style="word-break: break-all;word-wrap: break-word">${reportData.column3!""}</td>-->
<#-- <td width="25%" style="word-break: break-all;word-wrap: break-word">${reportData.column4!""}</td>-->
<#-- <td width="20%" style="word-break: break-all;word-wrap: break-word">${reportData.column5!""}</td>-->
<#-- <td width="10%" style="word-break: break-all;word-wrap: break-word">${reportData.column6!""}</td>-->
<#-- <td width="10%" style="word-break: break-all;word-wrap: break-word">${reportData.column7!""}</td>-->
<#-- </tr>-->
<#-- </#if>-->
<#-- </#if>-->
<#-- </#list>-->
<#-- </#if>-->
</table> </table>
<br/> <br/>
<br/> <br/>
</div>
</div>
</body> </body>
</html> </html>

Loading…
Cancel
Save