feat:打印机优化

This commit is contained in:
dzc committed 2025-03-19 20:16:40 +08:00
1 parent 481291884d
commit 32341ef253
5 files changed
+38 -17

No files matched your search

+18 -5
View File
@@ -5,6 +5,8 @@ import 'package:get/get.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
class PrintManage extends BaseFacilityManage {
static const String _tag = "打印机管理";
USBPrinterManager? manager;
CapabilityProfile? profile;
int paperSizeWidthMM = PaperSizeWidth.mm80;
@@ -25,8 +27,13 @@ class PrintManage extends BaseFacilityManage {
if (ObjectUtil.isEmpty(target)) return false;
profile = await CapabilityProfile.load();
manager = USBPrinterManager(target!);
final res = await manager!.connect();
return res.value == 1;
try {
await manager?.connect();
return true;
} catch (e) {
logger.e("|$_tag|打开打印机失败error|$e|");
return false;
}
}
Future<bool> printImg(String img) async {
@@ -43,11 +50,17 @@ class PrintManage extends BaseFacilityManage {
profile!,
);
List<int> bytes = [];
bytes += generator.feed(2);
bytes += generator.image(image!);
bytes += generator.feed(1);
bytes += generator.feed(2);
bytes += generator.cut();
final res = await manager!.writeBytes(bytes);
return res.value == 1;
try {
await manager!.writeBytes(bytes);
return true;
} catch (e) {
logger.e("|$_tag|打印机失败error|$e|");
return false;
}
}
@override
+8 -6
View File
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:common_utils/common_utils.dart';
import 'package:get/get.dart';
@@ -14,8 +16,8 @@ abstract class SyncPrintTool {
required String historyId,
required String pic,
}) async {
final app = Get.find<AppControl>();
final printHistoryDao = app.dataBase.getPrintHistoryDao;
final appC = Get.find<AppControl>();
final printHistoryDao = appC.dataBase.getPrintHistoryDao;
final saveObj = PrintHistoryEntity(
orderId: androidOrderId,
serviceOrderId: orderId,
@@ -35,9 +37,9 @@ abstract class SyncPrintTool {
logger.i("|$_tag|检查打印,正在打印中");
return;
}
final app = Get.find<AppControl>();
final printHistoryDao = app.dataBase.getPrintHistoryDao;
final printFacility = app.printManage;
final appC = Get.find<AppControl>();
final printHistoryDao = appC.dataBase.getPrintHistoryDao;
final printFacility = appC.printManage;
try {
// 检查有没有需要打印的
final list = await printHistoryDao.getAll(PrintStatus.NONE.name);
@@ -72,7 +74,7 @@ abstract class SyncPrintTool {
if (!isPrint) {
v.status = PrintStatus.ERROR;
await printHistoryDao.edit(v);
throw Error();
throw Exception("|$_tag|打印失败params|${v.toJson()}|");
}
// 更新本地数据库
v.status = PrintStatus.SUCCESS;
@@ -377,8 +377,12 @@ mixin OrderMixin {
// 获取商品的描述信息
String getProductDesc() {
String desc = "";
for (var e in shopCardList) {
desc += "${e.productName}x${e.productNumber};";
for (final v in shopCardList) {
if (v.nature == ProductNature.DEFAULT) {
desc += "${v.productName}x${v.productNumber};";
} else if (v.nature == ProductNature.WEIGHT) {
desc += "${v.productName}x${v.productWidget}/kg;";
}
}
return desc;
}
+1 -1
View File
@@ -228,7 +228,7 @@ class OrderHistoryController extends GetxController {
final data = await HardApi.generateInvoice(pa);
if (data == null) throw Error();
if (ObjectUtil.isEmpty(data.historyId) || ObjectUtil.isEmpty(data.pic)) {
throw Error();
throw Exception("服务端生成发票失败");
}
await SyncPrintTool.addTask(
orderId: v.serviceUniqueCode,
+5 -3
View File
@@ -134,9 +134,9 @@ class OrderHistoryPage extends GetView<OrderHistoryController> {
fixedWidth: 150.w,
),
DataColumn2(
label: Text('菜品名称'),
label: Text('商品名称'),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: 220.w,
fixedWidth: 400.w,
),
DataColumn2(
label: Text('总价'),
@@ -189,7 +189,9 @@ class OrderHistoryPage extends GetView<OrderHistoryController> {
DataCell(
Text(
v.productDesc ?? "未知商品",
textAlign: TextAlign.center,
textAlign: TextAlign.start,
maxLines: 1,
overflow: TextOverflow.ellipsis,
).center(),
),
DataCell(