| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174 |
- #include "formshkjfree.h"
- #include "ui_formshkjfree.h"
- #include "sncdatabase.h"
- #include "zxshdb.h"
- #include "respdljsjcresultfile.h"
- #include "respuserserviceverify.h"
- #include "respgetzxshtaskinfo.h"
- #include "respdlzxshresultfile.h"
- #include "zip.h";
- #include "wssso.h"
- #include "respgetservertime.h"
- FormShkjFree::FormShkjFree(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::FormShkjFree)
- {
- ui->setupUi(this);
- initVariables();
- initUI();
- setTableWidgetNoData(ui->tableWidget);
- }
- FormShkjFree::~FormShkjFree()
- {
- m_movieBig->stop();
- delete m_movieBig;
- m_cubews->abort();
- delete m_cubews;
- delete ui;
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormRiddle.FormShkjFree Destroyed.";
- }
- void FormShkjFree::initVariables()
- {
- m_movieBig = new QMovie(":/fetchfromserver.gif");
- m_movieBig->start();
- m_keys<<"ssid"<<"inserttime"<<"province"<<"city"<<"updatedays"<<"isp"\
- <<"neednum"<<"rpnum"<<"dealstatus"<<"detail"<<"download";
- m_state = NotLogin;
- m_headers<<""<<"操作时间"<<"省份"<<"地区"<<"更新时间"<<"isp"<<"选择下载量"<<"实际下载量"\
- <<"状态"<<"详情"<<"下载";
- m_curLtfid = "";
- m_curQryid = "";
- m_lastLtfid = "";
- m_srvtime = "";
- m_cubews = new WSCube2();
- ui->tableWidget->installEventFilter(this);
- }
- void FormShkjFree::setAccountInfo(QMap<QString, QString> info)
- {
- m_account = info;
- QString ssoHash = info.value("ssohash");
- if(!ssoHash.isEmpty())
- {
- m_state = LoginOk;
- //qDebug()<<"m_sertime"<<json<<m_srvtime;
- setTableWidgetSyncData(ui->tableWidget);
- }
- else
- {
- m_state = NotLogin;
- }
- if(m_state!=LoginOk)
- {
- setTableWidgetNoData(ui->tableWidget);
- setDetailNoData();
- }
- }
- bool FormShkjFree::eventFilter(QObject *object, QEvent *event)
- {
- if( event->type() == QEvent::KeyPress)
- {
- // if yes, we need to cast the event into a QMouseEvent type
- QKeyEvent * pKeyEvent = static_cast<QKeyEvent *>(event);
- // check whether it's mid button pressed
- if (pKeyEvent->key() == Qt::Key_Control||pKeyEvent->key() == Qt::Key_Shift)
- {
- //do the processing and return true
- //textBrowserErrorInfo->setText(tr("clicked"));
- ui->tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
- return true; //一定要返回true,如果你不想别的object也能接收到这个event
- }
- }
- else if( event->type() == QEvent::KeyRelease)
- {
- QKeyEvent * pKeyEvent = static_cast<QKeyEvent *>(event);
- // check whether it's mid button pressed
- if (pKeyEvent->key() == Qt::Key_Control||pKeyEvent->key() == Qt::Key_Shift)
- {
- //do the processing and return true
- //textBrowserErrorInfo->setText(tr("clicked"));
- ui->tableWidget->setSelectionMode(QAbstractItemView::MultiSelection);
- return true; //一定要返回true,如果你不想别的object也能接收到这个event
- }
- }
- return QWidget::eventFilter(object, event);
- }/**/
- void FormShkjFree::initUI()
- {
- ui->label->setStyleSheet("color:red");
- ui->batchDlHint->setStyleSheet("color:green");
- ui->tableWidget->setColumnCount(m_headers.size());
- ui->tableWidget->setHorizontalHeaderLabels(m_headers);
- //XCheckBoxHeaderView *myHeader = new XCheckBoxHeaderView(0, Qt::Horizontal, ui->tableWidget);
- //ui->tableWidget->setHorizontalHeader(myHeader);
- ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
- ui->tableWidget->setShowGrid(false);
- ui->tableWidget->setAlternatingRowColors(true);
- ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
- ui->tableWidget->setSelectionMode(QAbstractItemView::MultiSelection);
- ui->tableWidget->verticalHeader()->setVisible(false);
- ui->tableWidget->horizontalHeader()->setStyleSheet("font:12px");
- ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
- ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Fixed);
- ui->tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- ui->tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
- ui->tableWidget->verticalHeader()->setFixedWidth(30);
- ui->tableWidget->setSortingEnabled(true);
- int col = 0;
- ui->tableWidget->setColumnWidth(col++,20);
- ui->tableWidget->setColumnWidth(col++,140);
- ui->tableWidget->setColumnWidth(col++,80);
- ui->tableWidget->setColumnWidth(col++,80);//
- ui->tableWidget->setColumnWidth(col++,80);
- ui->tableWidget->setColumnWidth(col++,0);
- ui->tableWidget->setColumnWidth(col++,0);
- ui->tableWidget->setColumnWidth(col++,80);//
- ui->tableWidget->setColumnWidth(col++,100);//
- ui->tableWidget->setColumnWidth(col++,45);//
- ui->tableWidget->setColumnWidth(col++,45);//
- }
- void FormShkjFree::setTableWidgetNoData(QTableWidget *tableWidget)
- {
- prepareTableWidgetCells(tableWidget,7);
- tableWidget->setEnabled(false);
- QTableWidgetItem *item = new QTableWidgetItem();
- item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
- item->setText("暂无信息");
- tableWidget->setItem(3,3,item);
- }
- void FormShkjFree::setTableWidgetSyncData(QTableWidget *tableWidget)
- {
- prepareTableWidgetCells(tableWidget,7);
- tableWidget->setEnabled(false);
- QLabel *lbl = new QLabel();
- QTableWidgetItem *item = new QTableWidgetItem("正在读取...");
- lbl->setMovie(m_movieBig);
- lbl->setAlignment(Qt::AlignCenter|Qt::AlignVCenter);
- item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
- tableWidget->setItem(4,4,item);
- tableWidget->setCellWidget(4,3,lbl);
- }
- void FormShkjFree::setDetailNoData()
- {
- }
- void FormShkjFree::prepareTableWidgetCells(QTableWidget *tableWidget, int rows)
- {
- tableWidget->setRowCount(0);
- tableWidget->setRowCount(rows);
- }
- void FormShkjFree::fillDataList(QTableWidget *tableWidget,QStringList keys,
- QMultiMap<QString, QString> list, int rowCount)
- {
- setTableWidgetNoData(tableWidget);
- if(rowCount==0)
- {
- return ;
- }
- prepareTableWidgetCells(tableWidget,rowCount);
- tableWidget->setEnabled(true);
- for(int row = 0;row < rowCount;row++)
- {
- QMap<QString,QString> map;
- for(int col=0;col<keys.size();col++)
- {
- QString key = keys.at(col);
- QString value ;
- if(list.values(key).count()>row)
- value = list.values(key).at(row);
- map.insert(key,value);
- }
- for(int col=0;col<keys.size();col++)
- {
- QString key = keys.at(col);
- QString value ;
- if(list.values(key).count()>row)
- value = list.values(key).at(row);
- setCellElement(tableWidget,row,col,key,value,map);
- }
- }
- tableWidget->sortByColumn(0);
- //tableWidget->sortByColumn(0); //重复 del by wzx
- }
- void FormShkjFree::setCellElement(QTableWidget *tableWidget, int row, int col,
- QString key,QString value,QMap<QString,QString> data)
- {
- QTableWidgetItem* item = new QTableWidgetItem();
- QVariant display = value;
- QVariant tooltip = value;
- item->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
- //进行数据翻译
- if(key=="ssid")
- {
- tooltip = "";
- display = "";
- item->setCheckState(Qt::Unchecked);
- }
- else if(key=="dealstatus")
- {
- if(value=="0")
- {
- tooltip = "未处理";
- }
- else if(value=="1")
- {
- tooltip = "处理中";
- }
- else if(value=="2")
- {
- tooltip = "处理完毕";
- item->setTextColor(Qt::red);
- }
- else if(value=="3")
- {
- tooltip = "下载完毕";
- item->setTextColor(Qt::blue);
- }
- else if(value=="4")
- {
- tooltip = "处理异常";
- }
- else if(value=="5")
- {
- tooltip = "无有效数据";
- }
- else
- {
- tooltip = "未知";
- }
- display = tooltip;
- }
- else if(key=="neednum")
- {
- display = QString("%1条").arg(value);
- tooltip = display;
- }
- else if(key=="updatedays")
- {
- int days = value.toInt();
- if(days<30)
- display = QString("%1天内").arg(days);
- else if(days==30)
- display = QString("1月内");
- else if(days==90)
- display = QString("3月内");
- else if(days==180)
- display = QString("半年内");
- else
- display = QString::number(days);
- tooltip = display;
- }
- if(key == "detail")
- {
- delete item;
- QPushButton *button = new QPushButton(this);
- button->setProperty("class","txt-green");
- button->setCursor(Qt::PointingHandCursor);
- button->setText("查看");
- tableWidget->setCellWidget(row,col,button);
- connect(button,SIGNAL(clicked()),this,SLOT(onButtonClicked()));
- }
- else if(key == "download")
- {
- delete item;
- QPushButton *button = new QPushButton(this);
- button->setText("下载");
- button->setProperty("class","txt-green");
- button->setCursor(Qt::PointingHandCursor);
- QString dealstatus=data.value("dealstatus");
- if(dealstatus=="2" || dealstatus=="3")
- button->setEnabled(true);
- else
- button->setEnabled(false);
- tableWidget->setCellWidget(row,col,button);
- connect(button,SIGNAL(clicked()),this,SLOT(onButtonDownloadClicked()));
- }
- else
- {
- item->setData(Qt::DisplayRole,display);
- item->setData(Qt::UserRole,value);
- item->setData(Qt::ToolTipRole,tooltip);
- tableWidget->setItem(row,col,item);
- }
- }
- void FormShkjFree::query()
- {
- ui->batchDlHint->setText("");
- QString isdown;
- isdown = getIsDown();
- QString userCode= m_account.value("usercode");
- QMultiMap<QString,QString> list = ZxshDB::getShkjZxshTasksByUser(userCode,isdown);
- int cols = list.uniqueKeys().size();
- int rows = 0;
- if(cols!=0)
- rows = list.size()/cols;
- if(list.size()==0)
- {
- setTableWidgetNoData(ui->tableWidget);
- setDetailNoData();
- return ;
- }
- // QStringList ids;
- // QString curId;
- // for(int i=0;i<ui->tableWidget->rowCount();i++)
- // {
- // QTableWidgetItem *item = ui->tableWidget->item(i,0);
- // if(item)
- // {
- // if(item->checkState()==Qt::Checked)
- // {
- // ids<<item->data(Qt::UserRole).toString();
- // }
- // if(item->isSelected())
- // {
- // curId = item->data(Qt::UserRole).toString();
- // }
- // }
- // }
- fillDataList(ui->tableWidget,m_keys,list,rows);
- // for(int i=0;i<ui->tableWidget->rowCount();i++)
- // {
- // if(curId.isEmpty())
- // {
- // ui->tableWidget->selectRow(i);
- // //on_tableWidget_cellClicked(i,0);
- // break;
- // }
- // QTableWidgetItem *item = ui->tableWidget->item(i,0);
- // if(item)
- // {
- // QString id = item->data(Qt::UserRole).toString();
- // if(curId==id)
- // {
- // ui->tableWidget->selectRow(i);
- // //on_tableWidget_cellClicked(i,0);
- // }
- // for(int i=0;i<ids.size();i++)
- // {
- // if(id==ids.at(i))
- // {
- // item->setCheckState(Qt::Checked);
- // break;
- // }
- // }
- // }
- // }
- ui->checkBox->setCheckState(Qt::Unchecked);
- }
- void FormShkjFree::showRtnMessage(int row)
- {
- }
- void FormShkjFree::onDataUpdated()
- {
- query();
- }
- void FormShkjFree::onButtonClicked()
- {
- QPushButton *btn = qobject_cast<QPushButton*>(sender());
- for(int i=0;i<ui->tableWidget->rowCount();i++)
- {
- QWidget *widget = ui->tableWidget->cellWidget(i,9);
- if(widget)
- {
- if(btn==qobject_cast<QPushButton*>(widget))
- {
- QTableWidgetItem *item1 = ui->tableWidget->item(i,2);
- QTableWidgetItem *item2 = ui->tableWidget->item(i,3);
- QTableWidgetItem *item3 = ui->tableWidget->item(i,4);
- QTableWidgetItem *item4 = ui->tableWidget->item(i,5);
- emit rowButtonClicked("FREE",item1->data(Qt::UserRole).toString()+"-"+\
- item2->data(Qt::UserRole).toString()+"-"+\
- item3->data(Qt::UserRole).toString()+"-"+\
- item4->data(Qt::UserRole).toString());
- break;
- }
- }
- }
- }
- void FormShkjFree::onButtonDownloadClicked()
- {
- QPushButton *btn = qobject_cast<QPushButton*>(sender());
- for(int i=0;i<ui->tableWidget->rowCount();i++)
- {
- QWidget *widget = ui->tableWidget->cellWidget(i,10);
- if(widget)
- {
- if(btn==qobject_cast<QPushButton*>(widget))
- {
- QTableWidgetItem *item = ui->tableWidget->item(i,0);
- QString ssid = item->data(Qt::UserRole).toString();
- download(ssid);
- break;
- }
- }
- }
- }
- void FormShkjFree::displayDetail(QString hmzs, QStringList infos, QStringList nums,QString dealstatus)
- {
- // double r11 = 0;//快速检测实号数
- // double r31 = 0;//精准检测空号数
- // double r32 = 0;//精准检测停机数
- // double r33 = 0;//精准检测关机数
- // double r34 = 0;//精准检测实号数
- // int sum = hmzs.toInt();
- // int barLength = 500;
- // setDetailNoData();
- // if(infos.size()==2&&nums.size()==2)
- // {
- // int i=0;
- // int j=0;
- // QStringList list = infos.at(i++).split("|");
- // QStringList list2 = nums.at(j++).split(",");
- // if(list.size()==3 && list2.size()==3)
- // {
- // r11= list2.at(2).toDouble();
- // QString rate = QString::number(100*(sum-r11)/sum,'f',2);
- // ui->labelValidNum->setText(list.at(2));
- // ui->labelInvalidNum->setText(QString("未知:%1(%2%)").arg(sum-r11).arg(rate));
- // }
- // list = infos.at(i++).split("|");
- // list2 = nums.at(j++).split(",");
- // if(list.size()==5 && list2.size()==4)
- // {
- // r31= list2.at(0).toDouble();//kong
- // r32= list2.at(1).toDouble();//ting
- // r33= list2.at(2).toDouble();//guan
- // r34 = list2.at(3).toDouble();//shihao
- // ui->labelKong->setText(list.at(0));
- // ui->labelTing->setText(list.at(1));
- // ui->labelGuan->setText(list.at(2));
- // ui->labelShiHao->setText(list.at(3));
- // }
- // }
- // if(sum>0)
- // {
- // ui->labelBarShiHao->setFixedWidth(barLength*r11/sum);
- // ui->labelBarWeizhi->setFixedWidth(barLength*(1-r11/sum));
- // ui->labelBarShiHao2->setFixedWidth(barLength*r34/sum);
- // ui->labelBarKong->setFixedWidth(barLength*r31/sum);
- // ui->labelBarTing->setFixedWidth(barLength*r32/sum);
- // ui->labelBarGuan->setFixedWidth(barLength*r33/sum);
- // }
- // bool isok = (dealstatus=="2") || (dealstatus == "3");
- // ui->pushButtonDownload->setEnabled(isok);
- }
- //void FormShkjFree::on_tableWidget_cellClicked(int row, int column)
- //{
- // QStringList infos,nums;
- // if(row>=0&&column>=0)
- // {
- // m_curLtfid = ui->tableWidget->item(row,0)->data(Qt::UserRole).toString();
- // m_curQryid = ui->tableWidget->item(row,3)->data(Qt::UserRole).toString();
- // m_lastLtfid = m_curLtfid;
- // QList<int> indexs;
- // indexs<<5<<7;
- // for(int i=0;i<indexs.size();i++)
- // {
- // QString str = ui->tableWidget->item(row,indexs.at(i))->data(Qt::DisplayRole).toString();
- // str.replace(" ","");
- // infos<<str;
- // str = ui->tableWidget->item(row,indexs.at(i)+1)->data(Qt::DisplayRole).toString();
- // str.replace(" ","");
- // nums<<str;
- // }
- // QString dealstatus = "2";
- // displayDetail(ui->tableWidget->item(row,4)->data(Qt::DisplayRole).toString(),infos,nums,dealstatus);
- // if(column==4)
- // {
- // showDetailDialog(m_curLtfid);
- // }
- // }
- //}
- //void FormShkjFree::on_radioButtonAll_clicked()
- //{
- // if(!chkAccountState(m_state))
- // return ;
- // if(ui->radioButtonAll->isChecked())
- // {
- // query("");
- // }
- // else if(ui->radioButtonUndownoad->isChecked())
- // {
- // query("2");
- // }
- // else if(ui->radioButtonDownload->isChecked())
- // {
- // query("3");
- // }
- //}
- //void FormShkjFree::on_radioButtonUndownoad_clicked()
- //{
- // if(!chkAccountState(m_state))
- // return ;
- // on_radioButtonAll_clicked();
- //}
- //void FormShkjFree::on_radioButtonDownload_clicked()
- //{
- // if(!chkAccountState(m_state))
- // return ;
- // on_radioButtonAll_clicked();
- //}
- void FormShkjFree::download(QString ssid)
- {
- QString ssoHash = m_account.value("ssohash");
- if(ssoHash.isEmpty())
- {
- QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
- return;
- }
- if(ssid.isEmpty())
- {
- QMessageBox::critical(this,"提示","请先选择要下载的任务单!",QMessageBox::Ok);
- return ;
- }
- QString dealstatus;
- QString province;
- QString city;
- QString updatedays;
- QString isp;
- QString neednum;
- QString rpnum;
- for(int i=0;i<ui->tableWidget->rowCount();i++)
- {
- QTableWidgetItem *item = ui->tableWidget->item(i,0);
- if(item)
- {
- if(ssid == item->data(Qt::UserRole).toString())
- {
- province = ui->tableWidget->item(i,2)->data(Qt::UserRole).toString();
- city = ui->tableWidget->item(i,3)->data(Qt::UserRole).toString();
- updatedays = ui->tableWidget->item(i,4)->data(Qt::UserRole).toString();
- isp = ui->tableWidget->item(i,5)->data(Qt::UserRole).toString();
- neednum = ui->tableWidget->item(i,6)->data(Qt::UserRole).toString();
- rpnum = ui->tableWidget->item(i,7)->data(Qt::UserRole).toString();
- dealstatus = ui->tableWidget->item(i,8)->data(Qt::UserRole).toString();
- break;
- }
- }
- }
- // if(dealstatus=="2")
- // {
- // if(QMessageBox::Yes!=QMessageBox::question(NULL,
- // "确认",
- // QString("此次下载需要扣除下载量,是否继续?")
- // ,QMessageBox::Yes,QMessageBox::No))
- // {
- // return ;
- // }
- // }
- QString file = QString("zxsh_%1_%2_%3_%4_%5").arg(m_account.value("usercode")).arg(ssid).arg(province).arg(city).arg(rpnum);
- QString saveZipFileName = getSaveZipFileName(file);
- if(saveZipFileName.isEmpty())
- return ;
- downloadFromRemote(saveZipFileName,ssid,dealstatus,neednum,updatedays);
- // QString cachePath = SNCDataBase::getShkjCachePath(ssid);
- // bool iscached = false;
- // if(!cachePath.isEmpty())
- // {
- // if(QFile::exists(cachePath))
- // {
- // iscached = true;
- // }
- // }
- // this->setCursor(Qt::WaitCursor);
- // if(iscached)
- // {
- // downloadFromLocal(saveZipFileName,cachePath);
- // }
- // else
- // {
- // downloadFromRemote(saveZipFileName,ssid,dealstatus,neednum);
- // }
- // this->setCursor(Qt::ArrowCursor);
- }
- void FormShkjFree::downloadFromLocal(QString saveFileName,QString cacheFile)
- {
- QFile::copy(cacheFile,saveFileName);
- QMessageBox::information(this,"提示","下载成功!",QMessageBox::Ok);
- }
- void FormShkjFree::downloadFromRemote(QString saveFileName, QString ssid, QString dealstatus, QString total,QString updatedays)
- {
- QString ssoHash = m_account.value("ssohash");
- qDebug()<<dealstatus<<total<<updatedays;
- QString json = m_cubews->userServiceVerify("DlZxshResultFile",QString("%1,%2,%3").arg(dealstatus).arg(total).arg(updatedays),ssoHash);
- RespUserServiceVerify response1(json);
- if(response1.getRtnCode()<=0)
- {
- QMessageBox::critical(this,"提示",response1.getRtnMemo(),QMessageBox::Ok);
- return ;
- }
- this->setCursor(Qt::WaitCursor);
- json = m_cubews->dlZxshResultFile(ssid,ssoHash);
- this->setCursor(Qt::ArrowCursor);
- RespDlZxshResultFile response(json);
- if(response.getRtnCode()==1)
- {
- QString fileContent = response.getFileContent();
- QByteArray array = QByteArray::fromBase64(fileContent.toAscii());
- qDebug()<<response.getFileName();
- QFile file(saveFileName);
- file.open(QIODevice::WriteOnly);
- file.write(array);
- file.close();
- ZxshDB::updateZxshDealStatus(ssid,"3");
- query();
- emit dataDownload();
- QMessageBox::information(this,"提示","下载成功!",QMessageBox::Ok);
- }
- else
- {
- QMessageBox::critical(this,"提示",response.getRtnMemo(),QMessageBox::Ok);
- }
- }
- QString FormShkjFree::getSaveZipFileName(QString qryID)
- {
- QFileDialog::Options options;
- QString selectedFilter;
- QString exportDir = SNCDataBase::getExportDir();
- if(exportDir.isEmpty())
- {
- QString path = QProcessEnvironment::systemEnvironment().value("HOMEDRIVE")+\
- QProcessEnvironment::systemEnvironment().value("HOMEPATH")+"\\DESKTOP";
- exportDir = path;
- }
- QString defaultZipFileName = QString("%1.zip").arg(qryID);
- QString saveZipFileName = QFileDialog::getSaveFileName(this,"另存为",exportDir + "\\" + defaultZipFileName,
- tr("ZIP Files (*.zip)"),
- &selectedFilter,
- options);
- if(!saveZipFileName.isEmpty())
- {
- QFileInfo fileInfo(saveZipFileName);
- exportDir = fileInfo.absolutePath();
- SNCDataBase::updateExportDir(exportDir);
- }
- return saveZipFileName;
- }
- QString FormShkjFree::cacheDownloadFile(QString fileName)
- {
- QString userCode = m_account.value("usercode");
- QString date = QDate::currentDate().toString("yyyyMM");
- QString cachePath = QCoreApplication::applicationDirPath()+\
- QString("/../data/%1/cache/shkj/download/%2/").arg(userCode).arg(date);
- QDir dir;
- dir.mkpath(cachePath);
- QFileInfo fileinfo(fileName);
- QFile::copy(fileName,cachePath + fileinfo.fileName());
- return cachePath + fileinfo.fileName();
- }
- bool FormShkjFree::chkAccountState(AccountLoginState state)
- {
- bool ret = false;
- switch(state)
- {
- case NotLogin:
- QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
- break;
- case NotBind:
- QMessageBox::critical(this,"提示","此项服务尚未开通,请开通后再操作!",QMessageBox::Ok);
- break;
- case LoginError:
- QMessageBox::critical(this,"提示","此项服务暂时无法连接,请稍候重试!",QMessageBox::Ok);
- break;
- default:
- ret = true;
- }
- return ret;
- }
- //void FormShkjFree::showDetailDialog(QString ltfid)
- //{
- // setCursor(Qt::WaitCursor);
- // QString fileName = QCoreApplication::applicationDirPath()+\
- // QString("/../data/%1/cache/shkj/upload/%2.rtn").arg(m_account.value("usercode")).arg(ltfid);
- // QFile file(fileName);
- // file.open(QIODevice::ReadOnly);
- // QTextStream in(&file);
- // QString content = in.readAll();
- // file.close();
- // if(content.isEmpty())
- // {
- // QMessageBox::information(this,"提示","号码已经全部接收!",QMessageBox::Ok);
- // }
- // else
- // {
- // DialogSubmitResponseDetail dialog;
- // dialog.setDetailText(content);
- // dialog.exec();
- // }
- // setCursor(Qt::ArrowCursor);
- //}
- //void FormShkjFree::on_pushButtonDownload_clicked()
- //{
- // if(!chkAccountState(m_state))
- // return ;
- // download(m_curLtfid,m_curQryid);
- //}
- //void FormShkjFree::on_tableWidget_cellDoubleClicked(int row, int column)
- //{
- // if(!chkAccountState(m_state))
- // return ;
- // download(m_curLtfid,m_curQryid);
- //}
- void FormShkjFree::on_pushButtonDel_clicked()
- {
- if(!chkAccountState(m_state))
- return ;
- bool nodata = true;
- for(int i=0;i<ui->tableWidget->rowCount();i++)
- {
- QTableWidgetItem *item = ui->tableWidget->item(i,0);
- if(item)
- {
- if(item->checkState()==Qt::Checked)
- {
- nodata = false;
- }
- }
- }
- if(nodata)
- {
- QMessageBox::critical(this,"提示","请选择要删除的单子",QMessageBox::Ok);
- return ;
- }
- if(QMessageBox::Yes!=QMessageBox::question(NULL,
- "确认",
- QString("您确定要删除吗?")
- ,QMessageBox::Yes,QMessageBox::No))
- {
- return ;
- }
- for(int i=0;i<ui->tableWidget->rowCount();i++)
- {
- QTableWidgetItem *item = ui->tableWidget->item(i,0);
- if(item)
- {
- if(item->checkState()==Qt::Checked)
- {
- QString id = item->data(Qt::UserRole).toString();
- ZxshDB::delShkjZxshTaskByID(id);
- }
- }
- }
- query();
- }
- //void FormShkjFree::on_checkBox_clicked()
- //{
- // Qt::CheckState state;
- // state = ui->checkBox->checkState();
- // for(int i=0;i<ui->tableWidget->rowCount();i++)
- // {
- // QTableWidgetItem *item = ui->tableWidget->item(i,0);
- // if(item)
- // {
- // item->setCheckState(state);
- // }
- // }
- //}
- void FormShkjFree::on_pushButtonQuery_clicked()
- {
- if(!chkAccountState(m_state))
- return ;
- query();
- }
- void FormShkjFree::on_tableWidget_clicked(const QModelIndex &index)
- {
- if(index.column()==0)
- {
- QTableWidgetItem *item = ui->tableWidget->item(index.row(),index.column());
- if(item)
- {
- if(item->checkState()==Qt::Checked)
- {
- ui->tableWidget->selectRow(index.row());
- }
- else
- {
- ui->tableWidget->selectRow(index.row());
- }
- }
- }
- }
- void FormShkjFree::on_tableWidget_itemSelectionChanged()
- {
- for(int i=0;i<ui->tableWidget->rowCount();i++)
- {
- QTableWidgetItem *item = ui->tableWidget->item(i,0);
- if(item->isSelected())
- {
- item->setCheckState(Qt::Checked);
- }
- else
- {
- item->setCheckState(Qt::Unchecked);
- }
- }
- }
- void FormShkjFree::on_checkBox_clicked()
- {
- WSSSO sso;
- QString json = sso.getServerTime();
- RespGetServerTime resp(json);
- m_srvtime = resp.getServerTime();
- for(int i=0;i<ui->tableWidget->rowCount();i++)
- {
- QTableWidgetItem *item = ui->tableWidget->item(i,0);
- if(item)
- {
- if(ui->checkBox->isChecked())
- {
- // QString optdate,dealstatus;
- // optdate = ui->tableWidget->item(i,1)->data(Qt::UserRole).toString();
- // dealstatus = ui->tableWidget->item(i,8)->data(Qt::UserRole).toString();
- // if(dealstatus=="2" || dealstatus=="3")
- // {
- // QDateTime now;
- // if(m_srvtime.isEmpty())
- // now = QDateTime::currentDateTime();
- // else
- // now = QDateTime::fromString(m_srvtime,"yyyy-MM-dd hh:mm:ss");
- // QDateTime then = QDateTime::fromString(optdate,"yyyy-MM-dd hh:mm:ss");
- // qDebug()<<then.daysTo(now)<<then<<now<<optdate;
- // if(then.daysTo(now)<=30)
- // {
- // item->setCheckState(Qt::Checked);
- // }
- // }
- item->setCheckState(Qt::Checked);//modify by xxw on 2017-8-20 fix bug select all
- }
- else
- {
- item->setCheckState(Qt::Unchecked);
- }
- }
- }
- }
- void FormShkjFree::on_pushButtonBatchDown_clicked()
- {
- if(!chkAccountState(m_state))
- return;
- int selected = 0;
- QString defaultZipName;
- QString errText;
- errText = "";
- defaultZipName = "batch";
- int num = 0;
- for(int i=0;i<ui->tableWidget->rowCount();i++)
- {
- QTableWidgetItem *item = ui->tableWidget->item(i,0);
- if(item)
- {
- QString ssid;
- QString optdate;
- QString dealstatus;
- QString province;
- QString city;
- QString updatedays;
- QString isp;
- QString neednum;
- QString rpnum;
- if(item->checkState()==Qt::Checked)
- {
- num++;
- //ui->batchDlHint->setText(QString("正在分析第 %1 个文件,请稍候").arg(num));
- ssid = item->data(Qt::UserRole).toString();
- optdate = ui->tableWidget->item(i,1)->data(Qt::UserRole).toString();
- province = ui->tableWidget->item(i,2)->data(Qt::UserRole).toString();
- city = ui->tableWidget->item(i,3)->data(Qt::UserRole).toString();
- updatedays = ui->tableWidget->item(i,4)->data(Qt::UserRole).toString();
- isp = ui->tableWidget->item(i,5)->data(Qt::UserRole).toString();
- neednum = ui->tableWidget->item(i,6)->data(Qt::UserRole).toString();
- rpnum = ui->tableWidget->item(i,7)->data(Qt::UserRole).toString();
- dealstatus = ui->tableWidget->item(i,8)->data(Qt::UserRole).toString();
- selected++;
- if(dealstatus=="2" || dealstatus=="3")
- {
- if (num <= 10)
- defaultZipName += "_"+ssid;
- QDateTime now = QDateTime::currentDateTime();
- QDateTime then = QDateTime::fromString(optdate,"yyyy-MM-dd hh:mm:ss");
- qDebug()<<then.daysTo(now)<<then<<now<<optdate;
- if(then.daysTo(now)>30)
- {
- errText += QString("您选择第%1个文件,已经过期(有效期1个月),无法下载!\r\n").arg(i+1);
- }
- }
- else
- {
- errText += QString("您选择第%1个文件,还未处理完毕,无法下载!\r\n").arg(i+1);
- }
- }
- }
- }
- //ui->batchDlHint->setText("");
- if (num > 10)
- defaultZipName += "_more";
- if(selected==0)
- {
- QMessageBox::critical(this,"提示","请选择要下载的数据!",QMessageBox::Ok);
- return ;
- }
- if(!errText.isEmpty())
- {
- QMessageBox::critical(this,"提示",errText,QMessageBox::Ok);
- return ;
- }
- defaultZipName += "_"+QString::number(selected);
- QFileDialog::Options options;
- QString selectedFilter;
- QString exportDir = SNCDataBase::getExportDir();
- QString saveZipFileName = QFileDialog::getSaveFileName(this,"另存为",exportDir + "\\" + defaultZipName,
- tr("ZIP Files (*.zip)"),
- &selectedFilter,
- options);
- if(!saveZipFileName.isEmpty())
- {
- QFileInfo fileInfo(saveZipFileName);
- exportDir = fileInfo.absolutePath();
- SNCDataBase::updateExportDir(exportDir);
- }
- else
- {
- return;
- }
- QDir dir;
- if(!dir.exists(QDir::tempPath()+"/speednumcube"))
- {
- dir.mkdir(QDir::tempPath()+"/speednumcube");
- }
- QString tmpDir = QDir::tempPath()+"/speednumcube/";
- QStringList files;
- ui->pushButtonBatchDown->setEnabled(false);
- this->setCursor(Qt::WaitCursor);
- num = 0;
- for(int i=0;i<ui->tableWidget->rowCount();i++)
- {
- QTableWidgetItem *item = ui->tableWidget->item(i,0);
- QString ssid;
- QString dealstatus;
- QString province;
- QString city;
- QString updatedays;
- QString isp;
- QString neednum;
- QString rpnum;
- if(item->checkState()==Qt::Checked)
- {
- num++;
- ui->batchDlHint->setText(QString("正在下载第 %1 个文件,请稍候").arg(num));
- ssid = item->data(Qt::UserRole).toString();
- province = ui->tableWidget->item(i,2)->data(Qt::UserRole).toString();
- city = ui->tableWidget->item(i,3)->data(Qt::UserRole).toString();
- updatedays = ui->tableWidget->item(i,4)->data(Qt::UserRole).toString();
- isp = ui->tableWidget->item(i,5)->data(Qt::UserRole).toString();
- neednum = ui->tableWidget->item(i,6)->data(Qt::UserRole).toString();
- rpnum = ui->tableWidget->item(i,7)->data(Qt::UserRole).toString();
- dealstatus = ui->tableWidget->item(i,8)->data(Qt::UserRole).toString();
- QString fileName;
- fileName = downloadFromRemoteForBatch(tmpDir, ssid, dealstatus,neednum,updatedays);
- if(!fileName.isEmpty())
- {
- files.append(fileName);
- }
- }
- }
- ui->batchDlHint->setText("批量下载完成!");
- this->setCursor(Qt::ArrowCursor);
- if(files.size()>0)
- {
- if(addFileToZip(saveZipFileName,files))
- {
- QMessageBox::information(this,"结果",QString("您选择%1个文件,%2个文件下载成功!")\
- .arg(selected).arg(files.size()),QMessageBox::Ok);
- QFileInfo fileinfo(saveZipFileName);
- SNCDataBase::updateExportDir(fileinfo.absolutePath());
- }
- else
- {
- QMessageBox::critical(this,"结果","文件下载失败!",QMessageBox::Ok);
- }
- }
- else
- {
- QMessageBox::critical(this,"结果","文件下载失败!",QMessageBox::Ok);
- }
- ui->pushButtonBatchDown->setEnabled(true);
- query(); //数据刷新 add by wzx
- }
- QString FormShkjFree::downloadFromRemoteForBatch(QString savePath, QString ssid, QString dealstatus, QString total,QString updatedays)
- {
- QString ssoHash = m_account.value("ssohash");
- qDebug()<<dealstatus<<total<<updatedays;
- QString json = m_cubews->userServiceVerify("DlZxshResultFile",QString("%1,%2,%3").arg(dealstatus).arg(total).arg(updatedays),ssoHash);
- QString saveFileName;
- saveFileName = "";
- RespUserServiceVerify response1(json);
- // if(response1.getRtnCode()<=0)
- // {
- // QMessageBox::critical(this,"提示",response1.getRtnMemo(),QMessageBox::Ok);
- // return saveFileName;
- // }
- this->setCursor(Qt::WaitCursor);
- json = m_cubews->dlZxshResultFile(ssid,ssoHash);
- this->setCursor(Qt::ArrowCursor);
- RespDlZxshResultFile response(json);
- if(response.getRtnCode()==1)
- {
- QString fileContent = response.getFileContent();
- QByteArray array = QByteArray::fromBase64(fileContent.toAscii());
- saveFileName = savePath + response.getFileName();
- QFile file(saveFileName);
- file.open(QIODevice::WriteOnly);
- file.write(array);
- file.close();
- ZxshDB::updateZxshDealStatus(ssid,"3");
- return saveFileName;
- }
- else
- {
- QMessageBox::critical(this,"提示",response.getRtnMemo(),QMessageBox::Ok);
- return saveFileName;
- }
- }
- bool FormShkjFree::addFileToZip(QString zipName, QStringList files)
- {
- Zip::ErrorCode ec;
- Zip uz;
- QFile file(zipName);
- if(!file.open(QIODevice::WriteOnly)){
- return false ;
- }
- file.close();
- ec = uz.createArchive(zipName);
- if (ec != Zip::Ok) {
- return false;
- }
- ec = uz.addFiles(files);
- if (ec != Zip::Ok) {
- uz.closeArchive();
- return false;
- }
- if (uz.closeArchive() != Zip::Ok) {
- return false;
- }
- return true;
- }
- //add by wzx
- QString FormShkjFree::getIsDown()
- {
- QString isdown;
- if(ui->radioButtonAll->isChecked())
- isdown = "0";
- else if(ui->radioButtonDown->isChecked())
- isdown = "1";
- else if(ui->radioButtonNoDown->isChecked())
- isdown = "2";
- else
- isdown = "0";
- return isdown;
- }
- void FormShkjFree::on_radioButtonAll_clicked()
- {
- query();
- }
- void FormShkjFree::on_radioButtonDown_clicked()
- {
- query();
- }
- void FormShkjFree::on_radioButtonNoDown_clicked()
- {
- query();
- }
|