|
@@ -3,12 +3,14 @@ package com.fuint.common.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fuint.common.dto.OrderGoodsDto;
|
|
|
import com.fuint.common.dto.UserOrderDto;
|
|
|
import com.fuint.common.enums.PrinterSettingEnum;
|
|
|
import com.fuint.common.enums.SettingTypeEnum;
|
|
|
import com.fuint.common.enums.YesOrNoEnum;
|
|
|
import com.fuint.common.service.SettingService;
|
|
|
import com.fuint.common.util.HashSignUtil;
|
|
|
+import com.fuint.common.util.NoteFormatter;
|
|
|
import com.fuint.common.util.PrinterUtil;
|
|
|
import com.fuint.common.vo.printer.*;
|
|
|
import com.fuint.framework.annoation.OperationServiceLog;
|
|
@@ -85,10 +87,14 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
|
|
|
if (StringUtils.isNotBlank(sn)) {
|
|
|
lambdaQueryWrapper.eq(MtPrinter::getSn, sn);
|
|
|
}
|
|
|
- String name = paginationRequest.getSearchParams().get("name") == null ? "" : paginationRequest.getSearchParams().get("name").toString();
|
|
|
+ String name = paginationRequest.getSearchParams().get("name") == null ? "" : paginationRequest.getSearchParams().get("name").toString();
|
|
|
if (StringUtils.isNotBlank(name)) {
|
|
|
lambdaQueryWrapper.eq(MtPrinter::getName, name);
|
|
|
}
|
|
|
+ String autoPrint = paginationRequest.getSearchParams().get("autoPrint") == null ? "" : paginationRequest.getSearchParams().get("autoPrint").toString();
|
|
|
+ if (StringUtils.isNotBlank(autoPrint)) {
|
|
|
+ lambdaQueryWrapper.eq(MtPrinter::getAutoPrint, autoPrint);
|
|
|
+ }
|
|
|
|
|
|
lambdaQueryWrapper.orderByAsc(MtPrinter::getId);
|
|
|
List<MtPrinter> dataList = mtPrinterMapper.selectList(lambdaQueryWrapper);
|
|
@@ -125,7 +131,7 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
|
|
|
// 添加云打印机
|
|
|
if (mtPrinter.getSn() != null && mtPrinter.getName() != null) {
|
|
|
AddPrinterRequest restRequest = new AddPrinterRequest();
|
|
|
- createRequestHeader(0, restRequest);
|
|
|
+ createRequestHeader(mtPrinter.getMerchantId(), restRequest);
|
|
|
AddPrinterRequestItem item = new AddPrinterRequestItem();
|
|
|
item.setName(mtPrinter.getName());
|
|
|
item.setSn(mtPrinter.getSn());
|
|
@@ -147,9 +153,9 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
|
|
|
* @return
|
|
|
* */
|
|
|
@Override
|
|
|
- public Boolean printOrder(UserOrderDto orderInfo) throws BusinessCheckException {
|
|
|
+ public Boolean printOrder(UserOrderDto orderInfo) throws Exception {
|
|
|
PrintRequest printRequest = new PrintRequest();
|
|
|
- createRequestHeader(0, printRequest);
|
|
|
+ createRequestHeader(orderInfo.getMerchantId(), printRequest);
|
|
|
if (orderInfo.getStoreInfo() == null) {
|
|
|
return false;
|
|
|
}
|
|
@@ -167,20 +173,47 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
|
|
|
MtStore storeInfo = orderInfo.getStoreInfo();
|
|
|
for (MtPrinter mtPrinter : printers) {
|
|
|
printRequest.setSn(mtPrinter.getSn());
|
|
|
+
|
|
|
StringBuilder printContent = new StringBuilder();
|
|
|
- printContent.append("<C>下单店铺:").append("<BOLD>"+storeInfo.getName()+"</BOLD>").append("<BR></C>");
|
|
|
+ printContent.append("<C>").append("<B>" + storeInfo.getName() + "</B>").append("<BR></C>");
|
|
|
printContent.append("<BR>");
|
|
|
- printContent.append("订单号:").append("<BOLD>" + orderInfo.getOrderSn()+ "<BR></BOLD>");
|
|
|
- printContent.append("订单金额:").append("<BOLD>" + orderInfo.getPayAmount()+ "<BR></BOLD>");
|
|
|
- // 订单号条形码
|
|
|
+
|
|
|
+ printContent.append("品名").append(org.apache.commons.lang3.StringUtils.repeat(" ", 16))
|
|
|
+ .append("数量").append(org.apache.commons.lang3.StringUtils.repeat(" ", 2))
|
|
|
+ .append("单价").append(org.apache.commons.lang3.StringUtils.repeat(" ", 2))
|
|
|
+ .append("<BR>");
|
|
|
+
|
|
|
+ // 分割线
|
|
|
+ printContent.append(org.apache.commons.lang3.StringUtils.repeat("-", 32)).append("<BR>");
|
|
|
+
|
|
|
+ // 商品列表
|
|
|
+ if (orderInfo.getGoods() != null && orderInfo.getGoods().size() > 0) {
|
|
|
+ for (OrderGoodsDto goodsDto : orderInfo.getGoods()) {
|
|
|
+ printContent.append(NoteFormatter.formatPrintOrderItemForNewLine80(goodsDto.getName(), goodsDto.getNum(), Double.parseDouble(goodsDto.getPrice())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分割线
|
|
|
+ printContent.append(org.apache.commons.lang3.StringUtils.repeat("-", 32)).append("<BR>");
|
|
|
+
|
|
|
+ printContent.append("<R>").append("合计:").append(orderInfo.getPayAmount()).append("元").append("<BR></R>");
|
|
|
+
|
|
|
printContent.append("<BR>");
|
|
|
- printContent.append("<C><BARCODE>"+ orderInfo.getOrderSn() +"</BARCODE></C>");
|
|
|
+ printContent.append("<L>")
|
|
|
+ .append("店铺地址:").append(orderInfo.getStoreInfo().getAddress()).append("<BR>")
|
|
|
+ .append("联系电话:").append(orderInfo.getStoreInfo().getPhone()).append("<BR>")
|
|
|
+ .append("下单时间:").append(orderInfo.getCreateTime()).append("<BR>")
|
|
|
+ .append("订单备注:").append(orderInfo.getRemark()).append("<BR>");
|
|
|
+
|
|
|
+ printContent.append("<C>")
|
|
|
+ .append("<QR>https://www.fuint.cn</QR>")
|
|
|
+ .append("</C>");
|
|
|
|
|
|
printRequest.setContent(printContent.toString());
|
|
|
printRequest.setCopies(1);
|
|
|
printRequest.setVoice(2);
|
|
|
printRequest.setMode(0);
|
|
|
- ObjectRestResponse<String> resp = PrinterUtil.print(printRequest);
|
|
|
+ PrinterUtil.print(printRequest);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
@@ -215,7 +248,7 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
|
|
|
// 删除云打印机
|
|
|
if (StringUtil.isNotEmpty(mtPrinter.getSn())) {
|
|
|
DelPrinterRequest restRequest = new DelPrinterRequest();
|
|
|
- createRequestHeader(0, restRequest);
|
|
|
+ createRequestHeader(mtPrinter.getMerchantId(), restRequest);
|
|
|
String[] snList = { mtPrinter.getSn() };
|
|
|
restRequest.setSnlist(snList);
|
|
|
PrinterUtil.delPrinters(restRequest);
|
|
@@ -228,7 +261,7 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
|
|
|
/**
|
|
|
* 修改打印机数据
|
|
|
*
|
|
|
- * @param mtPrinter 打印机参数
|
|
|
+ * @param mtPrinter 打印机参数
|
|
|
* @throws BusinessCheckException
|
|
|
* @return
|
|
|
*/
|
|
@@ -244,6 +277,18 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
|
|
|
if (printer.getMerchantId() == null || printer.getMerchantId() < 1) {
|
|
|
throw new BusinessCheckException("平台方帐号无法执行该操作,请使用商户帐号操作");
|
|
|
}
|
|
|
+
|
|
|
+ if (mtPrinter.getSn() != null && mtPrinter.getName() != null && !mtPrinter.getStatus().equals(StatusEnum.DISABLE.getKey())) {
|
|
|
+ UpdPrinterRequest restRequest = new UpdPrinterRequest();
|
|
|
+ createRequestHeader(mtPrinter.getMerchantId(), restRequest);
|
|
|
+ restRequest.setName(mtPrinter.getName());
|
|
|
+ restRequest.setSn(mtPrinter.getSn());
|
|
|
+ PrinterUtil.updPrinter(restRequest);
|
|
|
+ }
|
|
|
+ if (mtPrinter.getStatus().equals(StatusEnum.DISABLE.getKey())) {
|
|
|
+ deletePrinter(mtPrinter.getId(), mtPrinter.getOperator());
|
|
|
+ }
|
|
|
+
|
|
|
mtPrinter.setUpdateTime(new Date());
|
|
|
mtPrinterMapper.updateById(printer);
|
|
|
return printer;
|
|
@@ -258,11 +303,12 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
|
|
|
* */
|
|
|
@Override
|
|
|
public List<MtPrinter> queryPrinterListByParams(Map<String, Object> params) {
|
|
|
- String status = params.get("status") == null ? StatusEnum.ENABLED.getKey(): params.get("status").toString();
|
|
|
- String storeId = params.get("storeId") == null ? "" : params.get("storeId").toString();
|
|
|
- String merchantId = params.get("merchantId") == null ? "" : params.get("merchantId").toString();
|
|
|
- String sn = params.get("sn") == null ? "" : params.get("sn").toString();
|
|
|
- String name = params.get("name") == null ? "" : params.get("name").toString();
|
|
|
+ String status = params.get("status") == null ? StatusEnum.ENABLED.getKey(): params.get("status").toString();
|
|
|
+ String storeId = params.get("storeId") == null ? "" : params.get("storeId").toString();
|
|
|
+ String merchantId = params.get("merchantId") == null ? "" : params.get("merchantId").toString();
|
|
|
+ String sn = params.get("sn") == null ? "" : params.get("sn").toString();
|
|
|
+ String name = params.get("name") == null ? "" : params.get("name").toString();
|
|
|
+ String autoPrint = params.get("autoPrint") == null ? "" : params.get("autoPrint").toString();
|
|
|
|
|
|
LambdaQueryWrapper<MtPrinter> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
if (StringUtils.isNotBlank(status)) {
|
|
@@ -280,6 +326,9 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
|
|
|
if (StringUtils.isNotBlank(storeId)) {
|
|
|
lambdaQueryWrapper.eq(MtPrinter::getStoreId, storeId);
|
|
|
}
|
|
|
+ if (StringUtils.isNotBlank(autoPrint)) {
|
|
|
+ lambdaQueryWrapper.eq(MtPrinter::getAutoPrint, autoPrint);
|
|
|
+ }
|
|
|
lambdaQueryWrapper.orderByAsc(MtPrinter::getId);
|
|
|
|
|
|
return mtPrinterMapper.selectList(lambdaQueryWrapper);
|
|
@@ -310,7 +359,11 @@ public class PrinterServiceImpl extends ServiceImpl<MtPrinterMapper, MtPrinter>
|
|
|
request.setTimestamp(System.currentTimeMillis() + "");
|
|
|
request.setSign(HashSignUtil.sign(request.getUser() + userKey + request.getTimestamp()));
|
|
|
request.setDebug("0");
|
|
|
+ } else {
|
|
|
+ throw new BusinessCheckException("请先设置芯烨云打印账号!");
|
|
|
}
|
|
|
+ } else {
|
|
|
+ throw new BusinessCheckException("请先设置芯烨云打印账号!");
|
|
|
}
|
|
|
}
|
|
|
}
|