| | |
| | | package com.zbooksoft.gdmis.common; |
| | | |
| | | import com.ruili.wcp.common.CustomConfigUtil; |
| | | import com.ruili.wcp.common.SpringContextUtil; |
| | | import com.zbooksoft.gdmis.config.ArchivesCustomConfig; |
| | | import com.zbooksoft.gdmis.data.entity.CatYswjxx; |
| | | import com.zbooksoft.gdmis.service.CatYswjxxService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import tsc_sdk.TcpComm; |
| | |
| | | |
| | | |
| | | public class UsbSyncExampleWindowsItem { |
| | | CatYswjxxService catYswjxxService = (CatYswjxxService) SpringContextUtil.getBean("catYswjxxServiceImpl"); |
| | | CustomConfigUtil customConfigUtil = (CustomConfigUtil) SpringContextUtil.getBean("customConfigUtil"); |
| | | |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger(UsbSyncExampleWindowsItem.class); |
| | | |
| | | public static void printItemLabel(List<CatYswjxx> itemDataList) { |
| | | TcpComm asyncComm = new TcpComm("172.0.0.1", 8080); |
| | | public void printItemLabel(List<Long> idList) { |
| | | ArchivesCustomConfig archivesCustomConfig = customConfigUtil.getConfigObj(ArchivesCustomConfig.class); |
| | | String fileIp = archivesCustomConfig.getFileIp(); |
| | | |
| | | TcpComm asyncComm = new TcpComm(fileIp, 9100); |
| | | try { |
| | | asyncComm.open(); |
| | | for (CatYswjxx catYswjxx : itemDataList) { |
| | | for (Long id : idList) { |
| | | CatYswjxx catYswjxx = catYswjxxService.getById(id); |
| | | String all = catYswjxx.getWjtm(); |
| | | String itemCode = catYswjxx.getDh(); |
| | | String isSecurity = catYswjxx.getSfsm(); |
| | |
| | | String newBarCode = itemCode.replace("底", "D").replace("测", "C").replace("观", "G").replace("探", "T").replace("样", "Y").replace("试", "S").replace("录", "L").replace("像", "X").replace("综", "Z").replace("文", "W").replace("实", "S").replace("物", "W").replace("钻", "Z").replace("设", "S").replace("相", "X").replace("油", "Y").replace("电", "D").replace("地", "D"); |
| | | String boxMum = catYswjxx.getHh(); |
| | | String newBoxMum = ""; |
| | | if (boxMum.contains("盒")) { |
| | | //获取盒字后面的内容 |
| | | newBoxMum = boxMum.substring(1); |
| | | } else { |
| | | newBoxMum = formatConverter(boxMum); |
| | | } |
| | | newBoxMum = boxMum; |
| | | newBarCode = newBarCode + "-" + newBoxMum; |
| | | // 使用示例 |
| | | List<String> wrappedLines = wrapText(all, 28, 3); // 每行最大宽度20 |
| | |
| | | yPosition += 35; |
| | | } |
| | | |
| | | commandBuilder.append("BARCODE 5,150,\"128\",140,0,0,2,2,\"").append(newBarCode).append("\"\r\n"); |
| | | commandBuilder.append("TEXT 20,320,\"A123.TTF\",0,16,16,\"").append(itemCode).append("\"\r\n"); |
| | | int wordWidth = getTextLong(boxMum); |
| | | int barcodeTextLength = newBarCode.length(); |
| | | long barcodeWidth = barcodeTextLength * 20L; |
| | | long barcodeX = (400 - barcodeWidth) / 2; |
| | | commandBuilder.append("BARCODE ").append(barcodeX).append(",145,\"128\",140,0,0,2,2,\"").append(newBarCode).append("\"\r\n"); |
| | | int textLong = getTextLong(itemCode); |
| | | long itemCodeWidth = textLong * 30L; |
| | | long itemCodeX = (400 - itemCodeWidth) / 2; |
| | | commandBuilder.append("TEXT ").append(itemCodeX).append(",315,\"A123.TTF\",0,16,16,\"").append(itemCode).append("\"\r\n"); |
| | | int wordWidth = getTextLong("盒" + boxMum); |
| | | long boxMumWidth = wordWidth * 30L; |
| | | long boxMumX = (400 - boxMumWidth) / 2; |
| | | if ("是".equals(isSecurity)) { |
| | | commandBuilder.append("TEXT ").append(boxMumX).append(",395,\"A123.TTF\",0,16,16,\"").append(boxMum).append("★\"\r\n"); |
| | | commandBuilder.append("TEXT ").append(boxMumX).append(",390,\"A123.TTF\",0,16,16,\"").append("盒").append(boxMum).append("★\"\r\n"); |
| | | } else { |
| | | boxMumX = boxMumX + 10; |
| | | commandBuilder.append("TEXT ").append(boxMumX).append(",395,\"A123.TTF\",0,16,16,\"").append(boxMum).append("\"\r\n"); |
| | | commandBuilder.append("TEXT ").append(boxMumX).append(",390,\"A123.TTF\",0,16,16,\"").append("盒").append(boxMum).append("\"\r\n"); |
| | | } |
| | | commandBuilder.append("PRINT 1\r\n"); |
| | | byte[] dataToSend = commandBuilder.toString().getBytes(); |
| | | System.out.println(commandBuilder.toString()); |
| | | byte[] dataToSend = commandBuilder.toString().getBytes("UTF-8"); |
| | | |
| | | asyncComm.writeSync(dataToSend); |
| | | } |
| | | Thread.sleep(25000); |