后台代码

//出货清单
@RequestMapping(params="getBusinessOutDetail")
public void getBusinessOutDetail(HttpServletRequest req,HttpServletResponse response,String id,String codes) throws IOException {
String impTypess = req.getParameter("impTypess");//1、打印 2、预览 3、打印并预览
if("1".equals(impTypess)){
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("收货清单.pdf" , "UTF-8"));
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
}
List<BusinessExpressEntity> expList = new ArrayList<>();
StringBuilder code = new StringBuilder("");
String productAllName = "";
String[] arr = codes.split(",");
for (String s : arr) {
BusinessExpressEntity express = systemService.findByProperty(BusinessExpressEntity.class, "shipmentLabelcode",s).get(0);
expList.add(express);
code.append("'" + s + "',");
productAllName += express.getProductName() + ",";
} String sql = " SELECT e.id,e.business_serveinvoicecode,e.consignee_country,e.product_name,e.business_pieces,e.business_grossweight,e.business_customervolumnweight,e.cargotype_code,group_concat(i.invoice_name SEPARATOR ';' ) as content,SUM(s.total_price) as totalPrice from business_express e \n" +
"LEFT JOIN business_invoice i on i.business_id = e.id\n" +
" LEFT JOIN wms_expenses_payment s on s.business_id = e.id \n" +
" LEFT JOIN business_shipment a on a.id = e.shipment_id \n" +
" where a.shipment_labelcode in ("+code.substring(0,code.length()-1).toString()+") and e.bpm_status!=0 GROUP BY e.id "; RowMapper<BusinessPdfDTO> rowMapper = new BeanPropertyRowMapper<BusinessPdfDTO>(BusinessPdfDTO.class);
List<BusinessPdfDTO> list = jdbcTemplate.query(sql, rowMapper); String typeSql = "SELECT * from t_s_type where typegroupid in (SELECT id from t_s_typegroup where typegroupcode= 'cargo')";
List<Map<String, Object>> typeList = jdbcTemplate.queryForList(typeSql);
HashMap typeMap = new HashMap<String, String>();
for (Map<String,Object> temp : typeList) {
typeMap.put(temp.get("typecode").toString(), temp.get("typename").toString());
} PdfFont font = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H",true); PdfDocument pdf = new PdfDocument(new PdfWriter(response.getOutputStream()));
Document document = new Document(pdf);
document.add(new Paragraph("出货交接清单").setVerticalAlignment(VerticalAlignment.MIDDLE).setTextAlignment(TextAlignment.CENTER).setFont(font).setFontSize(14));
for (BusinessExpressEntity express : expList) {
document.add(new Paragraph("出货信息:"+express.getShipmentLabelcode()+" "+DateUtils.date2Str(new Date(),DateUtils.time_sdf)+" "+express.getCustomerName()).setVerticalAlignment(VerticalAlignment.MIDDLE).setTextAlignment(TextAlignment.LEFT).setFont(font).setFontSize(12));
} Table table = new Table(new float[]{30,70,70,70,70,70,70,70,70,70});
table.addCell(new Cell().add(new Paragraph("序号")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("转单号")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("产品名称")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("件数")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("类型")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("国家")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("实重")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("体积重")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
//table.addCell(new Cell().add(new Paragraph("应收费用")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("备注")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9)); //统计包裹
int bg = 0;
//统计文件
int wj = 0;
double weight = 0;
double price = 0; for (int i=0;i<list.size();i++) {
table.addCell(new Cell().add(new Paragraph((i+1)+"")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph(list.get(i).getBusinessServeinvoicecode())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph(list.get(i).getProductName())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph(list.get(i).getBusinessPieces()+"")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
if (typeMap.containsKey(list.get(i).getCargotypeCode())) {
table.addCell(new Cell().add(new Paragraph(typeMap.get(list.get(i).getCargotypeCode()).toString())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
} else {
table.addCell(new Cell().add(new Paragraph("")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
}
table.addCell(new Cell().add(new Paragraph(list.get(i).getConsigneeCountry())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph(list.get(i).getBusinessGrossweight()==null?"": DecimalUtil.subData(list.get(i).getBusinessGrossweight()+""))).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph(list.get(i).getBusinessCustomervolumnweight()==null? "":list.get(i).getBusinessCustomervolumnweight()+"")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
//table.addCell(new Cell().add(new Paragraph(list.get(i).getTotalPrice()==null? "":list.get(i).getTotalPrice())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("配货:"+list.get(i).getContent())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9)); if("P".equals(list.get(i).getCargotypeCode())){
bg++;
}
if("D".equals(list.get(i).getCargotypeCode())){
wj++;
}
if (list.get(i).getBusinessGrossweight() != null) {
weight += java.lang.Double.parseDouble(list.get(i).getBusinessGrossweight().toString());
}
if (list.get(i).getTotalPrice() != null) {
price += java.lang.Double.parseDouble(list.get(i).getTotalPrice().toString());
} } document.add(table); document.add(new Paragraph("合计 总票数:"+list.size()+" 总实重:"+String.format("%.2f", weight)+" 总费用:"+price).setFont(font).setFontSize(9));
document.add(new Paragraph("包裹:"+bg+" 文件:"+wj).setFont(font).setFontSize(9).setMarginTop(-3));
// document.add(new Paragraph(express.getProductName()+" "+list.size()+" 票").setFont(font).setFontSize(9).setMarginTop(-8));
document.add(new Paragraph(productAllName.substring(0,productAllName.length()-1)+" "+list.size()+" 票").setFont(font).setFontSize(9).setMarginTop(-8)); document.add(new Paragraph("请仔细阅读后确认签字:").setFont(font).setFontSize(9).setMaxHeight(15).setMarginTop(-3));
document.add(new Paragraph("快件交接清单上显示的目的地国家仅供参考,正式录单时会再次确认,最终的目的地国家请以客户账单为准。如果发现快件").setFont(font).setFontSize(9).setMarginTop(-8).setMarginLeft(10));
document.add(new Paragraph("交接清单目的地国家有误,请立即告之快件签入人员或与负责贵司查询事务的客户专员联系,谢谢合作").setFont(font).setFontSize(9).setMarginTop(-8)); document.add(new Paragraph("收货公司签字: _________________ "+" "+"我司出货员: _________________").setFont(font).setFontSize(9).setMarginLeft(10)); document.close();
pdf.close(); }

前台代码:

function printQD() {
var rowsData = $('#businessArrivalList').datagrid('getSelections');
if(rowsData.length==0){
tip("请选择数据");
return false;
}else if(rowsData.length>1){
tip("只能选择一个数据");
return false;
}
var xueurl = "fileFormatController.do?getXbDetail_print&id=&codes=" + rowsData[0].arrivalLabelcode;
$.messager.defaults = { ok: "确定", cancel: "取消" };
const html = '<p id="p"><label for="r">请选择打印方式</label></p><p id="p">'
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="r"><input type="radio" id="r" name="impTypess" value="1" checked>'
+ ' 直接打印</label>'
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="r1"><input type="radio" id="r1" name="impTypess" value="2">'
+ ' 预览</label></p> </p>'
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="r2"><input type="radio" id="r2" name="impTypess" value="3" >'
+ ' 打印并预览</label></p> </p>'
$.messager.confirm("请选择打印方式", html, function (data) {
if (data) {
var impTypess = $("input[name='impTypess']:checked ").val();
xueurl+='&impTypess='+impTypess;
if(impTypess=='2'){//预览
window.open(xueurl);
}else if(impTypess=='3'){//预览并打印
window.open(xueurl);
window.location.href = 'fileFormatController.do?getXbDetail_print&id=&codes=' + rowsData[0].arrivalLabelcode+'&impTypess=1';
}else if(impTypess=='1'){//打印
window.location.href = 'fileFormatController.do?getXbDetail_print&id=&codes=' + rowsData[0].arrivalLabelcode+'&impTypess=1';
}
}
});
//window.location.href = "fileFormatController.do?getXbDetail_print&id=&codes=" + rowsData[0].arrivalLabelcode+"&ylFlag=0";
}

效果:

最新文章

  1. dsp28377控制DM9000收发数据——第二版程序,能够实现手术功能,但是容易掉帧;使用读取中断寄存器的方式判断中断
  2. List排序和去重
  3. MySQL常用操作总结
  4. XAF学习笔记之 Upcasting
  5. HTTP 错误405.0 - Method Not Allowed
  6. linux shell wc 命令
  7. HDU4532(组合DP)
  8. 数组名取地址所算数运算应注意的&amp;quot;trap&amp;quot;
  9. 安卓TextView完美展示html格式代码
  10. 基本数据类型 字典 dict
  11. c/c++ 网络编程 bind函数
  12. 【ASP.NET】Validation 服务器控件
  13. linux 学习笔记 wc命令
  14. web前端知识大纲:系列三 html篇
  15. 机器学习库--dlib
  16. python中字典的用法
  17. .NET读取视频信息、视频截图
  18. HTML的基本知识点
  19. INTEST/EXTEST SCAN 的学习
  20. ibatis.net:第三天,Insert

热门文章

  1. Docker+nginx部署前后端分离项目
  2. C#如何提高代码质量(一)
  3. MyBatis的使用六(解决字段名与成员名不一致)
  4. RA-Depth: Resolution Adaptive Self-Supervised Monocular Depth Estimation
  5. KingbaseES恢复被删除数据
  6. pdf转图片加水印压缩
  7. Gateway服务网关 (入门到使用)
  8. wsl ubuntu vscode 安装 Fira Code
  9. CentOS7登录到控制台后无网络
  10. Rpc-实现Zookeeper注册中心