店铺管理-店铺配置:打印机设置相关接口
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package com.chaozhanggui.system.cashierservice.rabbit.print;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.CallNumPrintPO;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.TbCallQueueMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.TbCallTableMapper;
|
||||
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
|
||||
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderInfoMapper;
|
||||
@@ -15,6 +20,7 @@ import com.chaozhanggui.system.cashierservice.service.ShopPrintLogService;
|
||||
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
||||
import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -25,6 +31,14 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class FeiPrinter extends PrinterHandler {
|
||||
|
||||
@Resource
|
||||
private TbCallQueueMapper tbCallQueueMapper;
|
||||
@Resource
|
||||
private TbCallTableMapper tbCallTableMapper;
|
||||
|
||||
@Value("${wx.mini.page.call}")
|
||||
private String callPageUrl;
|
||||
|
||||
private final MPOrderInfoMapper mPOrderInfoMapper;
|
||||
private final MpShopInfoMapper mpShopInfoMapper;
|
||||
private final MPOrderDetailMapper mPOrderDetailMapper;
|
||||
@@ -93,6 +107,30 @@ public class FeiPrinter extends PrinterHandler {
|
||||
@Override
|
||||
protected void callNumPrint(TbPrintMachine machine, CallNumPrintDTO printDTO) {
|
||||
log.error("未实现打印方法");
|
||||
TbCallQueue queue = tbCallQueueMapper.selectById(printDTO.getCallQueueId());
|
||||
if (queue == null) {
|
||||
log.warn("叫号记录不存在");
|
||||
return;
|
||||
}
|
||||
|
||||
TbCallTable tbCallTable = tbCallTableMapper.selectById(queue.getCallTableId());
|
||||
TbShopInfo shopInfo = mpShopInfoMapper.selectById(queue.getShopId());
|
||||
CallNumPrintPO po = new CallNumPrintPO();
|
||||
po.setCallNum(queue.getCallNum());
|
||||
po.setShopName(shopInfo.getShopName());
|
||||
po.setTableName(tbCallTable.getName());
|
||||
po.setTableNote(tbCallTable.getNote());
|
||||
po.setPreNum(tbCallQueueMapper.selectCount(new LambdaQueryWrapper<TbCallQueue>()
|
||||
.eq(TbCallQueue::getShopId, queue.getShopId())
|
||||
.eq(TbCallQueue::getCallTableId, queue.getCallTableId())
|
||||
.lt(TbCallQueue::getId, queue.getId())
|
||||
.in(TbCallQueue::getState, 0, 1)).toString());
|
||||
po.setCallNum(queue.getCallNum());
|
||||
po.setCodeUrl(StrUtil.format(callPageUrl, queue.getShopId(), queue.getId()));
|
||||
po.setTakeTime(queue.getCreateTime());
|
||||
po.setShopNote(StrUtil.format("过号顺延{}桌 {}桌后需重新排号 谢谢理解!", tbCallTable.getPostponeNum(), tbCallTable.getPostponeNum()));
|
||||
String data = FeieyunPrintUtil.getCallNumPrintData(po);
|
||||
String resp = FeieyunPrintUtil.print("",machine.getAddress());
|
||||
shopPrintLogService.save(machine, "叫号单", data, resp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.chaozhanggui.system.cashierservice.entity.po.CallNumPrintPO;
|
||||
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
@@ -316,6 +317,46 @@ public class FeieyunPrintUtil {
|
||||
|
||||
}
|
||||
|
||||
public static String print(String content, String sn){
|
||||
// 通过POST请求,发送打印信息到服务器
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setSocketTimeout(30000)// 读取超时
|
||||
.setConnectTimeout(30000)// 连接超时
|
||||
.build();
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
|
||||
HttpPost post = new HttpPost(URL);
|
||||
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
||||
nvps.add(new BasicNameValuePair("user", USER));
|
||||
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
nvps.add(new BasicNameValuePair("stime", STIME));
|
||||
nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
|
||||
nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));// 固定值,不需要修改
|
||||
nvps.add(new BasicNameValuePair("sn", sn));
|
||||
nvps.add(new BasicNameValuePair("content", content));
|
||||
nvps.add(new BasicNameValuePair("times", "1"));// 打印联数
|
||||
|
||||
CloseableHttpResponse response = null;
|
||||
String result = null;
|
||||
try {
|
||||
post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
|
||||
response = httpClient.execute(post);
|
||||
int statecode = response.getStatusLine().getStatusCode();
|
||||
if (statecode == 200) {
|
||||
HttpEntity httpentity = response.getEntity();
|
||||
if (httpentity != null) {
|
||||
// 服务器返回的JSON字符串,建议要当做日志记录起来
|
||||
result = EntityUtils.toString(httpentity);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
close(response, post, httpClient);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static int getProducrName(String str) {
|
||||
int count = 0;
|
||||
@@ -337,6 +378,43 @@ public class FeieyunPrintUtil {
|
||||
return s;
|
||||
}
|
||||
|
||||
public static void close(CloseableHttpResponse response, HttpPost post, CloseableHttpClient httpClient) {
|
||||
try {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
post.abort();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCallNumPrintData(CallNumPrintPO po) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(StrUtil.format("<CB>{}</CB><BR>", po.getShopName()));
|
||||
sb.append("--------------------------------<BR>");
|
||||
sb.append(StrUtil.format("<CB>{} {}</CB><BR>",po.getTableName(),po.getCallNum()));
|
||||
sb.append(StrUtil.format("<C>前面有{}桌</C><BR>",po.getPreNum()));
|
||||
sb.append(StrUtil.format("<C><QR>{}</QR></C><BR>", po.getCodeUrl()));
|
||||
sb.append("<CB>怕过号扫一扫</CB><BR>");
|
||||
sb.append("--------------------------------<BR>");
|
||||
sb.append(po.getShopNote()+"<BR>");
|
||||
sb.append("--------------------------------<BR>");
|
||||
sb.append(StrUtil.format("取号时间:{}<BR>", DateUtils.getTime(po.getTakeTime())));
|
||||
sb.append(StrUtil.format("打印时间:{}<BR>", DateUtils.getTime(new Date())));
|
||||
sb.append("<CUT>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查飞鹅打印机是否在线
|
||||
*
|
||||
@@ -457,4 +535,6 @@ public class FeieyunPrintUtil {
|
||||
//失败 {"msg":"ok","ret":0,"data":false,"serverExecutedTime":4}
|
||||
System.out.println(UnicodeUtil.toString(resp));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user