之前写过一个打印机的一段代码,由于之前的代码存在缺陷,现在我来做下补充:
直接上干货:

    @Scheduled(cron = "0/5 * * * * ?")public  void shopCancelOrder(){logger.info("开始打印商家端订单小票");QueryWrapper<ShopOrder> queryWrapper = new QueryWrapper<ShopOrder>();queryWrapper.eq("status", 2);//待发货queryWrapper.eq("is_del",2);//未删除的List<ShopOrder> shopOrderList = shopOrderService.list(queryWrapper);  //得到订单表for (ShopOrder shopOrder : shopOrderList) {// 遍历订单表String content ="";List<OrderInfo> orderInfoList = orderGoodsService.selectShopIdAndOther(shopOrder.getId());  //只搜索打印状态为0的 ,可以得到商品id的for (int i =0 ; i< orderInfoList.size();) {int num = 1;List<OrderInfo> orListChange = new ArrayList<>();BigDecimal totalPrice = new BigDecimal(0);BigDecimal totalPrice2 = new BigDecimal(0);BigDecimal totalPriceTotal = new BigDecimal(0);OrderInfo orderInfo = orderInfoList.get(i);Goods goods = goodsService.getById(orderInfo.getGoodsId());Long shopId = goods.getShopId();int returnCount = orderGoodsService.selectByShopIdReturnCount(shopOrder.getId(), shopId);SysUser sysUser = userService.selectByPrimaryKey(shopId);int flag = 0;if(flag == 0){if(sysUser!=null){content = "<CB>"+sysUser.getShopName()+"</CB><BR>";content += "序号 名称        单价 数量 ";content += "--------------------------------<BR>";flag++;}else{logger.error("商家端打印失败:无此商家" );}}for (int j =i+1 ; j< orderInfoList.size(); j++){OrderInfo orderInfo1 = orderInfoList.get(j);Goods goods1 = goodsService.getById(orderInfo1.getGoodsId());Long shopId1 = goods1.getShopId();if(shopId1.equals(shopId) && goods1 != null && orderInfo1.getShopPrint()==0 ){content += num + " " + cutString(goods1.getName()+"/"+goods.getStardardName()) + " " + orderInfo1.getUnitPrice()+ "  " + orderInfo1.getBuyNum() + "<BR>";num++;i++;orListChange.add(orderInfo1);//System.out.println("--------------加入orListChange的orderInfo为shopid->"+orderInfo1.getShopId()+"商品id为"+orderInfo1.getGoodsId()+"----------------");totalPrice = totalPrice.add(orderInfo1.getUnitPrice().multiply(new BigDecimal(orderInfo1.getBuyNum())));}else{ continue; }}if(goods != null ){if( orderInfo.getShopPrint()==0){content += num + " " + cutString(goods.getName()+"/"+goods.getStardardName()) + " " + orderInfo.getUnitPrice()+ "  " + orderInfo.getBuyNum() + "<BR>";num++;i++;orListChange.add(orderInfo);//System.out.println("--------------加入orListChange的orderInfo为shopid->"+orderInfo.getShopId()+"商品id为"+orderInfo.getGoodsId()+"----------------");totalPrice2 = totalPrice2.add(orderInfo.getUnitPrice().multiply(new BigDecimal(orderInfo.getBuyNum())));}}else{clearAllCont(totalPrice,totalPrice2,totalPriceTotal,orListChange);logger.error("商家端打印失败:无此商品 -> id: " + goods.getId() );}content += "备注:" + shopOrder.getBak() + "<BR>";content += "--------------------------------<BR>";totalPriceTotal= totalPrice.add(totalPrice2);content += "  合计: " + totalPriceTotal + "元<BR>";UserProp prop = userPropService.getById(shopOrder.getAddressId());content += "订单编号:" + shopOrder.getOrderNo() + "<BR>";content += "送货地点:" + prop.getAddress() + "<BR>";content += "收货人:  " + prop.getUserName() + "<BR>";content += "联系电话:" + prop.getPhone() + "<BR>";content += "下单时间:" + shopOrder.getCreatetime() + "<BR>";QueryWrapper<ShopDevices> queryShopDevicesWrapper = new QueryWrapper<ShopDevices>();queryShopDevicesWrapper.eq("status", 1);queryShopDevicesWrapper.eq("shop_id", shopId);List<ShopDevices> shopDevicesList = shopDevicesService.list(queryShopDevicesWrapper);for (int k = 0; k<shopDevicesList.size(); k++) {ShopDevices shopDevices = shopDevicesList.get(k);if (shopDevices.getStatus() == 1) {try {JSONObject jsonObject = PrintDeviceUtil.print(url, shopDevices.getDeviceNo(),shopDevices.getMkey(), content, shopDevices.getTimes() + "");String responseCode = jsonObject.getString("responseCode");if ("0".equals(responseCode)) {//获取打印设备的订单索引String orderindex = jsonObject.getString("orderindex");JSONObject jsonObject1 = PrintDeviceUtil.printStatus(url, shopDevices.getDeviceNo(),shopDevices.getMkey(), orderindex);String responseCode1 = jsonObject1.getString("responseCode");if ("0".equals(responseCode1)) {if(orListChange != null){//System.out.println("-----------------------"+orListChange.size()+"------------------------------------");if( returnCount == orListChange.size() ){///int count=0;for(OrderInfo orderInfo2:orListChange){if(orderInfo2.getShopPrint() == 0 ){count += orderGoodsService.updateByInfoId(orderInfo2.getOrderId(), orderInfo2.getGoodsId());}else{clearAllCont(totalPrice,totalPrice2,totalPriceTotal,orListChange);logger.error("商家端打印失败:订单中商品部分已经打印!" );}}if(count == orListChange.size()){/* System.out.println("====打印完之后的小票打印状态====" + orderGoodsService.getById(orderInfo.getId()).getShopPrint());System.out.println("====控制台输出订单打印内容===="+content);*/clearAllCont(totalPrice,totalPrice2,totalPriceTotal,orListChange);logger.info(content);logger.info("商家端打印成功");}else{if(k==shopDevicesList.size()){clearAllCont(totalPrice,totalPrice2,totalPriceTotal,orListChange);}logger.error("商家端打印失败:订单中商品未全部成功修改打印状态!" );}}else{if(k==shopDevicesList.size()){clearAllCont(totalPrice,totalPrice2,totalPriceTotal,orListChange);}logger.error("商家端打印失败:订单中商品未全部录入待打印状态!" );}}else{if(k==shopDevicesList.size()){clearAllCont(totalPrice,totalPrice2,totalPriceTotal,orListChange);}logger.error("商家端打印失败:无符合订单!" );}} else {if(k==shopDevicesList.size()){clearAllCont(totalPrice,totalPrice2,totalPriceTotal,orListChange);}logger.error("商家端打印失败:" + jsonObject1);}} else {if(k==shopDevicesList.size()){clearAllCont(totalPrice,totalPrice2,totalPriceTotal,orListChange);}logger.error("商家端打印失败:" + jsonObject);}} catch (IOException e) {if(k==shopDevicesList.size()){clearAllCont(totalPrice,totalPrice2,totalPriceTotal,orListChange);}logger.error("商家端打印失败:" + e.getMessage());}} else {if(k==shopDevicesList.size()){clearAllCont(totalPrice,totalPrice2,totalPriceTotal,orListChange);}logger.error("商家端打印失败,打印机未开启!");}}}}logger.info("商家端打印结束");}public static void clearAllCont(BigDecimal totalPrice,BigDecimal totalPrice2,BigDecimal totalPriceTotal,List<OrderInfo> orListChange){orListChange.clear();totalPrice = BigDecimal.ZERO;totalPrice2 = BigDecimal.ZERO;totalPriceTotal = BigDecimal.ZERO;}public static String cutString(String str) {String result = str_split(str, 10, "<BR>");
//        System.out.println(result);return result;}public static String[] str_split(String str, int length) {int len = str.length();String[] arr = new String[(len + length - 1) / length];for (int i = 0; i < len; i += length) {int n = len - i;if (n > length) {n = length;}if(i > 0){arr[i / length] = "  " + str.substring(i, i + n);}else{arr[i / length] =  str.substring(i, i + n);}}while (arr[arr.length - 1].length() < 15){arr[arr.length - 1] += " ";}return arr;}public static String str_split(String str, int length, CharSequence delimiter) {return String.join(delimiter, str_split(str, length));}

springBoot项目--平台控制商品订单中各商家打印机打印小票--终极版相关推荐

  1. springboot项目扫描不到controller中的解决方法

    springboot项目扫描不到controller中的解决方法 问题:启动类与controller不在同一级中,扫描不到controller中的方法 解决方法:在启动类填加注解@ComponentS ...

  2. get请求中文传参乱码问题解决汇总终极版

    get请求中文传参乱码问题解决汇总终极版 一.如果使用tomcat作为服务器,那么修改tomcat配置文件conf/server.xml中,在 <Connector port="808 ...

  3. SpringBoot 雪花算法生成商品订单号【SpringBoot系列13】

    SpringCloud 大型系列课程正在制作中,欢迎大家关注与提意见. 程序员每天的CV 与 板砖,也要知其所以然,本系列课程可以帮助初学者学习 SpringBooot 项目开发 与 SpringCl ...

  4. springboot项目自定义类在配置文件中的提示

    目录 一.写在前面 二.加依赖 三.打包时不需要将配置处理器打进去,排除即可 四.测试 一.写在前面 springboot自定义的bean,绑定配置文件之后通常是不会有提示的. 二.加依赖 <d ...

  5. Springboot项目使用jasypt加密配置文件中的敏感信息

    目录 目录 项目背景 需求 jasypt简介 使用 0,版本对应关系 1,引入依赖 2,启用加密 2.1,在启动类上配置注解 2.2,启用注解扫描和@Configuration配置 2.3,只针对指定 ...

  6. springboot创建parent_创建springboot项目时,pom.xml中parent报错

    下载Maven 进入maven官网 http://maven.apache.org/download.cgi. 找到并点击apache-maven-3.6.2-bin.zipi.下载压缩包 配置Mav ...

  7. 操作系统基础知识点(从题目中总结)期末复习总结 终极版 ctrl+f 寻找你想要的答案

    1.( )不是操作系统关心的主要问题 A. 管理计算机裸机  B. 设计.提供用户程序与计算机硬件系统的界面  C. 管理计算机系统资源  D. 高级程序设计语言的编译器 2.财务软件是一种( ). ...

  8. 混合 html5蓝牙打印小票怎么排版,蓝牙打印机打印小票项目版

    项目需要需要写一个手机开小票的东西,蓝牙打印机是目前比较成熟的东西!某宝买了一个蓝牙打印机和几卷热敏纸开搞..... 本人对android原生的东西不了解,也不想去麻烦我们的android工程师,只好 ...

  9. android 蓝牙打印兼容,在Android中使用蓝牙打印机打印不起作用

    我正在开发应用程序,允许用户创建PDF并允许使用蓝牙打印机进行打印. 我创建了PDF,但每当我要使用蓝牙打印机集成打印功能时,都会出现错误. 我无法获得蓝牙设备列表. 如果您有任何示例代码,请提供给我 ...

最新文章

  1. 操作Docker容器
  2. 利用Docker构建开发环境
  3. Intel Realsense C/C++ 转 python (9)rs-multicam 多摄像头可视化窗体显示
  4. 7 兼容 因特尔十代_年终抄底十代酷睿 请务必看看它……- ——快科技(驱动之家旗下媒体)-...
  5. linux deepin sudo: add-apt-repository:找不到命令 解决办法
  6. 在java中使用关键字导入包_java中import关键字的使用方法
  7. Python 基础知识(二)
  8. 搭建IntelliJ IDEA+maven+jetty+SpringMVC 开发环境(二)
  9. 颜色直方图的计算、显示、处理、对比及反向投影(How to Use Histogram? Calculate, Show, Process, Compare and BackProject)...
  10. 使用akka框架编写RPC框架
  11. levy过程和布朗运动的关系_金融数学之定价模型基础解释【布朗运动|维纳过程|伊藤引理】...
  12. Unity3D游戏开发从零单排(三) - 极速创建狂拽酷炫的游戏地形
  13. java程序编译后会产生_java程序编译后会产生什么
  14. vs2015安装与配置
  15. 手握百万恶意IP,阿里云要跟黑客拼了 | 云栖大会
  16. 假想参考解码器 vbv HRD
  17. 双稳态电路的两个稳定状态是什么_555时基电路内部结构及其工作原理
  18. 精细化用电侧能源管控 解码光伏电站运维痛点
  19. 栈帧%ebp,%esp详解
  20. 解决迅雷极速版强制升级-20190715

热门文章

  1. Oracle笔记之期末总复习
  2. 计算机课高数怎么过,我是大一新鸟,学软件,想向大虾们讨教几手,我有高数,英语,法律.计算机,4门课,我该怎么学!介绍越详细越好,...
  3. 编程中常见的小错误·
  4. 中文puppy linux7.5,小型Linux发行版Puppy Linux 7.5发布下载
  5. element 日期选择器
  6. 机器人测钢卷直径_自动拆钢卷捆带装置的制作方法
  7. GWAS理论 1-4 关联分析模型和常用软件介绍
  8. 品牌与Logo有什么区别?进来了解下
  9. phytool下载与使用(详解)
  10. ISCC 2019 杂项High起来!(酷爱音乐的你,在听歌的过程中突然收到音乐发烧友发来的一封神秘的邮件,邮件里什么都没有说,只有一个被损坏的图片。这名歌友到底要向你传达什么信息呢?答案或许就隐藏)