无关风月
2025-02-28 2f8e70ad2884d2b6b7443dfae0af11ae9cfc8b99
common/src/main/java/com/jilongda/common/Ticket/TicketUtil.java
@@ -15,6 +15,7 @@
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
@@ -109,10 +110,54 @@
         tAddOptometryVO.setOptometryDetailVOS(temp);
         tAddOptometryVO.setShopName("天府新谷门店");
         tAddOptometryVO.setOptometristName("无关风月");
         tAddOptometryVO.setTime("2025-11-11");
         tAddOptometryVO.setTime("2025-11-11 11:11:11");
         tAddOptometryVO.setPhone("19983174515");
         tAddOptometryVO.setSn("922440578");
         String method = print(tAddOptometryVO);
         List<TOrderGoodsPrintVO> tOrderGoodsPrintVOS = new ArrayList<>();
         TOrderGoodsPrintVO tOrderGoodsPrintVO1 = new TOrderGoodsPrintVO();
         tOrderGoodsPrintVO1.setColor("颜色");
         tOrderGoodsPrintVO1.setRLens("右边");
         tOrderGoodsPrintVO1.setType(0);
         tOrderGoodsPrintVO1.setRefractiveIndex("1.66");
         tOrderGoodsPrintVO1.setBrandName("平拍");
         tOrderGoodsPrintVO1.setSeriesName("系列");
         tOrderGoodsPrintVO1.setModelId(0);
         tOrderGoodsPrintVO1.setStatus(0);
         tOrderGoodsPrintVO1.setGoodsMoney(new BigDecimal("1"));
         tOrderGoodsPrintVO1.setCost(new BigDecimal("2"));
         tOrderGoodsPrintVO1.setConstConfirm(new BigDecimal("3"));
         tOrderGoodsPrintVO1.setRightLens("又");
         TOrderGoodsPrintVO tOrderGoodsPrintVO2 = new TOrderGoodsPrintVO();
         tOrderGoodsPrintVO2.setColor("颜色");
         tOrderGoodsPrintVO2.setLLens("左边");
         tOrderGoodsPrintVO2.setType(0);
         tOrderGoodsPrintVO2.setRefractiveIndex("1.66");
         tOrderGoodsPrintVO2.setBrandName("平拍");
         tOrderGoodsPrintVO2.setSeriesName("系列");
         tOrderGoodsPrintVO2.setModelId(0);
         tOrderGoodsPrintVO2.setStatus(0);
         tOrderGoodsPrintVO2.setGoodsMoney(new BigDecimal("1"));
         tOrderGoodsPrintVO2.setCost(new BigDecimal("2"));
         tOrderGoodsPrintVO2.setConstConfirm(new BigDecimal("3"));
         tOrderGoodsPrintVO2.setLeftLens("左边");
         TOrderGoodsPrintVO tOrderGoodsPrintVO3 = new TOrderGoodsPrintVO();
         tOrderGoodsPrintVO3.setColor("颜色");
         tOrderGoodsPrintVO3.setType(0);
         tOrderGoodsPrintVO3.setBrandName("平拍");
         tOrderGoodsPrintVO3.setModelName("型号");
         tOrderGoodsPrintVO3.setModelId(0);
         tOrderGoodsPrintVO3.setStatus(0);
         tOrderGoodsPrintVO3.setGoodsMoney(new BigDecimal("1"));
         tOrderGoodsPrintVO3.setCost(new BigDecimal("2"));
         tOrderGoodsPrintVO3.setConstConfirm(new BigDecimal("3"));
         tOrderGoodsPrintVO3.setMaterial("材质");
         tOrderGoodsPrintVOS.add(tOrderGoodsPrintVO1);
         tOrderGoodsPrintVOS.add(tOrderGoodsPrintVO2);
         tOrderGoodsPrintVOS.add(tOrderGoodsPrintVO3);
         tAddOptometryVO.setOrderGoods(tOrderGoodsPrintVOS);
//         String method = print(tAddOptometryVO);
         String method = printMatch(tAddOptometryVO);
         System.out.println(method);
         
@@ -340,31 +385,33 @@
               Comparator.comparingInt(TOptometryDetailVO::getType)
                     .thenComparingInt(TOptometryDetailVO::getStatus).reversed()
         );
         for (TOptometryDetailVO s : optometryDetailVOS) {
            switch (s.getType()){
               case 3:
                  if (s.getStatus()==2){
                     content.append("<BOLD>旧镜信息<BR>");
                     content.append("R:<BR>");
                     content.append("度数:"+s.getBallMirror()+" 散光:"+s.getColumnMirror()+" 轴位:"+s.getAxis()+"<BR>");
                     content.append("瞳距:"+s.getPupilDistance()+"<BR>");
                     content.append("度数:"+(s.getBallMirror()==null?"-":s.getBallMirror())+" 散光:"+(s.getColumnMirror()==null?"-":s.getColumnMirror())+" 轴位:"+(s.getAxis()==null?"-":s.getAxis())+"<BR>");
                     content.append("瞳距:"+(s.getPupilDistance()==null?"-":s.getPupilDistance())+"<BR>");
                  }else if (s.getStatus()==1){
                     content.append("L:<BR>");
                     content.append("度数:"+s.getBallMirror()+" 散光:"+s.getColumnMirror()+" 轴位:"+s.getAxis()+"<BR>");
                     content.append("瞳距:"+s.getPupilDistance()+"<BR>");
                     content.append("度数:"+(s.getBallMirror()==null?"-":s.getBallMirror())+" 散光:"+(s.getColumnMirror()==null?"-":s.getColumnMirror())+" 轴位:"+(s.getAxis()==null?"-":s.getAxis())+"<BR>");
                     content.append("瞳距:"+(s.getPupilDistance()==null?"-":s.getPupilDistance())+"<BR>");
                     content.append("--------------------------------<BR>");
                  }
                  break;
               case 2:
                  if (s.getStatus()==2){
                     content.append("完全矫正<BR>");
                     content.append("R:<BR>");
                     content.append("度数:"+s.getBallMirror()+" 散光:"+s.getColumnMirror()+" 轴位:"+s.getAxis()+"<BR>");
                     content.append("瞳距:"+s.getPupilDistance()+" 矫正:"+s.getCorrect()+"<BR>");
                     content.append("度数:"+(s.getBallMirror()==null?"-":s.getBallMirror())+" 散光:"+(s.getColumnMirror()==null?"-":s.getColumnMirror())+" 轴位:"+(s.getAxis()==null?"-":s.getAxis())+"<BR>");
                     content.append("瞳距:"+(s.getPupilDistance()==null?"-":s.getPupilDistance())+" 矫正:"+(s.getCorrect()==null?"-":s.getCorrect())+"<BR>");
                  }else if (s.getStatus()==1){
                     content.append("L:<BR>");
                     content.append("度数:"+s.getBallMirror()+" 散光:"+s.getColumnMirror()+" 轴位:"+s.getAxis()+"<BR>");
                     content.append("瞳距:"+s.getPupilDistance()+" 矫正:"+s.getCorrect()+"<BR>");
                     content.append("度数:"+(s.getBallMirror()==null?"-":s.getBallMirror())+" 散光:"+(s.getColumnMirror()==null?"-":s.getColumnMirror())+" 轴位:"+(s.getAxis()==null?"-":s.getAxis())+"<BR>");
                     content.append("瞳距:"+(s.getPupilDistance()==null?"-":s.getPupilDistance())+" 矫正:"+(s.getCorrect()==null?"-":s.getCorrect())+"<BR>");
                     content.append("--------------------------------<BR>");
                  }
                  break;
@@ -372,14 +419,14 @@
                  if (s.getStatus()==2){
                     content.append("配镜处方<BR>");
                     content.append("R:<BR>");
                     content.append("度数:"+s.getBallMirror()+" 散光:"+s.getColumnMirror()+" 轴位:"+s.getAxis()+"<BR>");
                     content.append("ADD:"+s.getAddS()+" 瞳距:"+s.getPupilDistance()+" 瞳高:"+s.getPupilHeight()+"<BR>");
                     content.append("矫正:"+s.getCorrect()+"<BR>");
                     content.append("度数:"+(s.getBallMirror()==null?"-":s.getBallMirror())+" 散光:"+(s.getColumnMirror()==null?"-":s.getColumnMirror())+" 轴位:"+(s.getAxis()==null?"-":s.getAxis())+"<BR>");
                     content.append("ADD:"+(s.getAddS()==null?"-":s.getAddS())+" 瞳距:"+(s.getPupilDistance()==null?"-":s.getPupilDistance())+" 瞳高:"+(s.getPupilHeight()==null?"-":s.getPupilHeight())+"<BR>");
                     content.append("矫正:"+(s.getCorrect()==null?"-":s.getCorrect())+"<BR>");
                  }else if (s.getStatus()==1){
                     content.append("L:<BR>");
                     content.append("度数:"+s.getBallMirror()+" 散光:"+s.getColumnMirror()+" 轴位:"+s.getAxis()+"<BR>");
                     content.append("ADD:"+s.getAddS()+" 瞳距:"+s.getPupilDistance()+" 瞳高:"+s.getPupilHeight()+"<BR>");
                     content.append("矫正:"+s.getCorrect()+"<BR>");
                     content.append("度数:"+(s.getBallMirror()==null?"-":s.getBallMirror())+" 散光:"+(s.getColumnMirror()==null?"-":s.getColumnMirror())+" 轴位:"+(s.getAxis()==null?"-":s.getAxis())+"<BR>");
                     content.append("ADD:"+(s.getAddS()==null?"-":s.getAddS())+" 瞳距:"+(s.getPupilDistance()==null?"-":s.getPupilDistance())+" 瞳高:"+(s.getPupilHeight()==null?"-":s.getPupilHeight())+"<BR>");
                     content.append("矫正:"+(s.getCorrect()==null?"-":s.getCorrect())+"<BR>");
                     content.append("--------------------------------<BR>");
                  }
                  break;
@@ -387,15 +434,15 @@
         }
         content.append("</BOLD>");
         //通过POST请求,发送打印信息到服务器
         RequestConfig requestConfig = RequestConfig.custom()
                  .setSocketTimeout(30000)//读取超时
         RequestConfig requestConfig = RequestConfig.custom()
                  .setSocketTimeout(30000)//读取超时
                  .setConnectTimeout(30000)//连接超时
                  .build();
         CloseableHttpClient httpClient = HttpClients.custom()
                .setDefaultRequestConfig(requestConfig)
                .build();
                .build();
          HttpPost post = new HttpPost(URL);
           List<NameValuePair> nvps = new ArrayList<NameValuePair>();
         nvps.add(new BasicNameValuePair("user",USER));
@@ -406,7 +453,7 @@
         nvps.add(new BasicNameValuePair("sn",dto.getSn()));
         nvps.add(new BasicNameValuePair("content", content.toString()));
         nvps.add(new BasicNameValuePair("times","1"));//打印联数
         CloseableHttpResponse response = null;
         String result = null;
           try
@@ -415,7 +462,7 @@
             response = httpClient.execute(post);
                int statecode = response.getStatusLine().getStatusCode();
                if(statecode == 200){
                 HttpEntity httpentity = response.getEntity();
                 HttpEntity httpentity = response.getEntity();
                  if (httpentity != null){
                     //服务器返回的JSON字符串,建议要当做日志记录起来
                     result = EntityUtils.toString(httpentity);
@@ -446,7 +493,155 @@
             }
          }
         return unescapeUnicode(result);
      }
      public static String printMatch(TAddOptometryVO dto){
         //标签说明:
         //单标签:
         //"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
         //"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
         //成对标签:
         //"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
         //<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,"<RIGHT></RIGHT>"为右对齐
         //拼凑订单内容时可参考如下格式
         //根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
         StringBuilder content;
         content=new StringBuilder("<BOLD>");
         content.append("隼目加工单<BR>");
         content.append(dto.getShopName()).append("<BR>");
         content.append("订单时间:").append(dto.getTime()).append("<BR>");
         content.append("--------------------------------<BR>");
         content.append("加工编号:").append("<BR>");
         content.append("<CB>");
         content.append(dto.getMachiningCode()).append("</CB>").append("<BR>");
         content.append("--------------------------------<BR>");
         List<TOptometryDetailVO> optometryDetailVOS = dto.getOptometryDetailVOS();
         // 使用 List.sort 和 Comparator 进行多字段倒序排序
         optometryDetailVOS.sort(
               Comparator.comparingInt(TOptometryDetailVO::getType)
                     .thenComparingInt(TOptometryDetailVO::getStatus).reversed()
         );
         for (TOptometryDetailVO s : optometryDetailVOS) {
            switch (s.getType()){
               case 1:
                  if (s.getStatus()==2){
                     content.append("配镜处方<BR>");
                     content.append("R:<BR>");
                     content.append("度数:"+(s.getBallMirror()==null?"-":s.getBallMirror())+" 散光:"+(s.getColumnMirror()==null?"-":s.getColumnMirror())+" 轴位:"+(s.getAxis()==null?"-":s.getAxis())+"<BR>");
                     content.append("ADD:"+(s.getAddS()==null?"-":s.getAddS())+" 瞳距:"+(s.getPupilDistance()==null?"-":s.getPupilDistance())+" 瞳高:"+(s.getPupilHeight()==null?"-":s.getPupilHeight())+"<BR>");
                     content.append("矫正:"+(s.getCorrect()==null?"-":s.getCorrect())+"<BR>");
                  }else if (s.getStatus()==1){
                     content.append("L:<BR>");
                     content.append("度数:"+(s.getBallMirror()==null?"-":s.getBallMirror())+" 散光:"+(s.getColumnMirror()==null?"-":s.getColumnMirror())+" 轴位:"+(s.getAxis()==null?"-":s.getAxis())+"<BR>");
                     content.append("ADD:"+(s.getAddS()==null?"-":s.getAddS())+" 瞳距:"+(s.getPupilDistance()==null?"-":s.getPupilDistance())+" 瞳高:"+(s.getPupilHeight()==null?"-":s.getPupilHeight())+"<BR>");
                     content.append("矫正:"+(s.getCorrect()==null?"-":s.getCorrect())+"<BR>");
                     content.append("--------------------------------<BR>");
                  }
                  break;
            }
         }
         content.append("订单详情:").append("<BR>");
         List<TOrderGoodsPrintVO> orderGoods = dto.getOrderGoods();
         List<TOrderGoodsPrintVO> tOrderGoodsPrintVOS = new ArrayList<>();
         for (TOrderGoodsPrintVO orderGood : orderGoods) {
            if (orderGood.getModelId()!=null){
               tOrderGoodsPrintVOS.add(orderGood);
               break;
            }
         }
         for (TOrderGoodsPrintVO orderGood : orderGoods) {
            if (orderGood.getRLens()!=null){
               tOrderGoodsPrintVOS.add(orderGood);
               break;
            }
         }
         for (TOrderGoodsPrintVO orderGood : orderGoods) {
            if (orderGood.getLLens()!=null){
               tOrderGoodsPrintVOS.add(orderGood);
               break;
            }
         }
         for (TOrderGoodsPrintVO tOrderGoodsPrintVO : tOrderGoodsPrintVOS) {
            if (tOrderGoodsPrintVO.getModelId()!=null){
               content.append("镜架:").append(tOrderGoodsPrintVO.getBrandName()==null?"     "+"-":tOrderGoodsPrintVO.getBrandName()+"-").append(tOrderGoodsPrintVO.getMaterial()==null?"    "+"-":tOrderGoodsPrintVO.getMaterial()+"-").append(tOrderGoodsPrintVO.getModelName()==null?"     "+"-":tOrderGoodsPrintVO.getModelName()).append("<BR>");
               continue;
            }
            if (tOrderGoodsPrintVO.getRLens()!=null){
               content.append("右眼镜片:").append(tOrderGoodsPrintVO.getBrandName()==null?"     "+"-":tOrderGoodsPrintVO.getBrandName()+"-").append(tOrderGoodsPrintVO.getSeriesName()==null?"     "+"-":tOrderGoodsPrintVO.getSeriesName()+"-").append(tOrderGoodsPrintVO.getRefractiveIndex()==null?"     "+"-":tOrderGoodsPrintVO.getRefractiveIndex()).append("<BR>");
               continue;
            }
            if (tOrderGoodsPrintVO.getLLens()!=null){
               content.append("左眼镜片:").append(tOrderGoodsPrintVO.getBrandName()==null?"     "+"-":tOrderGoodsPrintVO.getBrandName()+"-").append(tOrderGoodsPrintVO.getSeriesName()==null?"     "+"-":tOrderGoodsPrintVO.getSeriesName()+"-").append(tOrderGoodsPrintVO.getRefractiveIndex()==null?"     "+"-":tOrderGoodsPrintVO.getRefractiveIndex()).append("<BR>");
               continue;
            }
         }
         content.append("客户电话:").append(dto.getPhone()==null?"-":dto.getPhone()).append("<BR>");
         content.append("备注:").append(dto.getRemark()==null?"-":dto.getRemark()).append("<BR>");
         content.append("</BOLD>");
         //通过POST请求,发送打印信息到服务器
         RequestConfig requestConfig = RequestConfig.custom()
                  .setSocketTimeout(30000)//读取超时
                  .setConnectTimeout(30000)//连接超时
                  .build();
         CloseableHttpClient httpClient = HttpClients.custom()
                .setDefaultRequestConfig(requestConfig)
                .build();
          HttpPost post = new HttpPost(URL);
           List<NameValuePair> nvps = new ArrayList<NameValuePair>();
         nvps.add(new BasicNameValuePair("user",USER));
         String STIME = String.valueOf(System.currentTimeMillis()/1000);
         nvps.add(new BasicNameValuePair("stime",STIME));
         nvps.add(new BasicNameValuePair("sig",signature(USER,UKEY,STIME)));
         nvps.add(new BasicNameValuePair("apiname","Open_printMsg"));//固定值,不需要修改
         nvps.add(new BasicNameValuePair("sn",dto.getSn()));
         nvps.add(new BasicNameValuePair("content", content.toString()));
         nvps.add(new BasicNameValuePair("times","1"));//打印联数
         CloseableHttpResponse response = null;
         String result = null;
           try
           {
             post.setEntity(new UrlEncodedFormEntity(nvps,"utf-8"));
             response = httpClient.execute(post);
                int statecode = response.getStatusLine().getStatusCode();
                if(statecode == 200){
                 HttpEntity httpentity = response.getEntity();
                  if (httpentity != null){
                     //服务器返回的JSON字符串,建议要当做日志记录起来
                     result = EntityUtils.toString(httpentity);
                  }
              }
          }
          catch (Exception e)
          {
             e.printStackTrace();
          }
          finally{
             try {
                if(response!=null){
                   response.close();
                }
             } catch (IOException e) {
                e.printStackTrace();
             }
             try {
                post.abort();
             } catch (Exception e) {
                e.printStackTrace();
             }
             try {
                httpClient.close();
             } catch (IOException e) {
                e.printStackTrace();
             }
          }
         return unescapeUnicode(result);
      }