无关风月
2025-02-14 11ec1c23a9f47ed70b124e413e33e3696897390f
common/src/main/java/com/jilongda/common/Ticket/TicketUtil.java
@@ -51,58 +51,58 @@
         List<TOptometryDetailVO> temp = new ArrayList<>();
         TOptometryDetailVO t1 = new TOptometryDetailVO();
         t1.setType(3);
         t1.setBallMirror(-1.00D);
         t1.setColumnMirror(-0.10D);
         t1.setAxis("30");
         t1.setPupilDistance("33");
//         t1.setBallMirror(-1.00D);
//         t1.setColumnMirror(-0.10D);
//         t1.setAxis("30");
//         t1.setPupilDistance("33");
         t1.setStatus(1);
         temp.add(t1);
         TOptometryDetailVO t2 = new TOptometryDetailVO();
         t2.setType(3);
         t2.setBallMirror(-1.00D);
         t2.setColumnMirror(-0.10D);
         t2.setAxis("30");
         t2.setPupilDistance("33");
//         t2.setBallMirror(-1.00D);
//         t2.setColumnMirror(-0.10D);
//         t2.setAxis("30");
//         t2.setPupilDistance("33");
         t2.setStatus(2);
         temp.add(t2);
         TOptometryDetailVO t3 = new TOptometryDetailVO();
         t3.setType(2);
         t3.setBallMirror(-1.00D);
         t3.setColumnMirror(-0.10D);
         t3.setAxis("30");
         t3.setPupilDistance("33");
         t3.setCorrect("1.0");
//         t3.setBallMirror(-1.00D);
//         t3.setColumnMirror(-0.10D);
//         t3.setAxis("30");
//         t3.setPupilDistance("33");
//         t3.setCorrect("1.0");
         t3.setStatus(1);
         temp.add(t3);
         TOptometryDetailVO t4 =  new TOptometryDetailVO();
         t4.setType(2);
         t4.setBallMirror(-1.00D);
         t4.setColumnMirror(-0.10D);
         t4.setAxis("30");
         t4.setPupilDistance("33");
         t4.setCorrect("1.0");
//         t4.setBallMirror(-1.00D);
//         t4.setColumnMirror(-0.10D);
//         t4.setAxis("30");
//         t4.setPupilDistance("33");
//         t4.setCorrect("1.0");
         t4.setStatus(2);
         temp.add(t4);
         TOptometryDetailVO t5 = new TOptometryDetailVO();
         t5.setType(1);
         t5.setBallMirror(-1.00D);
         t5.setColumnMirror(-0.10D);
         t5.setAxis("30");
         t5.setAddS("50");
         t5.setPupilHeight("50");
         t5.setPupilDistance("33");
         t5.setCorrect("1.0");
//         t5.setBallMirror(-1.00D);
//         t5.setColumnMirror(-0.10D);
//         t5.setAxis("30");
//         t5.setAddS("50");
//         t5.setPupilHeight("50");
//         t5.setPupilDistance("33");
//         t5.setCorrect("1.0");
         t5.setStatus(1);
         temp.add(t5);
         TOptometryDetailVO t6 = new TOptometryDetailVO();
         t6.setType(1);
         t6.setBallMirror(-1.00D);
         t6.setColumnMirror(-0.10D);
         t6.setAxis("30");
         t6.setAddS("50");
         t6.setPupilHeight("50");
         t6.setPupilDistance("33");
         t6.setCorrect("1.0");
//         t6.setBallMirror(-1.00D);
//         t6.setColumnMirror(-0.10D);
//         t6.setAxis("30");
//         t6.setAddS("50");
//         t6.setPupilHeight("50");
//         t6.setPupilDistance("33");
//         t6.setCorrect("1.0");
         t6.setStatus(2);
         temp.add(t6);
@@ -340,31 +340,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 +374,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;
@@ -448,6 +450,158 @@
         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>");
//                     (s.getAddS()==null?"-":s.getAddS())
//                     (s.getPupilDistance()==null?"-":s.getPupilDistance())
//
//                     (s.getCorrect()==null?"-":s.getCorrect())
//                     (s.getBallMirror()==null?"-":s.getBallMirror())
//                     (s.getColumnMirror()==null?"-":s.getColumnMirror())
//                     (s.getAxis()==null?"-":s.getAxis())
//                     (s.getAddS()==null?"-":s.getAddS())
//                     (s.getPupilDistance()==null?"-":s.getPupilDistance())
//                     (s.getPupilHeight()==null?"-":s.getPupilHeight())
//                     (s.getCorrect()==null?"-":s.getCorrect())
                     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);
            }
         }
         for (TOrderGoodsPrintVO orderGood : orderGoods) {
            if (orderGood.getRLens()!=null){
               tOrderGoodsPrintVOS.add(orderGood);
            }
         }
         for (TOrderGoodsPrintVO orderGood : orderGoods) {
            if (orderGood.getLLens()!=null){
               tOrderGoodsPrintVOS.add(orderGood);
            }
         }
         for (TOrderGoodsPrintVO tOrderGoodsPrintVO : tOrderGoodsPrintVOS) {
            if (tOrderGoodsPrintVO.getModelId()!=null){
               content.append("镜架:").append(tOrderGoodsPrintVO.getBrandName()+"-").append(tOrderGoodsPrintVO.getMaterial()+"-").append(tOrderGoodsPrintVO.getModelName()).append("<BR>");
            }
            if (tOrderGoodsPrintVO.getRLens()!=null){
               content.append("右眼镜片:").append(tOrderGoodsPrintVO.getBrandName()+"-").append(tOrderGoodsPrintVO.getSeriesName()+"-").append(tOrderGoodsPrintVO.getRefractiveIndex()).append("<BR>");
            }
            if (tOrderGoodsPrintVO.getModelId()!=null){
               content.append("左眼镜片:").append(tOrderGoodsPrintVO.getBrandName()+"-").append(tOrderGoodsPrintVO.getSeriesName()+"-").append(tOrderGoodsPrintVO.getRefractiveIndex()).append("<BR>");
            }
         }
         content.append("客户电话:").append(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);
      }