package com.thhy.materials.modules.biz.rebarprint.service.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.github.pagehelper.util.StringUtil; import com.sun.jna.Native; import com.sun.jna.win32.StdCallLibrary; import com.thhy.general.common.BasicResult; import com.thhy.general.config.SysUserInfo; import com.thhy.general.utils.UserInfoUtils; import com.thhy.materials.modules.biz.rebarprint.entity.TSteelPrint; import com.thhy.materials.modules.biz.rebarprint.entity.TSteelProduce; import com.thhy.materials.modules.biz.rebarprint.mapper.TSteelPrintMapper; import com.thhy.materials.modules.biz.rebarprint.service.TSteelPrintService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.print.*; import javax.print.attribute.PrintServiceAttribute; import javax.print.attribute.standard.PrinterName; import javax.xml.crypto.Data; import java.awt.print.PrinterJob; import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; import java.util.*; import java.util.logging.SimpleFormatter; @Service public class TSteelPrintServiceImpl implements TSteelPrintService { @Resource private TSteelPrintMapper steelPrintMapper; @Override public BasicResult steelPrintInsert(Map values) { SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); String userId = sysUserInfo.getUserId(); values.put("createUser",userId); values.put("steelPrintId",""); steelPrintMapper.steelPrintInsert(values); return BasicResult.success("添加成功"); } @Override public BasicResult steelPrintList(Map values) { SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); values.put("companyId",sysUserInfo.getCompanyId()); Integer pageSize = Integer.valueOf(values.get("pageSize").toString()); Integer pageNum = Integer.valueOf(values.get("pageNum").toString()); PageHelper.startPage(pageNum,pageSize); List tSteelPrints = steelPrintMapper.steelPrintList(values); PageInfo tSteelPrintPageInfo = new PageInfo<>(tSteelPrints); return BasicResult.success(tSteelPrintPageInfo); } @Override public BasicResult steelPrintDel(String steelPrintId) { List produces = steelPrintMapper.steelProduce(steelPrintId); if(produces!=null && produces.size()>0){ return BasicResult.faild("11111","已存在打印数据","error"); } steelPrintMapper.steelPrintDel(steelPrintId); return BasicResult.success("删除成功"); } @Override @Transactional public BasicResult print(String steelPrintId) { //打印 //钢筋信息 TSteelPrint steelPrint = steelPrintMapper.steelPrintInfo(steelPrintId); String groupName= steelPrintMapper.steelPrintGroup(steelPrint.getCreateUser()); steelPrint.setGroupName(groupName); String proNumBer = steelPrintMapper.proIdSelectByNumber(steelPrint.getProId()); //需要打印的份数 Integer printNum = steelPrint.getPrintNum(); Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); String format1 = format.format(date); //查询已打印项目下钢筋编号 List produces= steelPrintMapper.produceList(steelPrint.getProId()); TSteelProduce produce1 = new TSteelProduce(); produce1.setProduceNumber("000000000000000000"); List> arrayList = new ArrayList<>(); if(produces.size()>0){ for (TSteelProduce produce :produces){ String produceNumber = produce.getProduceNumber(); String substring = produceNumber.substring(4, 12); if(substring.equals(format1)){ String number = produceNumber.substring(12, 17); if(Integer.valueOf(produce1.getProduceNumber().substring(12, 17)) values = new HashMap<>(); values.put("steelProduceId",""); values.put("proId",steelPrint.getProId()); values.put("reinforcementId",steelPrint.getReinforcementId()); values.put("blockNum",steelPrint.getBlockNum()); values.put("createUser",steelPrint.getCreateUser()); values.put("sizeId",steelPrint.getSizeId()); values.put("steelPrintId",steelPrintId); if(integer<9){ int i = (integer + 1); values.put("produceNumber","S"+proNumBer+format1+"0000"+i); }else if (integer<99){ int i = (integer + 1); values.put("produceNumber","S"+proNumBer+format1+"000"+i); }else if (integer<999){ int i = (integer + 1); values.put("produceNumber","S"+proNumBer+format1+"00"+i); }else if (integer<9999){ int i = (integer + 1); values.put("produceNumber","S"+proNumBer+format1+"0"+i); }else if (integer<99999){ int i = (integer + 1); values.put("produceNumber","S"+proNumBer+format1+i); } steelPrintMapper.produceInsert(values); HashMap hashMap = new HashMap<>(); hashMap.put("produceNumber",values.get("produceNumber").toString()); arrayList.add(hashMap); // try { // test(values.get("produceNumber").toString(),steelPrint); // } catch (UnsupportedEncodingException e) { // e.printStackTrace(); // } integer++; } }else { // s + 000 项目 + 日期8位 + 后 5位 for (int i=1 ; i<=printNum;i++){ HashMap values = new HashMap<>(); if(i<10){ values.put("produceNumber","S"+proNumBer+format1+"0000"+i); }else if(i<100){ values.put("produceNumber","S"+proNumBer+format1+"000"+i); }else if(i<1000){ values.put("produceNumber","S"+proNumBer+format1+"00"+i); }else if(i<10000){ values.put("produceNumber","S"+proNumBer+format1+"0"+i); }else if(i<10000){ values.put("produceNumber","S"+proNumBer+format1+i); } values.put("steelProduceId",""); values.put("proId",steelPrint.getProId()); values.put("reinforcementId",steelPrint.getReinforcementId()); values.put("blockNum",steelPrint.getBlockNum()); values.put("createUser",steelPrint.getCreateUser()); values.put("sizeId",steelPrint.getSizeId()); values.put("steelPrintId",steelPrintId); steelPrintMapper.produceInsert(values); HashMap hashMap = new HashMap<>(); hashMap.put("produceNumber",values.get("produceNumber").toString()); arrayList.add(hashMap); // try { // test(values.get("produceNumber").toString(),steelPrint); // } catch (UnsupportedEncodingException e) { // e.printStackTrace(); // } } } // for (int i=0 ; i= 0) { System.out.println("我进来来"); psZebra = services[i]; System.out.println(psZebra); break; } } if (psZebra == null) { System.out.println("Zebra printer not found."); return; } DocPrintJob job = psZebra.createPrintJob(); // String s = "${^XA^FO100,100^BY7^BCN,100,Y,N,N^FD123456^FS^XZ}$"; //^FO{1},{2}^A" + Font + "{3},{4},{5}^FD{0}^FS // String erwei = "${^FO50,260^BY1,2^BCN,100,Y,N^FDSMJH2000544610^FS}$"; // String command = "QRCODE 300,70,L,6,A,0,M2,S3,\"https://www.baidu.com/\"";// 打印二维码 String erwei = "${^XA^FO20,20^BQ,2,10^FDLA,0123456789ABCD 2D code^FS^XZ}$"; // byte[] by = s.getBytes(); // DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; // Doc doc = new SimpleDoc(by, flavor, null); // job.print(doc, null); byte[] bytes = erwei.getBytes(); DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; Doc doc1 = new SimpleDoc(bytes, flavor, null); job.print(doc1, null); } catch (PrintException e) { e.printStackTrace(); } } public interface TscLibDll extends StdCallLibrary { TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary("TSCLIB", TscLibDll.class); int about(); int openport(String pirnterName); int closeport(); int sendcommand(String printerCommand); int setup(String width, String height, String speed, String density, String sensor, String vertical, String offset); int downloadpcx(String filename, String image_name); int barcode(String x, String y, String type, String height, String readable, String rotation, String narrow, String wide, String code); int printerfont(String x, String y, String fonttype, String rotation, String xmul, String ymul, String text); int clearbuffer(); int printlabel(String set, String copy); int formfeed(); int nobackfeed(); int windowsfont(int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, String content); } public static void test(String produceNumber,TSteelPrint steelPrint) throws UnsupportedEncodingException { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String format1 = format.format(date); System.setProperty("jna.encoding", "GBK");// 支持中文 // TscLibDll.INSTANCE.about(); // TscLibDll.INSTANCE.openport("TSC TTP-244 Pro"); TscLibDll.INSTANCE.openport("TSC TTP-244 Pro"); // TscLibDll.INSTANCE.downloadpcx("C:\\UL.PCX", "UL.PCX");// 打印图片时需要先下载到设备 // TscLibDll.INSTANCE.sendcommand("REM ***** This is a test by JAVA. *****"); TscLibDll.INSTANCE.setup("80", "60", "3", "15", "0", "2", "0"); TscLibDll.INSTANCE.sendcommand("SET TEAR ON"); TscLibDll.INSTANCE.clearbuffer(); // String command = "QRCODE 300,70,L,6,A,0,M2,S3,\""+produceNumber+"\"";// 打印二维码 String command = "QRCODE 1,2,L,10,A,0,M2,S3,\""+produceNumber+"\"";// 打印二维码 TscLibDll.INSTANCE.sendcommand(command); // TscLibDll.INSTANCE.sendcommand("PUTPCX 550,10,\"UL.PCX\"");// 图片位置 // TscLibDll.INSTANCE.printerfont("100", "50", "TSS24.BF2", "0", "1", "1", "Technology"); // TscLibDll.INSTANCE.barcode("70", "140", "128", "90", "0", "0", "2", "2", "A123456789");// 打印内容,参数是位置和字体 // TscLibDll.INSTANCE.windowsfont(15, 15, 32, 0, 2, 0, "Arial", "尺寸:"+steelPrint.getSizeName()); // TscLibDll.INSTANCE.windowsfont(30, 90, 32, 0, 2, 0, "Arial", "配筋:"+steelPrint.getReinforcementName()); TscLibDll.INSTANCE.windowsfont(230, 1, 40, 0, 2, 0, "Arial", "钢筋笼信息牌"); TscLibDll.INSTANCE.windowsfont(230, 45, 32, 0, 2, 0, "Arial", "项目名称:"+steelPrint.getProName()); TscLibDll.INSTANCE.windowsfont(230, 90, 32, 0, 2, 0, "Arial", "尺寸:"+steelPrint.getSizeName()); TscLibDll.INSTANCE.windowsfont(230, 120, 32, 0, 2, 0, "Arial", "配筋:"+steelPrint.getReinforcementName()); TscLibDll.INSTANCE.windowsfont(230, 150, 32, 0, 2, 0, "Arial", "块号:"+steelPrint.getBlockName()); TscLibDll.INSTANCE.windowsfont(230, 180, 32, 0, 2, 0, "Arial", "制作人:"+steelPrint.getRealName()); TscLibDll.INSTANCE.windowsfont(230, 210, 32, 0, 2, 0, "Arial", "班组:"+steelPrint.getGroupName()); TscLibDll.INSTANCE.windowsfont(230, 240, 32, 0, 2, 0, "Arial", "打印时间:"+format1); TscLibDll.INSTANCE.printlabel("1", "1"); TscLibDll.INSTANCE.closeport(); } public static void main(String[] args) { String s = "s0012023050500001"; String substring = s.substring(12, 17); System.out.println(substring); String i = "000000000000000000"; Integer integer = Integer.valueOf(i); String substring1 = i.substring(12, 17); Integer integer1 = Integer.valueOf(substring1); System.out.println(substring1+"---"+integer1); } }