Commit 4c7cb82d by xiaoqing.gu

外卖 自提 后厨打印模板调试完成

parent e041f27d
......@@ -11,7 +11,9 @@
#include "preDefine.h"
#include "calculator.h"
#include "model/posorderpool.h"
#include <QJsonDocument>
#include <QJsonArray>
NewPrintLib::NewPrintLib()
{
......@@ -168,13 +170,28 @@ void NewPrintLib::PrintProcudt(const QList<LineNode*> &list,const QList<int>& pr
}
}
#define ORDERINFOCOPY(src, des) do { \
des.create_time = src->create_time; \
des.order_index = src->order_index; \
des.order_id = src->order_id; \
des.store_name = src->store_name; \
#define ORDERINFOCOPY(src, des) do { \
des.create_time = src->create_time; \
des.order_index = src->order_index; \
des.order_id = src->order_id; \
des.store_name = src->store_name; \
des._orderObject = src->_orderObject; \
des._orderObject["products"] = QJsonArray();\
}while(0);
void NewPrintLib::AddProdJson(OrderObject &des_order, ProductObject* prod)
{
QJsonArray array = des_order._orderObject["products"].toArray();
QJsonObject object;
object["pid"] = prod->pid;
object["price"] = prod->price;
object["name"] = prod->name;
object["product_amount"] = prod->product_amount;
array.append(object);
des_order._orderObject["products"] = array;
}
bool NewPrintLib::GetObjList(int page_depart, int prod_depart, QStringList prodlist, QList<OrderObject> &orderlist, OrderObject *order)
{
OrderObject allorder;
......@@ -192,12 +209,15 @@ bool NewPrintLib::GetObjList(int page_depart, int prod_depart, QStringList prodl
ProductObject *tmpod = new ProductObject(&tmporder);
*tmpod = *v;
tmporder.proList.append(tmpod);
AddProdJson(tmporder, tmpod);
QLOG_DEBUG() << "debug2" << tmporder._orderObject;
orderlist.append(tmporder);
}
else
{
OrderObject tmporder;
ORDERINFOCOPY(order, tmporder);
QLOG_DEBUG() << "222222" << tmporder._orderObject;
for(int i = 0; i < v->product_amount; ++i)
{
......@@ -205,7 +225,8 @@ bool NewPrintLib::GetObjList(int page_depart, int prod_depart, QStringList prodl
*tmpod = *v;
tmpod->product_amount = 1;
tmporder.proList.append(tmpod);
AddProdJson(tmporder, tmpod);
QLOG_DEBUG() << "debug3" << tmporder._orderObject;
}
orderlist.append(tmporder);
}
......@@ -217,6 +238,8 @@ bool NewPrintLib::GetObjList(int page_depart, int prod_depart, QStringList prodl
ProductObject *tmpod = new ProductObject(&allorder);
*tmpod = *v;
allorder.proList.append(tmpod);
AddProdJson(allorder, tmpod);
QLOG_DEBUG() << "debug4" << allorder._orderObject;
}
else
{
......@@ -227,6 +250,8 @@ bool NewPrintLib::GetObjList(int page_depart, int prod_depart, QStringList prodl
*tmpod = *v;
tmpod->product_amount = 1;
allorder.proList.append(tmpod);
AddProdJson(allorder, tmpod);
QLOG_DEBUG() << "debug5" << allorder._orderObject;
}
}
}
......@@ -260,17 +285,47 @@ bool NewPrintLib::DoPrint(const QString &config, const QString &context, OrderOb
CONSTCHARTOCHAR(prtconfigdata, prtconfig);
char *xml = NULL;
QByteArray xmldata = context.toUtf8();
// QByteArray xmldata = context.toUtf8();
QByteArray xmldata = context.toLocal8Bit();
CONSTCHARTOCHAR(xmldata, xml);
char *orderinfo = NULL;
QByteArray orderdata = QString(QJsonDocument(tmporder._orderObject).toJson()).toUtf8();
// QByteArray orderdata = QString(QJsonDocument(tmporder._orderObject).toJson()).toUtf8();
//根据订单号填写打印模板的表头
QJsonObject orderObj = tmporder._orderObject;
int type = -100;
if(orderObj.contains("order_type")) {
type = orderObj["order_type"].toInt();
}
QLOG_DEBUG() << "NewPrintLib::type:" << type;
switch(type) {
case TimelyTakeout:
tmporder._orderObject.insert("source_order_type" , QString::fromLocal8Bit(ORDER_TYPE_TIMELYTAKEOUT));
break;
case AppointmentTakeout:
tmporder._orderObject.insert("source_order_type" , QString::fromLocal8Bit(ORDER_TYPE_APPOINTMENTTAKEOUT));
break;
case TimelyInvite:
tmporder._orderObject.insert("source_order_type" , QString::fromLocal8Bit(ORDER_TYPE_TIMELYINVITE));
break;
case AppointmentInvite:
tmporder._orderObject.insert("source_order_type" , QString::fromLocal8Bit(ORDER_TYPE_APPOINTMENTTAKEOUT));
break;
default:
break;
}
QByteArray orderdata = QString(QJsonDocument(tmporder._orderObject).toJson()).toLocal8Bit();
CONSTCHARTOCHAR(orderdata, orderinfo);
char err[1024] = {0};
f_DoPrintWithXml(prtconfig, xml, orderinfo, err);
f_DoPrintWithXml(prtconfig, orderinfo, xml, err);
if(strlen(err) > 0)
{
......@@ -394,15 +449,18 @@ bool NewPrintLib::PrintLabel(const QString &config, OrderObject *order)
{
if(order->order_type == 3 || order->order_type == 4 || order->order_type == 5)
{
tmptitle = QString("\xE9\x9D\x9E\xE7\xA0\x81\xE8\x87\xAA\xE6\x8F\x90").append(order->code).append(" ").append(title);
// tmptitle = QString("\xE9\x9D\x9E\xE7\xA0\x81\xE8\x87\xAA\xE6\x8F\x90").append(order->code).append(" ").append(title);
tmptitle = QString("\xE8\x87\xAA\xE6\x8F\x90").append(order->code).append(" ").append(title);
}
else if(order->order_type == 6)
{
tmptitle = QString("\xE9\x9D\x9E\xE7\xA0\x81\xE9\xA2\x84\xE7\xBA\xA6").append(order->code).append(" ").append(title);
// tmptitle = QString("\xE9\x9D\x9E\xE7\xA0\x81\xE9\xA2\x84\xE7\xBA\xA6").append(order->code).append(" ").append(title);
tmptitle = QString("\xE9\xA2\x84\xE7\xBA\xA6").append(order->code).append(" ").append(title);
}
else
{
tmptitle = QString("\xE9\x9D\x9E\xE7\xA0\x81\xE5\xA4\x96\xE5\x8D\x96").append(QString::number(order->order_index)).append(" ").append(title);
// tmptitle = QString("\xE9\x9D\x9E\xE7\xA0\x81\xE5\xA4\x96\xE5\x8D\x96").append(QString::number(order->order_index)).append(" ").append(title);
tmptitle = QString("\xE5\xA4\x96\xE5\x8D\x96").append(QString::number(order->order_index)).append(" ").append(title);
}
}
else
......@@ -472,6 +530,8 @@ bool NewPrintLib::DoBackPrint(int page_depart, int prod_depart, int page_num, co
return true;
}
QLOG_DEBUG() << "NewPrintLib::list:" <<list;
QList<OrderObject> orderlist;
if(GetObjList(page_depart, prod_depart, list, orderlist, order) == false)
......@@ -481,6 +541,7 @@ bool NewPrintLib::DoBackPrint(int page_depart, int prod_depart, int page_num, co
return true;
}
int i = 0; //打印的页数
while( i < page_num)
......@@ -489,36 +550,95 @@ bool NewPrintLib::DoBackPrint(int page_depart, int prod_depart, int page_num, co
while(index < orderlist.size())
{
QByteArray data = config.toUtf8();
// QByteArray data = config.toUtf8();
char *tmpconfig = NULL;
// char *tmpconfig = NULL;
CONSTCHARTOCHAR(data, tmpconfig);
// CONSTCHARTOCHAR(data, tmpconfig);
if(f_prtopen(tmpconfig) != 1)
{
QLOG_ERROR() << "NewPrintLib::DoPrint::f_prtopen failed";
delete [] tmpconfig;
f_prtclose();
return false;
// if(f_prtopen(tmpconfig) != 1)
// {
// QLOG_ERROR() << "NewPrintLib::DoPrint::f_prtopen failed";
// delete [] tmpconfig;
// f_prtclose();
// return false;
// }
// delete [] tmpconfig;
// bool result;
// QString error;
// PrintDocument doc = PrintDocument::ParseToDocument(context, result, error);
// if(!result)
// {
// f_prtclose();
// QLOG_ERROR() << "NewPrintLib::DoPrint::PrintDocument::ParseToDocument failed";
// return false;
// }
// OrderObject tmporder = orderlist[index];
// PrintLineNode(doc, &tmporder);
// f_prtclose();
OrderObject tmporder = orderlist[index];
QLOG_DEBUG() << "input2:" << tmporder._orderObject;
char *prtconfig = NULL;
QByteArray prtconfigdata = config.toUtf8();
CONSTCHARTOCHAR(prtconfigdata, prtconfig);
char *xml = NULL;
QByteArray xmldata = context.toLocal8Bit();
CONSTCHARTOCHAR(xmldata, xml);
char *orderinfo = NULL;
QJsonObject orderObj = tmporder._orderObject;
int type = -100;
if(orderObj.contains("order_type")) {
type = orderObj["order_type"].toInt();
}
delete [] tmpconfig;
bool result;
QString error;
PrintDocument doc = PrintDocument::ParseToDocument(context, result, error);
if(!result)
{
f_prtclose();
QLOG_ERROR() << "NewPrintLib::DoPrint::PrintDocument::ParseToDocument failed";
return false;
QLOG_DEBUG() << "NewPrintLib::type:" << type;
switch(type) {
case TimelyTakeout:
tmporder._orderObject.insert("source_order_type" , QString::fromLocal8Bit(ORDER_TYPE_TIMELYTAKEOUT));
break;
case AppointmentTakeout:
tmporder._orderObject.insert("source_order_type" , QString::fromLocal8Bit(ORDER_TYPE_APPOINTMENTTAKEOUT));
break;
case TimelyInvite:
tmporder._orderObject.insert("source_order_type" , QString::fromLocal8Bit(ORDER_TYPE_TIMELYINVITE));
break;
case AppointmentInvite:
tmporder._orderObject.insert("source_order_type" , QString::fromLocal8Bit(ORDER_TYPE_APPOINTMENTTAKEOUT));
break;
default:
break;
}
OrderObject tmporder = orderlist[index];
QByteArray orderdata = QString(QJsonDocument(tmporder._orderObject).toJson()).toLocal8Bit();
CONSTCHARTOCHAR(orderdata, orderinfo);
char err[1024] = {0};
f_DoPrintWithXml(prtconfig, orderinfo, xml, err);
if(strlen(err) > 0)
{
QLOG_ERROR() << "f_DoPrintWithXml failed error : " << err;
}
PrintLineNode(doc, &tmporder);
QLOG_DEBUG() << "f_DoPrintWithXml success";
f_prtclose();
Sleep(200);
......
......@@ -77,6 +77,8 @@ private:
void PrintProcudt(const QList<LineNode *> &list, const QList<int> &protlist, OrderObject *_order);
void AddProdJson(OrderObject &des_order, ProductObject* prod);
bool GetObjList(int page_depart, int prod_depart, QStringList prodlist, QList<OrderObject> &orderlist, OrderObject *order);
bool GetProdObject(int prod_depart, QList<OrderObject> &orderlist, OrderObject *order);
......
......@@ -116,7 +116,7 @@ bool orderprintwork::GetPrtTemplet(int prttype, int pagew, QString &context, con
}
else if(order.order_type == 6)
{
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINTYY80_TEMPLET);
file.setFileName(qApp->applicationDirPath() + "/" + XML_YYINTAKE80_TEMPLATE);
}
else
{
......@@ -145,7 +145,7 @@ bool orderprintwork::GetPrtTemplet(int prttype, int pagew, QString &context, con
}
else if(order.order_type == 6)
{
file.setFileName(qApp->applicationDirPath() + "/" + FILE_PRINTYY_TEMPLET);
file.setFileName(qApp->applicationDirPath() + "/" + XML_YYINTAKE56_TEMPLATE);
}
else
{
......
......@@ -5,9 +5,10 @@
#include "base/DB/fm_database.h"
#include "QsLog.h"
#include <QJsonArray>
#include <QtXml/QDomDocument>
#include <QDomDocument>
#include <QApplication>
#include <QDir>
#include <Windows.h>
prtModelGetWork::prtModelGetWork(WorkObject *parent) : WorkObject(parent)
{
......@@ -169,7 +170,11 @@ bool prtModelGetWork::CheckPrtModelInfo(QJsonObject &json)
for(int i = 0;i != array.size(); ++i) {
if(array.at(i).toObject().contains("template") && array.at(i).toObject().contains("print_type")) {
if(array.at(i).toObject()["template"].toString() != 0) {
_templateMap.insert(array.at(i).toObject()["print_type"].toInt(), array.at(i).toObject()["template"].toString());
QString str = array.at(i).toObject()["template"].toString();
QLOG_DEBUG() << array.at(i).toObject()["print_type"].toInt();
if(praseXmlPrtModel(str)) {
_templateMap.insert(array.at(i).toObject()["print_type"].toInt(), array.at(i).toObject()["template"].toString());
}
}
} else {
return false;
......@@ -195,16 +200,7 @@ bool prtModelGetWork::CheckPrtModelInfo(QJsonObject &json)
prtModelLocalize();
logoImageLocalize();
// for(int i = 0;i != _templateList.size(); ++i) {
// QFile file(QApplication::applicationDirPath() + "/prtinfo/1.xml");
// if(file.open(QIODevice::ReadWrite)) {
// qDebug() << "--------------------4040-----------------" << _templateList.at(i) << QString(_templateList.at(i)).toUtf8();
// file.write(QString(_templateList.at(i)).toUtf8());
// file.close();
// return true;
// }
// }
qrCodeImageLocalize();
return true;
}
......@@ -212,19 +208,18 @@ bool prtModelGetWork::CheckPrtModelInfo(QJsonObject &json)
bool prtModelGetWork::prtModelLocalize()
{
qDebug() << "-------------------------------4040---------------------" << _templateMap;
// 检查目录是否存在,若不存在则新建
QString dir_str = QApplication::applicationDirPath() + QString("/prtinfo");
QDir dir;
if (!dir.exists(dir_str))
{
bool res = dir.mkpath(dir_str);
qDebug() << "新建目录是否成功" << res;
}
QMap<int, QString>::iterator it;
for(it = _templateMap.begin(); it != _templateMap.end(); ++it) {
QString dir_str = QApplication::applicationDirPath() + QString("/prtinfo");
// 检查目录是否存在,若不存在则新建
QDir dir;
if (!dir.exists(dir_str))
{
bool res = dir.mkpath(dir_str);
qDebug() << "新建目录是否成功" << res;
}
QFile file(QApplication::applicationDirPath() + QString("/prtinfo/%1.xml").arg(it.key()));
if(file.open(QIODevice::ReadWrite)) {
if(file.open(QFile::WriteOnly|QFile::Truncate)) {
file.write(QString(it.value()).toUtf8());
file.close();
} else {
......@@ -243,11 +238,24 @@ bool prtModelGetWork::logoImageLocalize()
}
QMap<int, QString>::iterator it;
for(it = _logoMap.begin(); it != _logoMap.end(); ++it) {
downloadImage(it.value(), QApplication::applicationDirPath() + QString("/prtinfo/%1.png").arg(it.key()));
downloadImage(it.value(), QApplication::applicationDirPath() + QString("/prtinfo/%1.bmp").arg(it.key()));
}
//将图片二值化
// img_rgb2gray();
return true;
}
bool prtModelGetWork::qrCodeImageLocalize()
{
if(_qrCodeMap.size() == 0)
{
return false;
}
QMap<int, QString>::iterator it;
for(it = _qrCodeMap.begin(); it != _qrCodeMap.end(); ++it) {
downloadImage(it.value(), QApplication::applicationDirPath() + QString("/prtinfo/%1p.bmp").arg(it.key()));
}
// downloadImage("https://picture.sandload.cn/1551195158116.png", QApplication::applicationDirPath()+"/prtinfo/1.bmp");
// Downloader downloader;
// downloader.downloadFileFromURL("https://picture.sandload.cn/1551195158116.png", QApplication::applicationDirPath()+"/prtinfo");
return true;
}
......@@ -280,7 +288,7 @@ bool prtModelGetWork::downloadImage(QString url, QString fileName)
reply->deleteLater();
QFile file(fileName);
if(!file.open(QIODevice::WriteOnly))
if(!file.open(QFile::WriteOnly|QFile::Truncate))
return false;
file.write(reply->readAll());
file.close();
......@@ -288,4 +296,91 @@ bool prtModelGetWork::downloadImage(QString url, QString fileName)
return true;
}
bool prtModelGetWork::praseXmlPrtModel(QString str)
{
QDomDocument doc;
QString errorMsg;
int errorLine;
int errorColumn;
if(!doc.setContent(str, &errorMsg, &errorLine, &errorColumn)) {
QLOG_ERROR() << "xml prtmodel prase failed!" << errorMsg;
return false;
}
return true;
}
void prtModelGetWork::img_rgb2gray()
{
int threshold=200;
FILE* stream=fopen("D:\\6.bmp","rb");
if(stream==NULL)
{
QLOG_ERROR() << "FILE didn't exist!";
return;
}
int sizeFileHeader=sizeof(BITMAPFILEHEADER);
int sizeInfoHeader=sizeof(BITMAPINFOHEADER);
BITMAPFILEHEADER* bitmapFileHeader=new BITMAPFILEHEADER[sizeFileHeader+1];
BITMAPINFOHEADER* bitmapInfoHeader=new BITMAPINFOHEADER[sizeInfoHeader+1];
memset(bitmapFileHeader,0,sizeFileHeader+1);
memset(bitmapInfoHeader,0,sizeInfoHeader+1);
fread(bitmapFileHeader,sizeof(char),sizeFileHeader,stream);
fseek(stream,sizeFileHeader,0);
fread(bitmapInfoHeader,sizeof(char),sizeInfoHeader,stream);
fseek(stream,sizeInfoHeader+sizeFileHeader,0);
RGBQUAD* pRgbQuards=new RGBQUAD[256];
for (int k=0;k<256;k++)
{
fread(&pRgbQuards[k],sizeof(RGBQUAD),1,stream);
}
int count=(((bitmapInfoHeader->biWidth)*8+31)/32)*4-bitmapInfoHeader->biWidth*(bitmapInfoHeader->biBitCount/8);
BYTE* tempData=new BYTE[count+1];
memset(tempData,0,count+1);
fseek(stream,sizeFileHeader+sizeInfoHeader+256*sizeof(RGBQUAD),0);
BYTE** data=new BYTE*[bitmapInfoHeader->biHeight];
for(int i=0;i<bitmapInfoHeader->biHeight;i++)
{
data[i]=new BYTE[bitmapInfoHeader->biWidth];
for (int j=0;j<bitmapInfoHeader->biWidth;j++)
{
fread(&data[i][j],sizeof(char),1,stream);
if(data[i][j]>threshold)
data[i][j]=255;
else
data[i][j]=0;
}
for (int n=0;n<count;n++)
{
fread(&tempData[n],sizeof(char),1,stream);
}
}
fclose(stream);
//写入。。
FILE* fileWrite=fopen("D:\\9.bmp","a+");
fwrite(bitmapFileHeader,sizeof(char),sizeof(BITMAPFILEHEADER),fileWrite);
fwrite(bitmapInfoHeader,sizeof(char),sizeof(BITMAPINFOHEADER),fileWrite);
fwrite(pRgbQuards,sizeof(RGBQUAD),256,fileWrite);
for(int i=0;i<bitmapInfoHeader->biHeight;i++)
{
for(int j=0;j<bitmapInfoHeader->biWidth;j++)
{
fwrite(&data[i][j],sizeof(BYTE),1,fileWrite);
}
for(int m=0;m<count;m++)
fwrite(&tempData[m],sizeof(char),1,fileWrite);
}
fclose(fileWrite);
}
......@@ -42,8 +42,14 @@ private:
bool logoImageLocalize();
bool qrCodeImageLocalize();
bool downloadImage(QString url, QString fileName);
bool praseXmlPrtModel(QString str);
void img_rgb2gray();
private:
QVariantMap _storeinfo;
......@@ -70,7 +76,7 @@ private:
switch (REQ)
{
case ADVANCEORDER:
action = QString("saas.printFile.query");
action = QString("saas.ticketSet.query");
return true;
default:
return false;
......@@ -79,7 +85,7 @@ private:
switch (REQ)
{
case ADVANCEORDER:
action = QString("saas.ticketSet.query");
action = QString("qasaas.ticketSet.query");
return true;
default:
return false;
......
......@@ -260,6 +260,12 @@
#define OPERATIONNAME_AGREE "同意"
#define OPERATIONNAME_REFUNDNEWORDER "拒绝接单"
//订单类型汉化
#define ORDER_TYPE_TIMELYTAKEOUT "小程序外卖"
#define ORDER_TYPE_TIMELYINVITE "小程序自提"
#define ORDER_TYPE_APPOINTMENTTAKEOUT "小程序预约"
#define REJECTUITYPE_REFUSEREFUND 0
#define REJECTUITYPE_AGREEREFUND 1
#define REJECTUITYPE_REFUSEORDER 2
......@@ -316,12 +322,15 @@
#define FILE_BACKPRINT_TEMPLET "backtemplet.txt"
#define FILE_BACKPRINT80_TEMPLET "backtemplet80.txt"
#define XML_TAKEOUT56_TEMPLATE "prtinfo/1.xml"
#define XML_INTAKE56_TEMPLATE "prtinfo/2.xml"
#define XML_LABEL_TEMPLATE "prtinfo/3.xml"
#define XML_BACK_TEMPLATE "prtinfo/4.xml"
#define XML_TAKEOUT80_TEMPLATE "prtinfo/5.xml"
#define XML_INTAKE80_TEMPLATE "prtinfo/6.xml"
#define XML_TAKEOUT56_TEMPLATE "prtinfo/1.xml" //外卖小票56
#define XML_INTAKE56_TEMPLATE "prtinfo/2.xml" //到店取餐56
#define XML_LABEL_TEMPLATE "prtinfo/3.xml" //杯贴
#define XML_BACK_TEMPLATE "prtinfo/4.xml" //厨打56
#define XML_TAKEOUT80_TEMPLATE "prtinfo/1.xml" //外卖小票80
#define XML_INTAKE80_TEMPLATE "prtinfo/2.xml" //到店取餐80
#define XML_YYINTAKE56_TEMPLATE "prtinfo/7.xml" //预约到店56
#define XML_YYINTAKE80_TEMPLATE "prtinfo/8.xml" //预约到店80
#define XML_BACK80_TEMPLATE "prtinfo/9.xml" //厨打80
#define DEFAULT_PRINTF_MAIN_SESSION "Printer"
......
......@@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT += core gui network multimedia sql printsupport
QT += core gui network multimedia sql printsupport xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
......@@ -21,7 +21,7 @@ LIBS += -L$$PWD/lib -llibeay32 -lssleay32 -lwinspool
LIBS += -lWs2_32
LIBS += -lDbghelp
DEFINES += USE_QAACTION
#DEFINES += USE_QAACTION
DEFINES += FM_NEW_UI
#DEFINES += FM_TEST
......
......@@ -1660,6 +1660,13 @@ void NewMainForm::on_newmainbtn_prttest_clicked()
prod3->product_amount = 1;
prod3->property_tags = QString::fromUtf8("\xE5\x8A\xA0\xE5\x8D\xA4\xE8\x9B\x8B");
QJsonObject json;
json.insert("order_id","888888");
json.insert("code", "12");
json.insert("customer", QString::fromUtf8("\xE6\x96\xB9\xE4\xBE\xBF\xE9\x9D\xA2"));
order._orderObject = json;
order.proList.append(prod3);
QStringList list;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment