店铺小票打印记录需求
This commit is contained in:
parent
ba710c854e
commit
ed2f5763ce
|
|
@ -10,11 +10,13 @@ import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
|
|||
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mybatis.MpShopInfoMapper;
|
||||
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.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -27,6 +29,9 @@ public class FeiPrinter extends PrinterHandler{
|
|||
private final MPOrderDetailMapper mPOrderDetailMapper;
|
||||
private final TbProductSkuMapper tbProductSkuMapper;
|
||||
|
||||
@Resource
|
||||
private ShopPrintLogService shopPrintLogService;
|
||||
|
||||
public FeiPrinter(TbProductMapper productMapper, TbProductSkuMapper tbProductSkuMapper, TbShopUserMapper tbShopUserMapper, MPOrderInfoMapper mPOrderInfoMapper, MpShopInfoMapper mpShopInfoMapper, MpShopInfoMapper mpShopInfoMapper1, MPOrderDetailMapper mPOrderDetailMapper) {
|
||||
super("fePrinter", productMapper, tbProductSkuMapper, tbShopUserMapper);
|
||||
this.mPOrderInfoMapper = mPOrderInfoMapper;
|
||||
|
|
@ -49,9 +54,9 @@ public class FeiPrinter extends PrinterHandler{
|
|||
return;
|
||||
}
|
||||
String remark = sku.getSpecSnap();
|
||||
FeieyunPrintUtil.getPrintData(machine.getAddress(), orderInfo.getMasterId(),
|
||||
String[] resp = FeieyunPrintUtil.getPrintData(machine.getAddress(), orderInfo.getMasterId(),
|
||||
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum(), remark);
|
||||
|
||||
shopPrintLogService.save(machine, "新订单", resp[0], resp[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -64,7 +69,8 @@ public class FeiPrinter extends PrinterHandler{
|
|||
(ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()),
|
||||
"0", detailList, orderInfo.getRemark(), null, null);
|
||||
String printType = "退款单";
|
||||
FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType);
|
||||
String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType);
|
||||
shopPrintLogService.save(machine, "退款单", resp[0], resp[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -77,7 +83,8 @@ public class FeiPrinter extends PrinterHandler{
|
|||
(ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()),
|
||||
"0", detailList, orderInfo.getRemark(), null, null);
|
||||
String printType = "结算单";
|
||||
FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType);
|
||||
String[] resp = FeieyunPrintUtil.getCashPrintData(detailPO, machine.getAddress(), printType, printType);
|
||||
shopPrintLogService.save(machine, "结算单", resp[0], resp[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
package com.chaozhanggui.system.cashierservice.rabbit.print;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
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.TbOrderDetail;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbProductSkuWithBLOBs;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
|
||||
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
|
||||
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderDetailMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mybatis.MPOrderInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mybatis.MpShopInfoMapper;
|
||||
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.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -24,6 +26,8 @@ public class LocalLabelPrinter extends PrinterHandler{
|
|||
|
||||
private final MPOrderDetailMapper mPOrderDetailMapper;
|
||||
private final TbProductSkuMapper tbProductSkuMapper;
|
||||
@Resource
|
||||
private ShopPrintLogService shopPrintLogService;
|
||||
|
||||
public LocalLabelPrinter(TbProductMapper productMapper, TbProductSkuMapper tbProductSkuMapper, TbShopUserMapper tbShopUserMapper, MPOrderDetailMapper mPOrderDetailMapper) {
|
||||
super("local", productMapper, tbProductSkuMapper, tbShopUserMapper);
|
||||
|
|
@ -44,8 +48,9 @@ public class LocalLabelPrinter extends PrinterHandler{
|
|||
return;
|
||||
}
|
||||
for (int i = 0; i < orderDetail.getNum(); i++) {
|
||||
FeieyunPrintUtil.printLabelMsg(machine.getAddress(), orderInfo.getTableName(), orderDetail.getProductName(),
|
||||
String[] resp = FeieyunPrintUtil.printLabelMsg(machine.getAddress(), orderInfo.getTableName(), orderDetail.getProductName(),
|
||||
1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), sku.getSalePrice().toPlainString(), sku.getSpecSnap());
|
||||
shopPrintLogService.save(machine, "新订单", resp[0], resp[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
|
|||
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachineLog;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ShopPrintLogDTO;
|
||||
import com.chaozhanggui.system.cashierservice.service.ShopPrintLogService;
|
||||
import com.chaozhanggui.system.cashierservice.util.FeieyunPrintUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.PrinterUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
|
@ -94,6 +95,7 @@ public class ShopPrintLogServiceImpl extends ServiceImpl<TbPrintMachineLogMapper
|
|||
int failFlag = 0;
|
||||
String respCode = "0";
|
||||
String respMsg = "打印中";
|
||||
|
||||
Map<Integer, String> yxxStatusMap = MapUtil.builder(0, "离线(设备上线后自动补打)").put(1, "在线").put(2, "获取失败").put(3, "未激活").put(4, "设备已禁用").build();
|
||||
// 云想印
|
||||
if ("yxyPrinter".equals(config.getContentType())) {
|
||||
|
|
@ -110,12 +112,26 @@ public class ShopPrintLogServiceImpl extends ServiceImpl<TbPrintMachineLogMapper
|
|||
failFlag = 1;
|
||||
respCode = code + "";
|
||||
|
||||
respMsg = status+"_"+yxxStatusMap.get(status);
|
||||
respMsg = status + "_" + yxxStatusMap.get(status);
|
||||
}
|
||||
if(code == 0){
|
||||
String taskId = resp.getJSONObject("data").getStr("orderId");
|
||||
entity.setTaskId(taskId);
|
||||
}
|
||||
String taskId = resp.getJSONObject("data").getStr("orderId");
|
||||
entity.setTaskId(taskId);
|
||||
} else {
|
||||
// 飞鹅云打印机暂时没有适配,先return不做打印记录
|
||||
}else if ("fePrinter".equals(config.getContentType())) {
|
||||
cn.hutool.json.JSONObject resp = JSONUtil.parseObj(respJson);
|
||||
int ret = resp.getInt("ret");
|
||||
if (ret != 0) {
|
||||
failFlag = 1;
|
||||
respCode = ret + "";
|
||||
respMsg = resp.getStr("msg");
|
||||
}else{
|
||||
String printOrderId = resp.getStr("data");
|
||||
entity.setTaskId(printOrderId);
|
||||
}
|
||||
} else {
|
||||
// 其他打印机暂时没有适配,先return不做打印记录
|
||||
return;
|
||||
}
|
||||
entity.setBizType(bizType);
|
||||
|
|
@ -168,6 +184,24 @@ public class ShopPrintLogServiceImpl extends ServiceImpl<TbPrintMachineLogMapper
|
|||
}
|
||||
super.updateById(entity);
|
||||
}
|
||||
// 飞鹅云打印机
|
||||
}else if("fePrinter".equals(config.getContentType())){
|
||||
ThreadUtil.safeSleep(1000*3);
|
||||
Boolean success = FeieyunPrintUtil.checkPrintStatus(entity.getTaskId());
|
||||
if(success == null){
|
||||
entity.setFailFlag(1);
|
||||
entity.setRespMsg("打印失败,未知错误");
|
||||
}else if(success) {
|
||||
entity.setFailFlag(0);
|
||||
entity.setPrintTime(new Date());
|
||||
entity.setRespMsg("打印成功");
|
||||
}else {
|
||||
String msg = FeieyunPrintUtil.checkOnline(entity.getAddress());
|
||||
entity.setFailFlag(1);
|
||||
entity.setPrintTime(null);
|
||||
entity.setRespMsg(StrUtil.concat(true,"打印失败,", "_", msg));
|
||||
}
|
||||
super.updateById(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
|
||||
import cn.hutool.core.text.UnicodeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
|
|
@ -16,9 +20,7 @@ import org.apache.http.message.BasicNameValuePair;
|
|||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class FeieyunPrintUtil {
|
||||
|
||||
|
|
@ -29,10 +31,9 @@ public class FeieyunPrintUtil {
|
|||
public static final String SN = "960238952";//*必填*:打印机编号,必须要在管理后台里添加打印机或调用API接口添加之后,才能调用API
|
||||
|
||||
|
||||
public static String[] printLabelMsg(String sn, String masterId, String productName, Integer number, String date, String money, String remark) {
|
||||
|
||||
public static String printLabelMsg(String sn,String masterId,String productName,Integer number,String date,String money,String remark){
|
||||
|
||||
StringBuffer sb=new StringBuffer();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("<DIRECTION>1</DIRECTION>");
|
||||
sb.append("<TEXT x='120' y='10' font='32*48' w='1' h='1' r='0'>");
|
||||
sb.append(masterId);
|
||||
|
|
@ -50,7 +51,7 @@ public class FeieyunPrintUtil {
|
|||
sb.append("¥");
|
||||
sb.append(money);
|
||||
|
||||
String content=sb.toString();
|
||||
String content = sb.toString();
|
||||
|
||||
//通过POST请求,发送打印信息到服务器
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
|
|
@ -64,37 +65,33 @@ public class FeieyunPrintUtil {
|
|||
|
||||
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_printLabelMsg"));//固定值,不需要修改
|
||||
nvps.add(new BasicNameValuePair("sn",sn));
|
||||
nvps.add(new BasicNameValuePair("content",content));
|
||||
nvps.add(new BasicNameValuePair("times","1"));//打印联数
|
||||
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_printLabelMsg"));//固定值,不需要修改
|
||||
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"));
|
||||
try {
|
||||
post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
|
||||
response = httpClient.execute(post);
|
||||
int statecode = response.getStatusLine().getStatusCode();
|
||||
if(statecode == 200){
|
||||
if (statecode == 200) {
|
||||
HttpEntity httpentity = response.getEntity();
|
||||
if (httpentity != null){
|
||||
if (httpentity != null) {
|
||||
//服务器返回的JSON字符串,建议要当做日志记录起来
|
||||
result = EntityUtils.toString(httpentity);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
} finally {
|
||||
try {
|
||||
if(response!=null){
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
@ -111,31 +108,32 @@ public class FeieyunPrintUtil {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return new String[]{content, result};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getPrintData(String sn,String pickupNumber,String date,String productName,Integer number,String remark) {
|
||||
public static String buildPrintContent(String pickupNumber, String date, String productName, Integer number, String remark) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("<CB>"+pickupNumber+"</CB><BR><BR>");
|
||||
builder.append("<L>时间: "+date+" </L><BR><BR><BR>");
|
||||
builder.append("<CB>" + pickupNumber + "</CB><BR><BR>");
|
||||
builder.append("<L>时间: " + date + " </L><BR><BR><BR>");
|
||||
|
||||
if(productName.length()>4||remark.length()>4){
|
||||
builder.append("<B><BOLD>"+productName+" "+number+"</BOLD></B><BR><BR>");
|
||||
builder.append("<B><BOLD>"+remark+" </BOLD></B><BR>");
|
||||
}else {
|
||||
builder.append("<B><BOLD>"+productName+" "+number+"</BOLD></B><BR><BR>");
|
||||
builder.append("<B><BOLD>"+remark+" </BOLD></B><BR>");
|
||||
if (productName.length() > 4 || remark.length() > 4) {
|
||||
builder.append("<B><BOLD>" + productName + " " + number + "</BOLD></B><BR><BR>");
|
||||
builder.append("<B><BOLD>" + remark + " </BOLD></B><BR>");
|
||||
} else {
|
||||
builder.append("<B><BOLD>" + productName + " " + number + "</BOLD></B><BR><BR>");
|
||||
builder.append("<B><BOLD>" + remark + " </BOLD></B><BR>");
|
||||
}
|
||||
|
||||
|
||||
builder.append("<BR><BR><BR><BR><BR><BR>");
|
||||
builder.append("<CUT>");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
String content=builder.toString();
|
||||
public static String[] getPrintData(String sn, String pickupNumber, String date, String productName, Integer number, String remark) {
|
||||
String content = buildPrintContent(pickupNumber, date, productName, number, remark);
|
||||
|
||||
System.out.println("content:".concat(content));
|
||||
|
||||
|
|
@ -151,38 +149,34 @@ public class FeieyunPrintUtil {
|
|||
|
||||
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"));//打印联数
|
||||
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"));
|
||||
try {
|
||||
post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
|
||||
response = httpClient.execute(post);
|
||||
int statecode = response.getStatusLine().getStatusCode();
|
||||
if(statecode == 200){
|
||||
if (statecode == 200) {
|
||||
HttpEntity httpentity = response.getEntity();
|
||||
if (httpentity != null){
|
||||
if (httpentity != null) {
|
||||
//服务器返回的JSON字符串,建议要当做日志记录起来
|
||||
result = EntityUtils.toString(httpentity);
|
||||
System.out.println("result:".concat(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
} finally {
|
||||
try {
|
||||
if(response!=null){
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
@ -199,78 +193,71 @@ public class FeieyunPrintUtil {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return new String[]{content, result};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static String getCashPrintData(OrderDetailPO detailPO,String sn, String type, String orderType){
|
||||
public static String[] getCashPrintData(OrderDetailPO detailPO, String sn, String type, String orderType) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<CB>"+detailPO.getMerchantName()+"</CB><BR><BR>");
|
||||
sb.append("<C><BOLD>"+type+"【"+detailPO.getMasterId()+"】</BOLD></C><BR><BR>");
|
||||
sb.append("订单号: "+detailPO.getOrderNo()+" <BR>");
|
||||
sb.append("交易时间: "+detailPO.getTradeDate()+" <BR>");
|
||||
sb.append("收银员: "+detailPO.getOperator()+" <BR><BR><BR>");
|
||||
sb.append("<CB>" + detailPO.getMerchantName() + "</CB><BR><BR>");
|
||||
sb.append("<C><BOLD>" + type + "【" + detailPO.getMasterId() + "】</BOLD></C><BR><BR>");
|
||||
sb.append("订单号: " + detailPO.getOrderNo() + " <BR>");
|
||||
sb.append("交易时间: " + detailPO.getTradeDate() + " <BR>");
|
||||
sb.append("收银员: " + detailPO.getOperator() + " <BR><BR><BR>");
|
||||
sb.append("------------------------<BR>");
|
||||
char paddingCharacter = ' ';
|
||||
sb.append("<S>"+String.format("%-15s","品名").replace(' ', paddingCharacter)+String.format("%-4s","数量").replace(' ', paddingCharacter)+String.format("%4s","小计").replace(' ', paddingCharacter)+"</S><BR>");
|
||||
sb.append("<S>" + String.format("%-15s", "品名").replace(' ', paddingCharacter) + String.format("%-4s", "数量").replace(' ', paddingCharacter) + String.format("%4s", "小计").replace(' ', paddingCharacter) + "</S><BR>");
|
||||
for (OrderDetailPO.Detail detail : detailPO.getDetailList()) {
|
||||
if(detail.getProductName().length()>4){
|
||||
if (detail.getProductName().length() > 4) {
|
||||
|
||||
int count=getProducrName(detail.getProductName());
|
||||
if(count<=0){
|
||||
int length=15-(detail.getProductName().length()-4);
|
||||
sb.append(""+String.format("%-"+length+"s",detail.getProductName()).replace(' ', paddingCharacter)+String.format("%-4s",detail.getNumber()).replace(' ', paddingCharacter)+String.format("%8s",detail.getAmount()).replace(' ', paddingCharacter)+"<BR>");
|
||||
}else {
|
||||
int length=15+count-(detail.getProductName().length()-4);
|
||||
sb.append(""+String.format("%-"+length+"s",detail.getProductName()).replace(' ', paddingCharacter)+String.format("%-4s",detail.getNumber()).replace(' ', paddingCharacter)+String.format("%8s",detail.getAmount()).replace(' ', paddingCharacter)+"<BR>");
|
||||
int count = getProducrName(detail.getProductName());
|
||||
if (count <= 0) {
|
||||
int length = 15 - (detail.getProductName().length() - 4);
|
||||
sb.append("" + String.format("%-" + length + "s", detail.getProductName()).replace(' ', paddingCharacter) + String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter) + String.format("%8s", detail.getAmount()).replace(' ', paddingCharacter) + "<BR>");
|
||||
} else {
|
||||
int length = 15 + count - (detail.getProductName().length() - 4);
|
||||
sb.append("" + String.format("%-" + length + "s", detail.getProductName()).replace(' ', paddingCharacter) + String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter) + String.format("%8s", detail.getAmount()).replace(' ', paddingCharacter) + "<BR>");
|
||||
}
|
||||
|
||||
}else {
|
||||
sb.append(""+String.format("%-15s",detail.getProductName()).replace(' ', paddingCharacter)+String.format("%-4s",detail.getNumber()).replace(' ', paddingCharacter)+String.format("%8s",detail.getAmount()).replace(' ', paddingCharacter)+"<BR>");
|
||||
} else {
|
||||
sb.append("" + String.format("%-15s", detail.getProductName()).replace(' ', paddingCharacter) + String.format("%-4s", detail.getNumber()).replace(' ', paddingCharacter) + String.format("%8s", detail.getAmount()).replace(' ', paddingCharacter) + "<BR>");
|
||||
}
|
||||
|
||||
if(detail.getSpec()!=null&& ObjectUtil.isNotEmpty(detail.getSpec())){
|
||||
sb.append("规格:"+detail.getSpec()+"<BR>");
|
||||
if (detail.getSpec() != null && ObjectUtil.isNotEmpty(detail.getSpec())) {
|
||||
sb.append("规格:" + detail.getSpec() + "<BR>");
|
||||
}
|
||||
|
||||
sb.append("<BR>");
|
||||
|
||||
}
|
||||
sb.append("------------------------<BR>");
|
||||
String t="¥"+detailPO.getReceiptsAmount();
|
||||
t=String.format("%11s",t).replace(' ', paddingCharacter);
|
||||
if(orderType.equals("return")){
|
||||
sb.append("<B>应退"+t+"</B><BR>");
|
||||
}else {
|
||||
sb.append("<B>应收"+t+"</B><BR>");
|
||||
String t = "¥" + detailPO.getReceiptsAmount();
|
||||
t = String.format("%11s", t).replace(' ', paddingCharacter);
|
||||
if (orderType.equals("return")) {
|
||||
sb.append("<B>应退" + t + "</B><BR>");
|
||||
} else {
|
||||
sb.append("<B>应收" + t + "</B><BR>");
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(detailPO.getPayType())&&ObjectUtil.isNotNull(detailPO.getPayType())&&detailPO.getPayType().equals("deposit")){
|
||||
sb.append("储值¥"+detailPO.getReceiptsAmount()+" <BR>");
|
||||
if (ObjectUtil.isNotEmpty(detailPO.getPayType()) && ObjectUtil.isNotNull(detailPO.getPayType()) && detailPO.getPayType().equals("deposit")) {
|
||||
sb.append("储值¥" + detailPO.getReceiptsAmount() + " <BR>");
|
||||
sb.append("------------------------<BR>");
|
||||
sb.append("积分:"+detailPO.getIntegral()+"<BR>");
|
||||
sb.append("积分:" + detailPO.getIntegral() + "<BR>");
|
||||
}
|
||||
|
||||
sb.append("余额:"+detailPO.getBalance()+"<BR>");
|
||||
sb.append("余额:" + detailPO.getBalance() + "<BR>");
|
||||
sb.append("------------------------<BR>");
|
||||
|
||||
if(ObjectUtil.isNotEmpty(detailPO.getRemark())&&ObjectUtil.isNotNull(detailPO.getRemark())){
|
||||
sb.append("<L>备注:"+detailPO.getRemark()+"</L><BR>");
|
||||
if (ObjectUtil.isNotEmpty(detailPO.getRemark()) && ObjectUtil.isNotNull(detailPO.getRemark())) {
|
||||
sb.append("<L>备注:" + detailPO.getRemark() + "</L><BR>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
sb.append("打印时间:"+DateUtils.getTime(new Date())+"<BR>");
|
||||
sb.append("打印时间:" + DateUtils.getTime(new Date()) + "<BR>");
|
||||
|
||||
sb.append("<CUT>");
|
||||
|
||||
String content=sb.toString();
|
||||
String content = sb.toString();
|
||||
|
||||
//通过POST请求,发送打印信息到服务器
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
|
|
@ -284,37 +271,33 @@ public class FeieyunPrintUtil {
|
|||
|
||||
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"));//打印联数
|
||||
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"));
|
||||
try {
|
||||
post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
|
||||
response = httpClient.execute(post);
|
||||
int statecode = response.getStatusLine().getStatusCode();
|
||||
if(statecode == 200){
|
||||
if (statecode == 200) {
|
||||
HttpEntity httpentity = response.getEntity();
|
||||
if (httpentity != null){
|
||||
if (httpentity != null) {
|
||||
//服务器返回的JSON字符串,建议要当做日志记录起来
|
||||
result = EntityUtils.toString(httpentity);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
} finally {
|
||||
try {
|
||||
if(response!=null){
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
@ -331,18 +314,16 @@ public class FeieyunPrintUtil {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return new String[]{content, result};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static int getProducrName(String str){
|
||||
public static int getProducrName(String str) {
|
||||
int count = 0;
|
||||
int digitCount=0;
|
||||
for (int i=0;i<str.length();i++){
|
||||
if ((str.charAt(i)>='a' && str.charAt(i)<='z') || (str.charAt(i)>='A' && str.charAt(i)<='Z')){
|
||||
int digitCount = 0;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if ((str.charAt(i) >= 'a' && str.charAt(i) <= 'z') || (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z')) {
|
||||
count++;
|
||||
}
|
||||
|
||||
|
|
@ -350,20 +331,130 @@ public class FeieyunPrintUtil {
|
|||
digitCount++;
|
||||
}
|
||||
}
|
||||
return count+digitCount;
|
||||
return count + digitCount;
|
||||
}
|
||||
|
||||
private static String signature(String USER,String UKEY,String STIME){
|
||||
String s = DigestUtils.sha1Hex(USER+UKEY+STIME);
|
||||
private static String signature(String USER, String UKEY, String STIME) {
|
||||
String s = DigestUtils.sha1Hex(USER + UKEY + STIME);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查飞鹅打印机是否在线
|
||||
* @param sn 设备编号
|
||||
* @return 在线,工作状态正常。/离线。/未知错误
|
||||
*/
|
||||
public static String checkOnline(String sn){
|
||||
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("user", USER);
|
||||
paramMap.put("stime", STIME);
|
||||
paramMap.put("sig", signature(USER, UKEY, STIME));
|
||||
paramMap.put("apiname", "Open_queryPrinterStatus");
|
||||
paramMap.put("sn", sn);
|
||||
String msg;
|
||||
try {
|
||||
String resp = HttpUtil.post(URL, paramMap, 1000 * 5);
|
||||
//成功 开机 {"msg":"ok","ret":0,"data":"在线,工作状态正常。","serverExecutedTime":4}
|
||||
//成功 离线 {"msg":"ok","ret":0,"data":"离线。","serverExecutedTime":7}
|
||||
JSONObject json = JSONUtil.parseObj(UnicodeUtil.toString(resp));
|
||||
msg = json.getStr("data");
|
||||
}catch (Exception e){
|
||||
msg = "未知错误";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
// OrderDetailPO detailPO=new OrderDetailPO("牛叉闪闪",null,null,"DD20240312142156962",null,null,null,null,null,null,null,null);
|
||||
// getCashPrintData(detailPO,"922690786","结算单",null);
|
||||
/**
|
||||
* 检查飞鹅打印机打印任务是否已打印
|
||||
* @param printOrderId 打印订单编号
|
||||
* @return null-未知错误,true-已打印,false-未打印
|
||||
*/
|
||||
public static Boolean checkPrintStatus(String printOrderId){
|
||||
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("user", USER);
|
||||
paramMap.put("stime", STIME);
|
||||
paramMap.put("sig", signature(USER, UKEY, STIME));
|
||||
paramMap.put("apiname", "Open_queryOrderState");
|
||||
paramMap.put("orderid", printOrderId);
|
||||
Boolean ret;
|
||||
try {
|
||||
String resp = HttpUtil.post(URL, paramMap, 1000 * 5);
|
||||
//成功 {"msg":"ok","ret":0,"data":true,"serverExecutedTime":4}
|
||||
//失败 {"msg":"ok","ret":0,"data":false,"serverExecutedTime":4}
|
||||
JSONObject json = JSONUtil.parseObj(UnicodeUtil.toString(resp));
|
||||
ret = json.getBool("data");
|
||||
}catch (Exception e){
|
||||
ret = null;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
//testPrint();
|
||||
//testPrint2();
|
||||
testPrint3();
|
||||
}
|
||||
|
||||
public static void testPrint(){
|
||||
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽");
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
// 参考文档:https://help.feieyun.com/home/doc/zh;nav=0-2
|
||||
paramMap.put("user", USER);
|
||||
paramMap.put("stime", STIME);
|
||||
paramMap.put("sig", signature("chaozhanggui2022@163.com", "UfWkhXxSkeSSscsU", STIME));
|
||||
paramMap.put("apiname", "Open_printMsg");
|
||||
paramMap.put("sn", "922690786");
|
||||
paramMap.put("content", content);
|
||||
paramMap.put("times", 1);
|
||||
//paramMap.put("debug", "1");
|
||||
String resp = HttpUtil.post(URL, paramMap, 1000 * 5);
|
||||
//成功 开机和关机都会响应成功,只是打印任务已正确下发,不代表打印成功
|
||||
//{"msg":"ok","ret":0,"data":"922690786_20241010174146_2050070451","serverExecutedTime":4} data是打印订单id
|
||||
//失败1 {"msg":"参数错误 : 该帐号未注册.","ret":-2,"data":null,"serverExecutedTime":37}
|
||||
System.out.println(UnicodeUtil.toString(resp));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询打印机状态
|
||||
*/
|
||||
public static void testPrint2(){
|
||||
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽");
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
// 参考文档:https://help.feieyun.com/home/doc/zh;nav=0-2
|
||||
paramMap.put("user", USER);
|
||||
paramMap.put("stime", STIME);
|
||||
paramMap.put("sig", signature("chaozhanggui2022@163.com", "UfWkhXxSkeSSscsU", STIME));
|
||||
paramMap.put("apiname", "Open_queryPrinterStatus");
|
||||
paramMap.put("sn", "922690786");
|
||||
//paramMap.put("debug", "1");
|
||||
String resp = HttpUtil.post(URL, paramMap, 1000 * 5);
|
||||
//成功 开机 {"msg":"ok","ret":0,"data":"在线,工作状态正常。","serverExecutedTime":4}
|
||||
//成功 离线 {"msg":"ok","ret":0,"data":"离线。","serverExecutedTime":7}
|
||||
System.out.println(UnicodeUtil.toString(resp));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询打印任务是否打印成功
|
||||
*/
|
||||
public static void testPrint3(){
|
||||
String STIME = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
String content = buildPrintContent("123456789", "2024-10-10 18:11:11", "澳洲大龙虾", 1, "一只吃爽爽");
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
// 参考文档:https://help.feieyun.com/home/doc/zh;nav=0-2
|
||||
paramMap.put("user", USER);
|
||||
paramMap.put("stime", STIME);
|
||||
paramMap.put("sig", signature("chaozhanggui2022@163.com", "UfWkhXxSkeSSscsU", STIME));
|
||||
paramMap.put("apiname", "Open_queryOrderState");
|
||||
paramMap.put("orderid", "922690786_20241010175946_1576957351x");
|
||||
//paramMap.put("debug", "1");
|
||||
String resp = HttpUtil.post(URL, paramMap, 1000 * 5);
|
||||
//成功 {"msg":"ok","ret":0,"data":true,"serverExecutedTime":4}
|
||||
//失败 {"msg":"ok","ret":0,"data":false,"serverExecutedTime":4}
|
||||
System.out.println(UnicodeUtil.toString(resp));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue