| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- #include "autopackutils.h"
- /**
- * @brief AutoPackForm工具类
- */
- AutoPackUtils::AutoPackUtils()
- {
- connect(&_request,&HttpRequest::result,this,&AutoPackUtils::httpResult);
- }
- /**
- * @brief 把打包数据存入本地数据库后,上传服务器打包数据
- * @param info
- */
- void AutoPackUtils::doSend(QSharedPointer<PackInfo> &info)
- {
- if(info.isNull()) return;
- //把数据添加到数据库里
- insertProductSQL(info);
- //TODO:发送码单 packinfo 数据, 转换为 json数据发送
- QJsonObject json = toJson(info);
- _request.setUserToken(QString::number(GlobalInfo::this_()->user().accountId),GlobalInfo::this_()->user().acessToken);
- // qDebug()<<QString::number(GlobalInfo::this_()->user().accountId);
- // qDebug()<<GlobalInfo::this_()->user().acessToken;
- // _request.post(GlobalInfo::this_()->config().autoPackUrl,json);
- // qDebug()<<json;
- } // http://doc.vanlai.net:3001/web/#/1?page_id=64
- void AutoPackUtils::httpResult(int emitcode, const QJsonObject body)
- {
- qDebug()<<emitcode;
- qDebug()<<body;
- if(emitcode==200&&body["product_id"].toInt()!=0){
- database.changeState(codeSingle);
- }
- }
- //把BoxInfo数据添加到deetails数据库里;
- void AutoPackUtils::insertDetailsSQL(QSharedPointer<BoxInfo> boxes,QString codeSingle)
- {
- // qDebug()<<boxes->caseNumber();
- detailsData.code_single = codeSingle;
- detailsData.case_number = boxes->caseNumber();
- detailsData.box_weight = boxes->box_weight;
- detailsData.tube_number = boxes->tube_number;
- detailsData.bucket_weight = boxes->bucket_weight;
- detailsData.gross_weight = boxes->gross_weight;
- detailsData.net_weight = boxes->net_weight;
- detailsData.sort = boxes->sort;
- detailsData.remark = boxes->remark;
- if(database.insertDetails(detailsData)){
- qDebug()<<"details数据库添加成功";
- return;
- }
- qDebug()<<"details数据库添加失败";
- }
- //把PackInfo添加到product数据库里;
- void AutoPackUtils::insertProductSQL(QSharedPointer<PackInfo> packes)
- {
- //保存码单,上传服务器成功后,以codeSingle为条件更改同步字段;
- this->codeSingle = packes->codeSingle();
- productData.goods_id = packes->goodsID();
- productData.code_single = packes->codeSingle();
- productData.quantity = packes->quantity;
- productData.batch_no = packes->info().batch_no;
- productData.category = packes->info().category;
- productData.level_id = packes->level_id;
- productData.tube_number = packes->tube_number();
- productData.gross_weight = packes->gross_weight();
- productData.net_weight = packes->net_weight();
- productData.machine_no = packes->machine_no;
- productData.packing_time = packes->packing_time;
- productData.packing_type = packes->packing_type;
- productData.carton_type = packes->carton_type;
- productData.operator_id = packes->operator_id;
- productData.remark = packes->remark;
- if(database.insertProduct(productData)){
- qDebug()<<"product数据库添加成功";
- return;
- }
- qDebug()<<"product数据库添加失败";
- }
- //将打包数据转换为json数据
- QJsonObject AutoPackUtils::toJson(QSharedPointer<PackInfo> &info)
- {
- QJsonObject json;
- QJsonObject detailsjson;
- QJsonArray jsonarray;
- for(int i = 0;i<info->boxes().size();i++){
- detailsjson.insert("case_number",info->boxes().at(i)->caseNumber());
- detailsjson.insert("box_weight",info->boxes().at(i)->box_weight);
- detailsjson.insert("tube_number",info->boxes().at(i)->tube_number);
- detailsjson.insert("bucket_weight",info->boxes().at(i)->bucket_weight);
- detailsjson.insert("gross_weight",info->boxes().at(i)->gross_weight);
- detailsjson.insert("net_weight",info->boxes().at(i)->net_weight);
- detailsjson.insert("box_weight",info->boxes().at(i)->box_weight);
- detailsjson.insert("sort",info->boxes().at(i)->sort);
- detailsjson.insert("remark",info->boxes().at(i)->remark);
- jsonarray.append(detailsjson);
- }
- json.insert("goods_id",info->goodsID());
- json.insert("code_single",info->codeSingle());
- json.insert("quantity",info->quantity);
- json.insert("level_id",info->level_id);
- json.insert("tube_number",info->tube_number());
- json.insert("gross_weight",info->gross_weight());
- json.insert("net_weight",info->net_weight());
- json.insert("machine_no",info->machine_no);
- json.insert("packing_time",info->packing_time);
- json.insert("packing_type",info->packing_type);
- json.insert("carton_type",info->carton_type);
- json.insert("operator",info->operator_id);
- json.insert("details",jsonarray);
- json.insert("remark",info->remark);
- return json;
- }
|