提交代码

dev-discount
胡锐 2 years ago
parent 890989902b
commit b535152aa6
  1. 60
      hai-bweb/src/main/java/com/bweb/controller/HighGasClassGroupTaskController.java
  2. 32
      hai-service/src/main/java/com/hai/config/SpPrinterTemplate.java
  3. 75
      hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java
  4. 47
      hai-service/src/main/java/com/hai/service/impl/HighGasClassGroupTaskServiceImpl.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<HighDevice> 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);
}
}
}

@ -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 = "<C>" + dataCount.getClassNum() + "班结流水</C> <BR> " +
"===============================<BR>" +
"开始时间:" + DateUtil.date2String(dataCount.getStartTime(), "yyyy-MM-dd HH:mm:ss") + "<BR>" +
"结束时间:" + DateUtil.date2String(dataCount.getEndTime(), "yyyy-MM-dd HH:mm:ss") + "<BR>" +
"<BR>" +
"加油金额汇总:" + dataCount.getRefuelPrice() + "元<BR>" +
"加油笔数汇总:" + dataCount.getRefuelNum() + "笔<BR>" +
"加油升数汇总:" + dataCount.getRefuelLiters() + "升<BR>" +
"<BR>" +
"退款金额汇总:" + dataCount.getRefundPrice() + "元<BR>" +
"退款笔数汇总:" + dataCount.getRefundNum() + "笔<BR>" +
"退款升数汇总:" + dataCount.getRefundLiters() + "升<BR>" +
"<BR>" +
"--------------收款-------------<BR>" +
"油号 金额 升数 笔数<BR>";
String oilCountStr = "";
for (GasClassGroupTaskOilCount oilCount : dataCount.getGroupTaskOilCountList()) {
oilCountStr += oilCount.getOilNo() + "# " + oilCount.getRefuelPrice() + "元 " + oilCount.getRefuelLiters() + "升 " + oilCount.getRefuelNum() + "笔<BR>";
}
str += oilCountStr +
"==============================<BR>" +
"<C>" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss") +"</C> <BR>";
return str;
}
/**
* 加油站收银员存根模板
* @param gasName 油站名称

@ -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 油站名称

@ -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<HighDevice> 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();
}
}
}
}

Loading…
Cancel
Save