Browse Source

打印测试

anderx 6 years ago
parent
commit
45c5b54df6

+ 74 - 0
src/main/java/com/goafanti/common/bo/Prient.java

@@ -0,0 +1,74 @@
+package com.goafanti.common.bo;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.print.PageFormat;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 模板
+ * @author admin
+ * 
+ */
+public class Prient implements Printable {
+	// 菜品集合
+	public static List<Test> testList = new ArrayList<Test>();
+
+	// 设置小票打印
+	public int print(Graphics g, PageFormat pf, int page)
+			throws PrinterException {
+		if (page > 0) {
+			return NO_SUCH_PAGE;
+		}
+		Graphics2D g2d = (Graphics2D) g;
+		// 设置颜色
+		g2d.setColor(Color.BLACK);
+		//模式  字体   字体大小
+		g2d.setFont(new Font("Default", Font.PLAIN, 16));
+		// 参数1:显示内容 参数2:横向偏移 参数3:纵向偏移
+		g2d.drawString("点菜清单", 100, 50);
+		g2d.drawString("------------------------------------------------", 40, 70);
+		g2d.setFont(new Font("Default", Font.PLAIN, 12));
+		g2d.drawString("点餐员:自定义", 40, 90);
+		g2d.drawString("电话:自定义", 40, 110);
+		g2d.drawString("用餐时间:自定义", 40, 130);
+		g2d.drawString("用餐地址:打印测试", 40, 150);
+		g2d.setFont(new Font("Default", Font.PLAIN, 16));
+		g2d.drawString("------------------------------------------------", 40, 170);
+		g2d.drawString("菜品             单价             小计", 40, 190);
+		g2d.setFont(new Font("Default", Font.PLAIN, 12));
+		int H1 = 190;
+		double zmoney = 0;
+		int count = 0;
+		for (Test test : testList) {
+			count = count + 1;
+			H1 = H1 + 20;
+			zmoney = test.getMoney() * test.getNum() + zmoney;
+			g2d.drawString(count + "." + test.getName() + "(" + test.getNum()
+					+ "份)     ¥" + test.getMoney()+"     ¥"+test.getMoney()*test.getNum(), 40, H1);
+		}
+		g2d.setFont(new Font("Default", Font.PLAIN, 16));
+		g2d.drawString("------------------------------------------------", 40, H1 + 20);
+		g2d.setFont(new Font("Default", Font.PLAIN, 12));
+		g2d.drawString("合计:¥" + zmoney, 40, H1 + 40);
+		g2d.drawString("优惠金额:¥" + 20, 40, H1 + 60);
+		g2d.drawString("应收:¥" + (zmoney-20), 40, H1 + 80);
+		g2d.drawString("实收:¥" + zmoney, 40, H1 + 100);
+		g2d.drawString("找零:¥" + 20, 40, H1 + 120);
+		g2d.drawString("收银员:" + "打印测试", 40, H1 + 140);
+		g2d.drawString("谢谢惠顾,欢迎下次光临!", 80, H1 + 160);
+		return PAGE_EXISTS;
+	}
+	public static List<Test> getTestList() {
+		return testList;
+	}
+	public static void setTestList(List<Test> testList) {
+		Prient.testList = testList;
+	}
+}
+

+ 53 - 0
src/main/java/com/goafanti/common/bo/Test.java

@@ -0,0 +1,53 @@
+package com.goafanti.common.bo;
+
+	/**
+	 * 菜品对象
+	 * 
+	 * @author admin
+	 * 
+	 */
+	public class Test {
+		// 菜品名称
+		private String name;
+		// 价格
+		private double money;
+		// 数量
+		private Integer num;
+		//菜品分类
+		private String fenlei;
+
+		public Test() {
+			super();
+		}
+		public Test(String name, double money, Integer num) {
+			super();
+			this.name = name;
+			this.money = money;
+			this.num = num;
+		}
+		public String getName() {
+			return name;
+		}
+		public void setName(String name) {
+			this.name = name;
+		}
+		public double getMoney() {
+			return money;
+		}
+		public void setMoney(double money) {
+			this.money = money;
+		}
+		public Integer getNum() {
+			return num;
+		}
+		public void setNum(Integer num) {
+			this.num = num;
+		}
+		public String getFenlei() {
+			return fenlei;
+		}
+		public void setFenlei(String fenlei) {
+			this.fenlei = fenlei;
+		}
+	}
+

+ 93 - 0
src/main/java/com/goafanti/common/controller/MainTest.java

@@ -0,0 +1,93 @@
+package com.goafanti.common.controller;
+
+import java.awt.print.Book;
+import java.awt.print.PageFormat;
+import java.awt.print.Paper;
+import java.awt.print.PrinterException;
+import java.awt.print.PrinterJob;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.print.PrintService;
+import javax.print.PrintServiceLookup;
+import javax.print.attribute.HashAttributeSet;
+import javax.print.attribute.standard.PrinterName;
+
+import com.goafanti.common.bo.Prient;
+import com.goafanti.common.bo.Test;
+
+/**
+ * 打印测试类
+ * 
+ * @author admin
+ * 
+ */
+public class MainTest {
+
+	public static void main(String[] args) {
+		//这里是测试用的数据,自己定义就好了
+		List<Test> testList = new ArrayList<Test>();
+		Test t1 = new Test("麻辣牛肉", 23.00, 2);
+		Test t2 = new Test("麻辣牛肉", 23.00, 4);
+		Test t3 = new Test("精品千层肚", 24.00, 3);
+		Test t4 = new Test("麻辣牛肉", 23.00, 2);
+		Test t5 = new Test("极品鲜毛肚", 26.00, 1);
+		Test t6 = new Test("极品鲜毛肚", 26.00, 1);
+		Test t7 = new Test("极品鲜毛肚", 26.00, 1);
+		Test t8 = new Test("极品鲜毛肚", 26.00, 1);
+		Test t9 = new Test("极品鲜毛肚", 26.00, 1);
+		testList.add(t1);
+		testList.add(t2);
+		testList.add(t3);
+		testList.add(t4);
+		testList.add(t5);
+		testList.add(t6);
+		testList.add(t7);
+		testList.add(t8);
+		testList.add(t9);
+		
+		// 设置小票模型菜品集合
+		Prient.setTestList(testList);
+		// 定义纸张高度
+//		int height = 842;
+		// 通俗理解就是书、文档
+		Book book = new Book();
+		// 打印格式
+		PageFormat pf = new PageFormat();
+		// 原点在纸张的左上方,x 指向右方,y 指向下方。
+		pf.setOrientation(PageFormat.PORTRAIT);
+		// 通过Paper设置页面的空白边距和可打印区域。必须与实际打印纸张大小相符。
+		Paper p = new Paper();
+		// 页面宽度 页面高度
+		p.setSize(592, 842);
+		// x轴 y轴 宽度 高度
+		p.setImageableArea(0, 0, 260, 842);
+		pf.setPaper(p);
+		// 把 PageFormat 和 Printable 添加到书中,组成一个页面
+		book.append(new Prient(), pf);
+		// 指定打印机打印(printerName打印机名称)
+//		HashAttributeSet hs = new HashAttributeSet();
+//		String printerName = "OneNote";
+//		hs.add(new PrinterName(printerName, null));
+//		PrintService[] pss = PrintServiceLookup.lookupPrintServices(null, hs);
+		PrintService ps = PrintServiceLookup.lookupDefaultPrintService();
+		if (ps==null) {
+			System.out.println("无法找到打印机!");
+			return;
+		}
+		// 获取打印服务对象
+		PrinterJob job = PrinterJob.getPrinterJob();
+		// 写入书
+		job.setPageable(book);
+		try {
+			Integer random6 = (int) ((Math.random() * 9 + 1) * 100000);
+			System.out.println("Z"+System.currentTimeMillis()+random6.toString());
+			// 添加指定的打印机
+			job.setPrintService(ps);
+			// 打印执行
+			job.print();
+		} catch (PrinterException e) {
+			System.out.println("================打印出现异常");
+		}
+	}
+}

+ 1 - 0
src/main/java/com/goafanti/order/service/impl/OrderChangeServiceImpl.java

@@ -171,6 +171,7 @@ public class OrderChangeServiceImpl extends BaseMybatisDao<NewOrderChangeMapper>
 			orderNew.setAdditionalOrder(additionalOrderNo);
 			additionalOrder.setOrderNo(additionalOrderNo);
 			additionalOrder.setCreater(TokenManager.getAdminId());
+			additionalOrder.setContractNo(t1.getContractNo());
 			additionalOrder.setSalesmanId(t1.getSalesmanId());
 			additionalOrder.setOrderType(t1.getOrderType());
 			additionalOrder.setBuyerId(t1.getBuyerId());	

+ 1 - 1
src/main/resources/props/config_local.properties

@@ -60,7 +60,7 @@ template.cacheable=false
 portal.host=//sf.jishutao.com/portal/2.0.6
 avatar.upload.host=//sb.jishutao.com/upload
 #连接开发
-static.host=//sb.jishutao.com/1.1.16
+static.host=//sb.jishutao.com/1.1.17
 avatar.host=//sb.jishutao.com
 
 #连测试