From b535152aa65fa301ad637143c2ea4f078b72e8ea Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Fri, 15 Jul 2022 17:30:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HighGasClassGroupTaskController.java | 60 ++++++++++++++- .../com/hai/config/SpPrinterTemplate.java | 32 ++++++++ .../com/hai/config/ZkcPrinterTemplate.java | 75 +++++++++++++++++++ .../HighGasClassGroupTaskServiceImpl.java | 47 ++++++++++-- 4 files changed, 208 insertions(+), 6 deletions(-) diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighGasClassGroupTaskController.java b/hai-bweb/src/main/java/com/bweb/controller/HighGasClassGroupTaskController.java index c0ce5ba1..eabe0107 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighGasClassGroupTaskController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighGasClassGroupTaskController.java @@ -8,10 +8,17 @@ import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.security.UserCenter; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.config.MqttProviderConfig; +import com.hai.config.SpPrinterConfig; +import com.hai.config.SpPrinterTemplate; +import com.hai.config.ZkcPrinterTemplate; +import com.hai.entity.HighDevice; import com.hai.entity.HighGasClassGroupTask; +import com.hai.enum_type.DeviceTypeEnum; import com.hai.enum_type.GasClassGroupTaskStatus; import com.hai.model.GasClassGroupTaskDataCount; import com.hai.model.ResponseData; +import com.hai.service.HighDeviceService; import com.hai.service.HighGasClassGroupTaskService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -41,6 +48,12 @@ public class HighGasClassGroupTaskController { @Resource private HighGasClassGroupTaskService gasClassGroupTaskService; + @Resource + private HighDeviceService deviceService; + + @Resource + private MqttProviderConfig mqttProviderConfig; + @Resource private UserCenter userCenter; @@ -140,7 +153,6 @@ public class HighGasClassGroupTaskController { } } - @RequestMapping(value = "/getClassGroupTaskById", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询班组任务记录") @@ -178,4 +190,50 @@ public class HighGasClassGroupTaskController { } } + @RequestMapping(value = "/print", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "打印小票") + public ResponseData print(@RequestParam(name = "gasClassGroupTaskId", required = true) Long gasClassGroupTaskId) { + try { + HighGasClassGroupTask groupTask = gasClassGroupTaskService.getDetailById(gasClassGroupTaskId); + if (groupTask == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到班次"); + } + GasClassGroupTaskDataCount dataCount = JSONObject.parseObject(groupTask.getDataCount(), GasClassGroupTaskDataCount.class); + + // 查询加油站打印机 + List deviceList = deviceService.getDeviceListByStoreId(groupTask.getMerchantStoreId()); + for (HighDevice device : deviceList) { + if (device.getType().equals(DeviceTypeEnum.type1.getType())) { + new Thread(() -> { + try { + // 推送打印机 + SpPrinterConfig spPrinterConfig = new SpPrinterConfig(); + spPrinterConfig.print(device.getDeviceSn(), SpPrinterTemplate.classGroupCountTemp(dataCount), 1); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + } + if (device.getType().equals(DeviceTypeEnum.type2.getType())) { + new Thread(() -> { + try { + // 推送打印机 + mqttProviderConfig.publish(2,false, device.getDeviceImei(), ZkcPrinterTemplate.classGroupCountTemp(dataCount)); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + } + } + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("HighGasClassGroupTaskController --> getClassGroupTaskById() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + } diff --git a/hai-service/src/main/java/com/hai/config/SpPrinterTemplate.java b/hai-service/src/main/java/com/hai/config/SpPrinterTemplate.java index 88fb65ff..7dbce50a 100644 --- a/hai-service/src/main/java/com/hai/config/SpPrinterTemplate.java +++ b/hai-service/src/main/java/com/hai/config/SpPrinterTemplate.java @@ -1,6 +1,8 @@ package com.hai.config; import com.hai.common.utils.DateUtil; +import com.hai.model.GasClassGroupTaskDataCount; +import com.hai.model.GasClassGroupTaskOilCount; import java.util.Date; @@ -10,6 +12,36 @@ import java.util.Date; */ public class SpPrinterTemplate { + /** + * 加油站收银员存根模板 + */ + public static String classGroupCountTemp(GasClassGroupTaskDataCount dataCount) throws Exception { + String str = "" + dataCount.getClassNum() + "班结流水
" + + "===============================
" + + "开始时间:" + DateUtil.date2String(dataCount.getStartTime(), "yyyy-MM-dd HH:mm:ss") + "
" + + "结束时间:" + DateUtil.date2String(dataCount.getEndTime(), "yyyy-MM-dd HH:mm:ss") + "
" + + "
" + + "加油金额汇总:" + dataCount.getRefuelPrice() + "元
" + + "加油笔数汇总:" + dataCount.getRefuelNum() + "笔
" + + "加油升数汇总:" + dataCount.getRefuelLiters() + "升
" + + "
" + + "退款金额汇总:" + dataCount.getRefundPrice() + "元
" + + "退款笔数汇总:" + dataCount.getRefundNum() + "笔
" + + "退款升数汇总:" + dataCount.getRefundLiters() + "升
" + + "
" + + "--------------收款-------------
" + + "油号 金额 升数 笔数
"; + + String oilCountStr = ""; + for (GasClassGroupTaskOilCount oilCount : dataCount.getGroupTaskOilCountList()) { + oilCountStr += oilCount.getOilNo() + "# " + oilCount.getRefuelPrice() + "元 " + oilCount.getRefuelLiters() + "升 " + oilCount.getRefuelNum() + "笔
"; + } + str += oilCountStr + + "==============================
" + + "" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss") +"
"; + return str; + } + /** * 加油站收银员存根模板 * @param gasName 油站名称 diff --git a/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java b/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java index 2bc51261..2124a31c 100644 --- a/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java +++ b/hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java @@ -1,6 +1,8 @@ package com.hai.config; import com.hai.common.utils.DateUtil; +import com.hai.model.GasClassGroupTaskDataCount; +import com.hai.model.GasClassGroupTaskOilCount; import java.io.ByteArrayOutputStream; import java.util.Date; @@ -11,6 +13,79 @@ import java.util.Date; */ public class ZkcPrinterTemplate { + /** + * 加油站 + * @return + */ + public static byte[] classGroupCountTemp(GasClassGroupTaskDataCount dataCount) throws Exception { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + // 居中 + stream.write(0x1B); + stream.write(0x61); + stream.write(0x01); + + stream.write((dataCount.getClassNum() + "班结流水").getBytes("UTF-8")); + stream.write(0x0A); + stream.write("================================".getBytes("UTF-8")); + stream.write(0x0A); + + // 左对齐 + stream.write(0x1B); + stream.write(0x61); + stream.write(0x00); + + stream.write(0x0A); + stream.write(("开始时间:" + DateUtil.date2String(dataCount.getStartTime(), "yyyy-MM-dd HH:mm:ss")).getBytes("UTF-8")); + stream.write(0x0A); + stream.write(("结束时间:" + DateUtil.date2String(dataCount.getEndTime(), "yyyy-MM-dd HH:mm:ss")).getBytes("UTF-8")); + stream.write(0x0A); + stream.write(0x0A); + + stream.write(("加油金额汇总:" + dataCount.getRefuelPrice() + "元").getBytes("UTF-8")); + stream.write(0x0A); + stream.write(("加油笔数汇总:" + dataCount.getRefuelNum() + "笔").getBytes("UTF-8")); + stream.write(0x0A); + stream.write(("加油升数汇总:" + dataCount.getRefuelLiters() + "升").getBytes("UTF-8")); + stream.write(0x0A); + stream.write(0x0A); + + stream.write(("退款金额汇总:" + dataCount.getRefundPrice() + "元").getBytes("UTF-8")); + stream.write(0x0A); + stream.write(("退款笔数汇总:" + dataCount.getRefundNum() + "笔").getBytes("UTF-8")); + stream.write(0x0A); + stream.write(("退款升数汇总:" + dataCount.getRefundLiters() + "升").getBytes("UTF-8")); + stream.write(0x0A); + stream.write(0x0A); + + stream.write("--------------收款--------------".getBytes("UTF-8")); + stream.write(0x0A); + stream.write("油号 金额 升数 笔数".getBytes("UTF-8")); + stream.write(0x0A); + + for (GasClassGroupTaskOilCount oilCount : dataCount.getGroupTaskOilCountList()) { + stream.write((oilCount.getOilNo() + "# " + oilCount.getRefuelPrice() + "元 " + oilCount.getRefuelNum() + "升 " + oilCount.getRefuelLiters() + "笔").getBytes("UTF-8")); + stream.write(0x0A); + } + stream.write("================================".getBytes("UTF-8")); + stream.write(0x0A); + + // 居中 + stream.write(0x1B); + stream.write(0x61); + stream.write(0x01); + + stream.write(DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss").getBytes("UTF-8")); + stream.write(0x0A); + + + stream.write(0x0A); + stream.write(0x0A); + stream.write(0x0A); + stream.write(0x0A); + + return getPrinterBytes(stream.toByteArray(), 1, "UTF-8"); + } + /** * 加油站 * @param gasName 油站名称 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighGasClassGroupTaskServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighGasClassGroupTaskServiceImpl.java index 2e265f10..22c38c22 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighGasClassGroupTaskServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighGasClassGroupTaskServiceImpl.java @@ -4,14 +4,17 @@ import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.config.MqttProviderConfig; +import com.hai.config.SpPrinterConfig; +import com.hai.config.SpPrinterTemplate; +import com.hai.config.ZkcPrinterTemplate; import com.hai.dao.HighGasClassGroupTaskMapper; -import com.hai.entity.HighGasClassGroup; -import com.hai.entity.HighGasClassGroupTask; -import com.hai.entity.HighGasClassGroupTaskExample; -import com.hai.entity.HighMerchantStore; +import com.hai.entity.*; +import com.hai.enum_type.DeviceTypeEnum; import com.hai.enum_type.GasClassGroupTaskStatus; import com.hai.model.GasClassGroupTaskDataCount; import com.hai.model.GasClassGroupTaskOilCount; +import com.hai.service.HighDeviceService; import com.hai.service.HighGasClassGroupService; import com.hai.service.HighGasClassGroupTaskService; import com.hai.service.HighMerchantStoreService; @@ -37,6 +40,12 @@ public class HighGasClassGroupTaskServiceImpl implements HighGasClassGroupTaskSe @Resource private HighMerchantStoreService merchantStoreService; + @Resource + private HighDeviceService deviceService; + + @Resource + private MqttProviderConfig mqttProviderConfig; + @Override @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void startGroupTask(Long gasId, Long gasClassGroupId) { @@ -82,8 +91,36 @@ public class HighGasClassGroupTaskServiceImpl implements HighGasClassGroupTaskSe HighGasClassGroupTask groupTask = list.get(0); groupTask.setEndTime(new Date()); groupTask.setStatus(GasClassGroupTaskStatus.status2.getStatus()); - groupTask.setDataCount(JSONObject.toJSONString(countGroupTaskData(gasId, groupTask.getClassNum(), groupTask.getId(), groupTask.getStatus(), groupTask.getStartTime(), groupTask.getEndTime()))); + // 统计 + GasClassGroupTaskDataCount dataCount = countGroupTaskData(gasId, groupTask.getClassNum(), groupTask.getId(), groupTask.getStatus(), groupTask.getStartTime(), groupTask.getEndTime()); + groupTask.setDataCount(JSONObject.toJSONString(dataCount)); editGroupTask(groupTask); + + // 查询加油站打印机 + List deviceList = deviceService.getDeviceListByStoreId(gasId); + for (HighDevice device : deviceList) { + if (device.getType().equals(DeviceTypeEnum.type1.getType())) { + new Thread(() -> { + try { + // 推送打印机 + SpPrinterConfig spPrinterConfig = new SpPrinterConfig(); + spPrinterConfig.print(device.getDeviceSn(), SpPrinterTemplate.classGroupCountTemp(dataCount), 1); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + } + if (device.getType().equals(DeviceTypeEnum.type2.getType())) { + new Thread(() -> { + try { + // 推送打印机 + mqttProviderConfig.publish(2,false, device.getDeviceImei(), ZkcPrinterTemplate.classGroupCountTemp(dataCount)); + } catch (Exception e) { + e.printStackTrace(); + } + }).start(); + } + } } }