formshkjfree.cpp 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. #include "formshkjfree.h"
  2. #include "ui_formshkjfree.h"
  3. #include "sncdatabase.h"
  4. #include "zxshdb.h"
  5. #include "respdljsjcresultfile.h"
  6. #include "respuserserviceverify.h"
  7. #include "respgetzxshtaskinfo.h"
  8. #include "respdlzxshresultfile.h"
  9. #include "zip.h";
  10. #include "wssso.h"
  11. #include "respgetservertime.h"
  12. FormShkjFree::FormShkjFree(QWidget *parent) :
  13. QWidget(parent),
  14. ui(new Ui::FormShkjFree)
  15. {
  16. ui->setupUi(this);
  17. initVariables();
  18. initUI();
  19. setTableWidgetNoData(ui->tableWidget);
  20. }
  21. FormShkjFree::~FormShkjFree()
  22. {
  23. m_movieBig->stop();
  24. delete m_movieBig;
  25. m_cubews->abort();
  26. delete m_cubews;
  27. delete ui;
  28. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  29. <<"FormRiddle.FormShkjFree Destroyed.";
  30. }
  31. void FormShkjFree::initVariables()
  32. {
  33. m_movieBig = new QMovie(":/fetchfromserver.gif");
  34. m_movieBig->start();
  35. m_keys<<"ssid"<<"inserttime"<<"province"<<"city"<<"updatedays"<<"isp"\
  36. <<"neednum"<<"rpnum"<<"dealstatus"<<"detail"<<"download";
  37. m_state = NotLogin;
  38. m_headers<<""<<"操作时间"<<"省份"<<"地区"<<"更新时间"<<"isp"<<"选择下载量"<<"实际下载量"\
  39. <<"状态"<<"详情"<<"下载";
  40. m_curLtfid = "";
  41. m_curQryid = "";
  42. m_lastLtfid = "";
  43. m_srvtime = "";
  44. m_cubews = new WSCube2();
  45. ui->tableWidget->installEventFilter(this);
  46. }
  47. void FormShkjFree::setAccountInfo(QMap<QString, QString> info)
  48. {
  49. m_account = info;
  50. QString ssoHash = info.value("ssohash");
  51. if(!ssoHash.isEmpty())
  52. {
  53. m_state = LoginOk;
  54. //qDebug()<<"m_sertime"<<json<<m_srvtime;
  55. setTableWidgetSyncData(ui->tableWidget);
  56. }
  57. else
  58. {
  59. m_state = NotLogin;
  60. }
  61. if(m_state!=LoginOk)
  62. {
  63. setTableWidgetNoData(ui->tableWidget);
  64. setDetailNoData();
  65. }
  66. }
  67. bool FormShkjFree::eventFilter(QObject *object, QEvent *event)
  68. {
  69. if( event->type() == QEvent::KeyPress)
  70. {
  71. // if yes, we need to cast the event into a QMouseEvent type
  72. QKeyEvent * pKeyEvent = static_cast<QKeyEvent *>(event);
  73. // check whether it's mid button pressed
  74. if (pKeyEvent->key() == Qt::Key_Control||pKeyEvent->key() == Qt::Key_Shift)
  75. {
  76. //do the processing and return true
  77. //textBrowserErrorInfo->setText(tr("clicked"));
  78. ui->tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
  79. return true; //一定要返回true,如果你不想别的object也能接收到这个event
  80. }
  81. }
  82. else if( event->type() == QEvent::KeyRelease)
  83. {
  84. QKeyEvent * pKeyEvent = static_cast<QKeyEvent *>(event);
  85. // check whether it's mid button pressed
  86. if (pKeyEvent->key() == Qt::Key_Control||pKeyEvent->key() == Qt::Key_Shift)
  87. {
  88. //do the processing and return true
  89. //textBrowserErrorInfo->setText(tr("clicked"));
  90. ui->tableWidget->setSelectionMode(QAbstractItemView::MultiSelection);
  91. return true; //一定要返回true,如果你不想别的object也能接收到这个event
  92. }
  93. }
  94. return QWidget::eventFilter(object, event);
  95. }/**/
  96. void FormShkjFree::initUI()
  97. {
  98. ui->label->setStyleSheet("color:red");
  99. ui->batchDlHint->setStyleSheet("color:green");
  100. ui->tableWidget->setColumnCount(m_headers.size());
  101. ui->tableWidget->setHorizontalHeaderLabels(m_headers);
  102. //XCheckBoxHeaderView *myHeader = new XCheckBoxHeaderView(0, Qt::Horizontal, ui->tableWidget);
  103. //ui->tableWidget->setHorizontalHeader(myHeader);
  104. ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
  105. ui->tableWidget->setShowGrid(false);
  106. ui->tableWidget->setAlternatingRowColors(true);
  107. ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
  108. ui->tableWidget->setSelectionMode(QAbstractItemView::MultiSelection);
  109. ui->tableWidget->verticalHeader()->setVisible(false);
  110. ui->tableWidget->horizontalHeader()->setStyleSheet("font:12px");
  111. ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
  112. ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Fixed);
  113. ui->tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  114. ui->tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
  115. ui->tableWidget->verticalHeader()->setFixedWidth(30);
  116. ui->tableWidget->setSortingEnabled(true);
  117. int col = 0;
  118. ui->tableWidget->setColumnWidth(col++,20);
  119. ui->tableWidget->setColumnWidth(col++,140);
  120. ui->tableWidget->setColumnWidth(col++,80);
  121. ui->tableWidget->setColumnWidth(col++,80);//
  122. ui->tableWidget->setColumnWidth(col++,80);
  123. ui->tableWidget->setColumnWidth(col++,0);
  124. ui->tableWidget->setColumnWidth(col++,0);
  125. ui->tableWidget->setColumnWidth(col++,80);//
  126. ui->tableWidget->setColumnWidth(col++,100);//
  127. ui->tableWidget->setColumnWidth(col++,45);//
  128. ui->tableWidget->setColumnWidth(col++,45);//
  129. }
  130. void FormShkjFree::setTableWidgetNoData(QTableWidget *tableWidget)
  131. {
  132. prepareTableWidgetCells(tableWidget,7);
  133. tableWidget->setEnabled(false);
  134. QTableWidgetItem *item = new QTableWidgetItem();
  135. item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
  136. item->setText("暂无信息");
  137. tableWidget->setItem(3,3,item);
  138. }
  139. void FormShkjFree::setTableWidgetSyncData(QTableWidget *tableWidget)
  140. {
  141. prepareTableWidgetCells(tableWidget,7);
  142. tableWidget->setEnabled(false);
  143. QLabel *lbl = new QLabel();
  144. QTableWidgetItem *item = new QTableWidgetItem("正在读取...");
  145. lbl->setMovie(m_movieBig);
  146. lbl->setAlignment(Qt::AlignCenter|Qt::AlignVCenter);
  147. item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
  148. tableWidget->setItem(4,4,item);
  149. tableWidget->setCellWidget(4,3,lbl);
  150. }
  151. void FormShkjFree::setDetailNoData()
  152. {
  153. }
  154. void FormShkjFree::prepareTableWidgetCells(QTableWidget *tableWidget, int rows)
  155. {
  156. tableWidget->setRowCount(0);
  157. tableWidget->setRowCount(rows);
  158. }
  159. void FormShkjFree::fillDataList(QTableWidget *tableWidget,QStringList keys,
  160. QMultiMap<QString, QString> list, int rowCount)
  161. {
  162. setTableWidgetNoData(tableWidget);
  163. if(rowCount==0)
  164. {
  165. return ;
  166. }
  167. prepareTableWidgetCells(tableWidget,rowCount);
  168. tableWidget->setEnabled(true);
  169. for(int row = 0;row < rowCount;row++)
  170. {
  171. QMap<QString,QString> map;
  172. for(int col=0;col<keys.size();col++)
  173. {
  174. QString key = keys.at(col);
  175. QString value ;
  176. if(list.values(key).count()>row)
  177. value = list.values(key).at(row);
  178. map.insert(key,value);
  179. }
  180. for(int col=0;col<keys.size();col++)
  181. {
  182. QString key = keys.at(col);
  183. QString value ;
  184. if(list.values(key).count()>row)
  185. value = list.values(key).at(row);
  186. setCellElement(tableWidget,row,col,key,value,map);
  187. }
  188. }
  189. tableWidget->sortByColumn(0);
  190. //tableWidget->sortByColumn(0); //重复 del by wzx
  191. }
  192. void FormShkjFree::setCellElement(QTableWidget *tableWidget, int row, int col,
  193. QString key,QString value,QMap<QString,QString> data)
  194. {
  195. QTableWidgetItem* item = new QTableWidgetItem();
  196. QVariant display = value;
  197. QVariant tooltip = value;
  198. item->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
  199. //进行数据翻译
  200. if(key=="ssid")
  201. {
  202. tooltip = "";
  203. display = "";
  204. item->setCheckState(Qt::Unchecked);
  205. }
  206. else if(key=="dealstatus")
  207. {
  208. if(value=="0")
  209. {
  210. tooltip = "未处理";
  211. }
  212. else if(value=="1")
  213. {
  214. tooltip = "处理中";
  215. }
  216. else if(value=="2")
  217. {
  218. tooltip = "处理完毕";
  219. item->setTextColor(Qt::red);
  220. }
  221. else if(value=="3")
  222. {
  223. tooltip = "下载完毕";
  224. item->setTextColor(Qt::blue);
  225. }
  226. else if(value=="4")
  227. {
  228. tooltip = "处理异常";
  229. }
  230. else if(value=="5")
  231. {
  232. tooltip = "无有效数据";
  233. }
  234. else
  235. {
  236. tooltip = "未知";
  237. }
  238. display = tooltip;
  239. }
  240. else if(key=="neednum")
  241. {
  242. display = QString("%1条").arg(value);
  243. tooltip = display;
  244. }
  245. else if(key=="updatedays")
  246. {
  247. int days = value.toInt();
  248. if(days<30)
  249. display = QString("%1天内").arg(days);
  250. else if(days==30)
  251. display = QString("1月内");
  252. else if(days==90)
  253. display = QString("3月内");
  254. else if(days==180)
  255. display = QString("半年内");
  256. else
  257. display = QString::number(days);
  258. tooltip = display;
  259. }
  260. if(key == "detail")
  261. {
  262. delete item;
  263. QPushButton *button = new QPushButton(this);
  264. button->setProperty("class","txt-green");
  265. button->setCursor(Qt::PointingHandCursor);
  266. button->setText("查看");
  267. tableWidget->setCellWidget(row,col,button);
  268. connect(button,SIGNAL(clicked()),this,SLOT(onButtonClicked()));
  269. }
  270. else if(key == "download")
  271. {
  272. delete item;
  273. QPushButton *button = new QPushButton(this);
  274. button->setText("下载");
  275. button->setProperty("class","txt-green");
  276. button->setCursor(Qt::PointingHandCursor);
  277. QString dealstatus=data.value("dealstatus");
  278. if(dealstatus=="2" || dealstatus=="3")
  279. button->setEnabled(true);
  280. else
  281. button->setEnabled(false);
  282. tableWidget->setCellWidget(row,col,button);
  283. connect(button,SIGNAL(clicked()),this,SLOT(onButtonDownloadClicked()));
  284. }
  285. else
  286. {
  287. item->setData(Qt::DisplayRole,display);
  288. item->setData(Qt::UserRole,value);
  289. item->setData(Qt::ToolTipRole,tooltip);
  290. tableWidget->setItem(row,col,item);
  291. }
  292. }
  293. void FormShkjFree::query()
  294. {
  295. ui->batchDlHint->setText("");
  296. QString isdown;
  297. isdown = getIsDown();
  298. QString userCode= m_account.value("usercode");
  299. QMultiMap<QString,QString> list = ZxshDB::getShkjZxshTasksByUser(userCode,isdown);
  300. int cols = list.uniqueKeys().size();
  301. int rows = 0;
  302. if(cols!=0)
  303. rows = list.size()/cols;
  304. if(list.size()==0)
  305. {
  306. setTableWidgetNoData(ui->tableWidget);
  307. setDetailNoData();
  308. return ;
  309. }
  310. // QStringList ids;
  311. // QString curId;
  312. // for(int i=0;i<ui->tableWidget->rowCount();i++)
  313. // {
  314. // QTableWidgetItem *item = ui->tableWidget->item(i,0);
  315. // if(item)
  316. // {
  317. // if(item->checkState()==Qt::Checked)
  318. // {
  319. // ids<<item->data(Qt::UserRole).toString();
  320. // }
  321. // if(item->isSelected())
  322. // {
  323. // curId = item->data(Qt::UserRole).toString();
  324. // }
  325. // }
  326. // }
  327. fillDataList(ui->tableWidget,m_keys,list,rows);
  328. // for(int i=0;i<ui->tableWidget->rowCount();i++)
  329. // {
  330. // if(curId.isEmpty())
  331. // {
  332. // ui->tableWidget->selectRow(i);
  333. // //on_tableWidget_cellClicked(i,0);
  334. // break;
  335. // }
  336. // QTableWidgetItem *item = ui->tableWidget->item(i,0);
  337. // if(item)
  338. // {
  339. // QString id = item->data(Qt::UserRole).toString();
  340. // if(curId==id)
  341. // {
  342. // ui->tableWidget->selectRow(i);
  343. // //on_tableWidget_cellClicked(i,0);
  344. // }
  345. // for(int i=0;i<ids.size();i++)
  346. // {
  347. // if(id==ids.at(i))
  348. // {
  349. // item->setCheckState(Qt::Checked);
  350. // break;
  351. // }
  352. // }
  353. // }
  354. // }
  355. ui->checkBox->setCheckState(Qt::Unchecked);
  356. }
  357. void FormShkjFree::showRtnMessage(int row)
  358. {
  359. }
  360. void FormShkjFree::onDataUpdated()
  361. {
  362. query();
  363. }
  364. void FormShkjFree::onButtonClicked()
  365. {
  366. QPushButton *btn = qobject_cast<QPushButton*>(sender());
  367. for(int i=0;i<ui->tableWidget->rowCount();i++)
  368. {
  369. QWidget *widget = ui->tableWidget->cellWidget(i,9);
  370. if(widget)
  371. {
  372. if(btn==qobject_cast<QPushButton*>(widget))
  373. {
  374. QTableWidgetItem *item1 = ui->tableWidget->item(i,2);
  375. QTableWidgetItem *item2 = ui->tableWidget->item(i,3);
  376. QTableWidgetItem *item3 = ui->tableWidget->item(i,4);
  377. QTableWidgetItem *item4 = ui->tableWidget->item(i,5);
  378. emit rowButtonClicked("FREE",item1->data(Qt::UserRole).toString()+"-"+\
  379. item2->data(Qt::UserRole).toString()+"-"+\
  380. item3->data(Qt::UserRole).toString()+"-"+\
  381. item4->data(Qt::UserRole).toString());
  382. break;
  383. }
  384. }
  385. }
  386. }
  387. void FormShkjFree::onButtonDownloadClicked()
  388. {
  389. QPushButton *btn = qobject_cast<QPushButton*>(sender());
  390. for(int i=0;i<ui->tableWidget->rowCount();i++)
  391. {
  392. QWidget *widget = ui->tableWidget->cellWidget(i,10);
  393. if(widget)
  394. {
  395. if(btn==qobject_cast<QPushButton*>(widget))
  396. {
  397. QTableWidgetItem *item = ui->tableWidget->item(i,0);
  398. QString ssid = item->data(Qt::UserRole).toString();
  399. download(ssid);
  400. break;
  401. }
  402. }
  403. }
  404. }
  405. void FormShkjFree::displayDetail(QString hmzs, QStringList infos, QStringList nums,QString dealstatus)
  406. {
  407. // double r11 = 0;//快速检测实号数
  408. // double r31 = 0;//精准检测空号数
  409. // double r32 = 0;//精准检测停机数
  410. // double r33 = 0;//精准检测关机数
  411. // double r34 = 0;//精准检测实号数
  412. // int sum = hmzs.toInt();
  413. // int barLength = 500;
  414. // setDetailNoData();
  415. // if(infos.size()==2&&nums.size()==2)
  416. // {
  417. // int i=0;
  418. // int j=0;
  419. // QStringList list = infos.at(i++).split("|");
  420. // QStringList list2 = nums.at(j++).split(",");
  421. // if(list.size()==3 && list2.size()==3)
  422. // {
  423. // r11= list2.at(2).toDouble();
  424. // QString rate = QString::number(100*(sum-r11)/sum,'f',2);
  425. // ui->labelValidNum->setText(list.at(2));
  426. // ui->labelInvalidNum->setText(QString("未知:%1(%2%)").arg(sum-r11).arg(rate));
  427. // }
  428. // list = infos.at(i++).split("|");
  429. // list2 = nums.at(j++).split(",");
  430. // if(list.size()==5 && list2.size()==4)
  431. // {
  432. // r31= list2.at(0).toDouble();//kong
  433. // r32= list2.at(1).toDouble();//ting
  434. // r33= list2.at(2).toDouble();//guan
  435. // r34 = list2.at(3).toDouble();//shihao
  436. // ui->labelKong->setText(list.at(0));
  437. // ui->labelTing->setText(list.at(1));
  438. // ui->labelGuan->setText(list.at(2));
  439. // ui->labelShiHao->setText(list.at(3));
  440. // }
  441. // }
  442. // if(sum>0)
  443. // {
  444. // ui->labelBarShiHao->setFixedWidth(barLength*r11/sum);
  445. // ui->labelBarWeizhi->setFixedWidth(barLength*(1-r11/sum));
  446. // ui->labelBarShiHao2->setFixedWidth(barLength*r34/sum);
  447. // ui->labelBarKong->setFixedWidth(barLength*r31/sum);
  448. // ui->labelBarTing->setFixedWidth(barLength*r32/sum);
  449. // ui->labelBarGuan->setFixedWidth(barLength*r33/sum);
  450. // }
  451. // bool isok = (dealstatus=="2") || (dealstatus == "3");
  452. // ui->pushButtonDownload->setEnabled(isok);
  453. }
  454. //void FormShkjFree::on_tableWidget_cellClicked(int row, int column)
  455. //{
  456. // QStringList infos,nums;
  457. // if(row>=0&&column>=0)
  458. // {
  459. // m_curLtfid = ui->tableWidget->item(row,0)->data(Qt::UserRole).toString();
  460. // m_curQryid = ui->tableWidget->item(row,3)->data(Qt::UserRole).toString();
  461. // m_lastLtfid = m_curLtfid;
  462. // QList<int> indexs;
  463. // indexs<<5<<7;
  464. // for(int i=0;i<indexs.size();i++)
  465. // {
  466. // QString str = ui->tableWidget->item(row,indexs.at(i))->data(Qt::DisplayRole).toString();
  467. // str.replace(" ","");
  468. // infos<<str;
  469. // str = ui->tableWidget->item(row,indexs.at(i)+1)->data(Qt::DisplayRole).toString();
  470. // str.replace(" ","");
  471. // nums<<str;
  472. // }
  473. // QString dealstatus = "2";
  474. // displayDetail(ui->tableWidget->item(row,4)->data(Qt::DisplayRole).toString(),infos,nums,dealstatus);
  475. // if(column==4)
  476. // {
  477. // showDetailDialog(m_curLtfid);
  478. // }
  479. // }
  480. //}
  481. //void FormShkjFree::on_radioButtonAll_clicked()
  482. //{
  483. // if(!chkAccountState(m_state))
  484. // return ;
  485. // if(ui->radioButtonAll->isChecked())
  486. // {
  487. // query("");
  488. // }
  489. // else if(ui->radioButtonUndownoad->isChecked())
  490. // {
  491. // query("2");
  492. // }
  493. // else if(ui->radioButtonDownload->isChecked())
  494. // {
  495. // query("3");
  496. // }
  497. //}
  498. //void FormShkjFree::on_radioButtonUndownoad_clicked()
  499. //{
  500. // if(!chkAccountState(m_state))
  501. // return ;
  502. // on_radioButtonAll_clicked();
  503. //}
  504. //void FormShkjFree::on_radioButtonDownload_clicked()
  505. //{
  506. // if(!chkAccountState(m_state))
  507. // return ;
  508. // on_radioButtonAll_clicked();
  509. //}
  510. void FormShkjFree::download(QString ssid)
  511. {
  512. QString ssoHash = m_account.value("ssohash");
  513. if(ssoHash.isEmpty())
  514. {
  515. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  516. return;
  517. }
  518. if(ssid.isEmpty())
  519. {
  520. QMessageBox::critical(this,"提示","请先选择要下载的任务单!",QMessageBox::Ok);
  521. return ;
  522. }
  523. QString dealstatus;
  524. QString province;
  525. QString city;
  526. QString updatedays;
  527. QString isp;
  528. QString neednum;
  529. QString rpnum;
  530. for(int i=0;i<ui->tableWidget->rowCount();i++)
  531. {
  532. QTableWidgetItem *item = ui->tableWidget->item(i,0);
  533. if(item)
  534. {
  535. if(ssid == item->data(Qt::UserRole).toString())
  536. {
  537. province = ui->tableWidget->item(i,2)->data(Qt::UserRole).toString();
  538. city = ui->tableWidget->item(i,3)->data(Qt::UserRole).toString();
  539. updatedays = ui->tableWidget->item(i,4)->data(Qt::UserRole).toString();
  540. isp = ui->tableWidget->item(i,5)->data(Qt::UserRole).toString();
  541. neednum = ui->tableWidget->item(i,6)->data(Qt::UserRole).toString();
  542. rpnum = ui->tableWidget->item(i,7)->data(Qt::UserRole).toString();
  543. dealstatus = ui->tableWidget->item(i,8)->data(Qt::UserRole).toString();
  544. break;
  545. }
  546. }
  547. }
  548. // if(dealstatus=="2")
  549. // {
  550. // if(QMessageBox::Yes!=QMessageBox::question(NULL,
  551. // "确认",
  552. // QString("此次下载需要扣除下载量,是否继续?")
  553. // ,QMessageBox::Yes,QMessageBox::No))
  554. // {
  555. // return ;
  556. // }
  557. // }
  558. QString file = QString("zxsh_%1_%2_%3_%4_%5").arg(m_account.value("usercode")).arg(ssid).arg(province).arg(city).arg(rpnum);
  559. QString saveZipFileName = getSaveZipFileName(file);
  560. if(saveZipFileName.isEmpty())
  561. return ;
  562. downloadFromRemote(saveZipFileName,ssid,dealstatus,neednum,updatedays);
  563. // QString cachePath = SNCDataBase::getShkjCachePath(ssid);
  564. // bool iscached = false;
  565. // if(!cachePath.isEmpty())
  566. // {
  567. // if(QFile::exists(cachePath))
  568. // {
  569. // iscached = true;
  570. // }
  571. // }
  572. // this->setCursor(Qt::WaitCursor);
  573. // if(iscached)
  574. // {
  575. // downloadFromLocal(saveZipFileName,cachePath);
  576. // }
  577. // else
  578. // {
  579. // downloadFromRemote(saveZipFileName,ssid,dealstatus,neednum);
  580. // }
  581. // this->setCursor(Qt::ArrowCursor);
  582. }
  583. void FormShkjFree::downloadFromLocal(QString saveFileName,QString cacheFile)
  584. {
  585. QFile::copy(cacheFile,saveFileName);
  586. QMessageBox::information(this,"提示","下载成功!",QMessageBox::Ok);
  587. }
  588. void FormShkjFree::downloadFromRemote(QString saveFileName, QString ssid, QString dealstatus, QString total,QString updatedays)
  589. {
  590. QString ssoHash = m_account.value("ssohash");
  591. qDebug()<<dealstatus<<total<<updatedays;
  592. QString json = m_cubews->userServiceVerify("DlZxshResultFile",QString("%1,%2,%3").arg(dealstatus).arg(total).arg(updatedays),ssoHash);
  593. RespUserServiceVerify response1(json);
  594. if(response1.getRtnCode()<=0)
  595. {
  596. QMessageBox::critical(this,"提示",response1.getRtnMemo(),QMessageBox::Ok);
  597. return ;
  598. }
  599. this->setCursor(Qt::WaitCursor);
  600. json = m_cubews->dlZxshResultFile(ssid,ssoHash);
  601. this->setCursor(Qt::ArrowCursor);
  602. RespDlZxshResultFile response(json);
  603. if(response.getRtnCode()==1)
  604. {
  605. QString fileContent = response.getFileContent();
  606. QByteArray array = QByteArray::fromBase64(fileContent.toAscii());
  607. qDebug()<<response.getFileName();
  608. QFile file(saveFileName);
  609. file.open(QIODevice::WriteOnly);
  610. file.write(array);
  611. file.close();
  612. ZxshDB::updateZxshDealStatus(ssid,"3");
  613. query();
  614. emit dataDownload();
  615. QMessageBox::information(this,"提示","下载成功!",QMessageBox::Ok);
  616. }
  617. else
  618. {
  619. QMessageBox::critical(this,"提示",response.getRtnMemo(),QMessageBox::Ok);
  620. }
  621. }
  622. QString FormShkjFree::getSaveZipFileName(QString qryID)
  623. {
  624. QFileDialog::Options options;
  625. QString selectedFilter;
  626. QString exportDir = SNCDataBase::getExportDir();
  627. if(exportDir.isEmpty())
  628. {
  629. QString path = QProcessEnvironment::systemEnvironment().value("HOMEDRIVE")+\
  630. QProcessEnvironment::systemEnvironment().value("HOMEPATH")+"\\DESKTOP";
  631. exportDir = path;
  632. }
  633. QString defaultZipFileName = QString("%1.zip").arg(qryID);
  634. QString saveZipFileName = QFileDialog::getSaveFileName(this,"另存为",exportDir + "\\" + defaultZipFileName,
  635. tr("ZIP Files (*.zip)"),
  636. &selectedFilter,
  637. options);
  638. if(!saveZipFileName.isEmpty())
  639. {
  640. QFileInfo fileInfo(saveZipFileName);
  641. exportDir = fileInfo.absolutePath();
  642. SNCDataBase::updateExportDir(exportDir);
  643. }
  644. return saveZipFileName;
  645. }
  646. QString FormShkjFree::cacheDownloadFile(QString fileName)
  647. {
  648. QString userCode = m_account.value("usercode");
  649. QString date = QDate::currentDate().toString("yyyyMM");
  650. QString cachePath = QCoreApplication::applicationDirPath()+\
  651. QString("/../data/%1/cache/shkj/download/%2/").arg(userCode).arg(date);
  652. QDir dir;
  653. dir.mkpath(cachePath);
  654. QFileInfo fileinfo(fileName);
  655. QFile::copy(fileName,cachePath + fileinfo.fileName());
  656. return cachePath + fileinfo.fileName();
  657. }
  658. bool FormShkjFree::chkAccountState(AccountLoginState state)
  659. {
  660. bool ret = false;
  661. switch(state)
  662. {
  663. case NotLogin:
  664. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  665. break;
  666. case NotBind:
  667. QMessageBox::critical(this,"提示","此项服务尚未开通,请开通后再操作!",QMessageBox::Ok);
  668. break;
  669. case LoginError:
  670. QMessageBox::critical(this,"提示","此项服务暂时无法连接,请稍候重试!",QMessageBox::Ok);
  671. break;
  672. default:
  673. ret = true;
  674. }
  675. return ret;
  676. }
  677. //void FormShkjFree::showDetailDialog(QString ltfid)
  678. //{
  679. // setCursor(Qt::WaitCursor);
  680. // QString fileName = QCoreApplication::applicationDirPath()+\
  681. // QString("/../data/%1/cache/shkj/upload/%2.rtn").arg(m_account.value("usercode")).arg(ltfid);
  682. // QFile file(fileName);
  683. // file.open(QIODevice::ReadOnly);
  684. // QTextStream in(&file);
  685. // QString content = in.readAll();
  686. // file.close();
  687. // if(content.isEmpty())
  688. // {
  689. // QMessageBox::information(this,"提示","号码已经全部接收!",QMessageBox::Ok);
  690. // }
  691. // else
  692. // {
  693. // DialogSubmitResponseDetail dialog;
  694. // dialog.setDetailText(content);
  695. // dialog.exec();
  696. // }
  697. // setCursor(Qt::ArrowCursor);
  698. //}
  699. //void FormShkjFree::on_pushButtonDownload_clicked()
  700. //{
  701. // if(!chkAccountState(m_state))
  702. // return ;
  703. // download(m_curLtfid,m_curQryid);
  704. //}
  705. //void FormShkjFree::on_tableWidget_cellDoubleClicked(int row, int column)
  706. //{
  707. // if(!chkAccountState(m_state))
  708. // return ;
  709. // download(m_curLtfid,m_curQryid);
  710. //}
  711. void FormShkjFree::on_pushButtonDel_clicked()
  712. {
  713. if(!chkAccountState(m_state))
  714. return ;
  715. bool nodata = true;
  716. for(int i=0;i<ui->tableWidget->rowCount();i++)
  717. {
  718. QTableWidgetItem *item = ui->tableWidget->item(i,0);
  719. if(item)
  720. {
  721. if(item->checkState()==Qt::Checked)
  722. {
  723. nodata = false;
  724. }
  725. }
  726. }
  727. if(nodata)
  728. {
  729. QMessageBox::critical(this,"提示","请选择要删除的单子",QMessageBox::Ok);
  730. return ;
  731. }
  732. if(QMessageBox::Yes!=QMessageBox::question(NULL,
  733. "确认",
  734. QString("您确定要删除吗?")
  735. ,QMessageBox::Yes,QMessageBox::No))
  736. {
  737. return ;
  738. }
  739. for(int i=0;i<ui->tableWidget->rowCount();i++)
  740. {
  741. QTableWidgetItem *item = ui->tableWidget->item(i,0);
  742. if(item)
  743. {
  744. if(item->checkState()==Qt::Checked)
  745. {
  746. QString id = item->data(Qt::UserRole).toString();
  747. ZxshDB::delShkjZxshTaskByID(id);
  748. }
  749. }
  750. }
  751. query();
  752. }
  753. //void FormShkjFree::on_checkBox_clicked()
  754. //{
  755. // Qt::CheckState state;
  756. // state = ui->checkBox->checkState();
  757. // for(int i=0;i<ui->tableWidget->rowCount();i++)
  758. // {
  759. // QTableWidgetItem *item = ui->tableWidget->item(i,0);
  760. // if(item)
  761. // {
  762. // item->setCheckState(state);
  763. // }
  764. // }
  765. //}
  766. void FormShkjFree::on_pushButtonQuery_clicked()
  767. {
  768. if(!chkAccountState(m_state))
  769. return ;
  770. query();
  771. }
  772. void FormShkjFree::on_tableWidget_clicked(const QModelIndex &index)
  773. {
  774. if(index.column()==0)
  775. {
  776. QTableWidgetItem *item = ui->tableWidget->item(index.row(),index.column());
  777. if(item)
  778. {
  779. if(item->checkState()==Qt::Checked)
  780. {
  781. ui->tableWidget->selectRow(index.row());
  782. }
  783. else
  784. {
  785. ui->tableWidget->selectRow(index.row());
  786. }
  787. }
  788. }
  789. }
  790. void FormShkjFree::on_tableWidget_itemSelectionChanged()
  791. {
  792. for(int i=0;i<ui->tableWidget->rowCount();i++)
  793. {
  794. QTableWidgetItem *item = ui->tableWidget->item(i,0);
  795. if(item->isSelected())
  796. {
  797. item->setCheckState(Qt::Checked);
  798. }
  799. else
  800. {
  801. item->setCheckState(Qt::Unchecked);
  802. }
  803. }
  804. }
  805. void FormShkjFree::on_checkBox_clicked()
  806. {
  807. WSSSO sso;
  808. QString json = sso.getServerTime();
  809. RespGetServerTime resp(json);
  810. m_srvtime = resp.getServerTime();
  811. for(int i=0;i<ui->tableWidget->rowCount();i++)
  812. {
  813. QTableWidgetItem *item = ui->tableWidget->item(i,0);
  814. if(item)
  815. {
  816. if(ui->checkBox->isChecked())
  817. {
  818. // QString optdate,dealstatus;
  819. // optdate = ui->tableWidget->item(i,1)->data(Qt::UserRole).toString();
  820. // dealstatus = ui->tableWidget->item(i,8)->data(Qt::UserRole).toString();
  821. // if(dealstatus=="2" || dealstatus=="3")
  822. // {
  823. // QDateTime now;
  824. // if(m_srvtime.isEmpty())
  825. // now = QDateTime::currentDateTime();
  826. // else
  827. // now = QDateTime::fromString(m_srvtime,"yyyy-MM-dd hh:mm:ss");
  828. // QDateTime then = QDateTime::fromString(optdate,"yyyy-MM-dd hh:mm:ss");
  829. // qDebug()<<then.daysTo(now)<<then<<now<<optdate;
  830. // if(then.daysTo(now)<=30)
  831. // {
  832. // item->setCheckState(Qt::Checked);
  833. // }
  834. // }
  835. item->setCheckState(Qt::Checked);//modify by xxw on 2017-8-20 fix bug select all
  836. }
  837. else
  838. {
  839. item->setCheckState(Qt::Unchecked);
  840. }
  841. }
  842. }
  843. }
  844. void FormShkjFree::on_pushButtonBatchDown_clicked()
  845. {
  846. if(!chkAccountState(m_state))
  847. return;
  848. int selected = 0;
  849. QString defaultZipName;
  850. QString errText;
  851. errText = "";
  852. defaultZipName = "batch";
  853. int num = 0;
  854. for(int i=0;i<ui->tableWidget->rowCount();i++)
  855. {
  856. QTableWidgetItem *item = ui->tableWidget->item(i,0);
  857. if(item)
  858. {
  859. QString ssid;
  860. QString optdate;
  861. QString dealstatus;
  862. QString province;
  863. QString city;
  864. QString updatedays;
  865. QString isp;
  866. QString neednum;
  867. QString rpnum;
  868. if(item->checkState()==Qt::Checked)
  869. {
  870. num++;
  871. //ui->batchDlHint->setText(QString("正在分析第 %1 个文件,请稍候").arg(num));
  872. ssid = item->data(Qt::UserRole).toString();
  873. optdate = ui->tableWidget->item(i,1)->data(Qt::UserRole).toString();
  874. province = ui->tableWidget->item(i,2)->data(Qt::UserRole).toString();
  875. city = ui->tableWidget->item(i,3)->data(Qt::UserRole).toString();
  876. updatedays = ui->tableWidget->item(i,4)->data(Qt::UserRole).toString();
  877. isp = ui->tableWidget->item(i,5)->data(Qt::UserRole).toString();
  878. neednum = ui->tableWidget->item(i,6)->data(Qt::UserRole).toString();
  879. rpnum = ui->tableWidget->item(i,7)->data(Qt::UserRole).toString();
  880. dealstatus = ui->tableWidget->item(i,8)->data(Qt::UserRole).toString();
  881. selected++;
  882. if(dealstatus=="2" || dealstatus=="3")
  883. {
  884. if (num <= 10)
  885. defaultZipName += "_"+ssid;
  886. QDateTime now = QDateTime::currentDateTime();
  887. QDateTime then = QDateTime::fromString(optdate,"yyyy-MM-dd hh:mm:ss");
  888. qDebug()<<then.daysTo(now)<<then<<now<<optdate;
  889. if(then.daysTo(now)>30)
  890. {
  891. errText += QString("您选择第%1个文件,已经过期(有效期1个月),无法下载!\r\n").arg(i+1);
  892. }
  893. }
  894. else
  895. {
  896. errText += QString("您选择第%1个文件,还未处理完毕,无法下载!\r\n").arg(i+1);
  897. }
  898. }
  899. }
  900. }
  901. //ui->batchDlHint->setText("");
  902. if (num > 10)
  903. defaultZipName += "_more";
  904. if(selected==0)
  905. {
  906. QMessageBox::critical(this,"提示","请选择要下载的数据!",QMessageBox::Ok);
  907. return ;
  908. }
  909. if(!errText.isEmpty())
  910. {
  911. QMessageBox::critical(this,"提示",errText,QMessageBox::Ok);
  912. return ;
  913. }
  914. defaultZipName += "_"+QString::number(selected);
  915. QFileDialog::Options options;
  916. QString selectedFilter;
  917. QString exportDir = SNCDataBase::getExportDir();
  918. QString saveZipFileName = QFileDialog::getSaveFileName(this,"另存为",exportDir + "\\" + defaultZipName,
  919. tr("ZIP Files (*.zip)"),
  920. &selectedFilter,
  921. options);
  922. if(!saveZipFileName.isEmpty())
  923. {
  924. QFileInfo fileInfo(saveZipFileName);
  925. exportDir = fileInfo.absolutePath();
  926. SNCDataBase::updateExportDir(exportDir);
  927. }
  928. else
  929. {
  930. return;
  931. }
  932. QDir dir;
  933. if(!dir.exists(QDir::tempPath()+"/speednumcube"))
  934. {
  935. dir.mkdir(QDir::tempPath()+"/speednumcube");
  936. }
  937. QString tmpDir = QDir::tempPath()+"/speednumcube/";
  938. QStringList files;
  939. ui->pushButtonBatchDown->setEnabled(false);
  940. this->setCursor(Qt::WaitCursor);
  941. num = 0;
  942. for(int i=0;i<ui->tableWidget->rowCount();i++)
  943. {
  944. QTableWidgetItem *item = ui->tableWidget->item(i,0);
  945. QString ssid;
  946. QString dealstatus;
  947. QString province;
  948. QString city;
  949. QString updatedays;
  950. QString isp;
  951. QString neednum;
  952. QString rpnum;
  953. if(item->checkState()==Qt::Checked)
  954. {
  955. num++;
  956. ui->batchDlHint->setText(QString("正在下载第 %1 个文件,请稍候").arg(num));
  957. ssid = item->data(Qt::UserRole).toString();
  958. province = ui->tableWidget->item(i,2)->data(Qt::UserRole).toString();
  959. city = ui->tableWidget->item(i,3)->data(Qt::UserRole).toString();
  960. updatedays = ui->tableWidget->item(i,4)->data(Qt::UserRole).toString();
  961. isp = ui->tableWidget->item(i,5)->data(Qt::UserRole).toString();
  962. neednum = ui->tableWidget->item(i,6)->data(Qt::UserRole).toString();
  963. rpnum = ui->tableWidget->item(i,7)->data(Qt::UserRole).toString();
  964. dealstatus = ui->tableWidget->item(i,8)->data(Qt::UserRole).toString();
  965. QString fileName;
  966. fileName = downloadFromRemoteForBatch(tmpDir, ssid, dealstatus,neednum,updatedays);
  967. if(!fileName.isEmpty())
  968. {
  969. files.append(fileName);
  970. }
  971. }
  972. }
  973. ui->batchDlHint->setText("批量下载完成!");
  974. this->setCursor(Qt::ArrowCursor);
  975. if(files.size()>0)
  976. {
  977. if(addFileToZip(saveZipFileName,files))
  978. {
  979. QMessageBox::information(this,"结果",QString("您选择%1个文件,%2个文件下载成功!")\
  980. .arg(selected).arg(files.size()),QMessageBox::Ok);
  981. QFileInfo fileinfo(saveZipFileName);
  982. SNCDataBase::updateExportDir(fileinfo.absolutePath());
  983. }
  984. else
  985. {
  986. QMessageBox::critical(this,"结果","文件下载失败!",QMessageBox::Ok);
  987. }
  988. }
  989. else
  990. {
  991. QMessageBox::critical(this,"结果","文件下载失败!",QMessageBox::Ok);
  992. }
  993. ui->pushButtonBatchDown->setEnabled(true);
  994. query(); //数据刷新 add by wzx
  995. }
  996. QString FormShkjFree::downloadFromRemoteForBatch(QString savePath, QString ssid, QString dealstatus, QString total,QString updatedays)
  997. {
  998. QString ssoHash = m_account.value("ssohash");
  999. qDebug()<<dealstatus<<total<<updatedays;
  1000. QString json = m_cubews->userServiceVerify("DlZxshResultFile",QString("%1,%2,%3").arg(dealstatus).arg(total).arg(updatedays),ssoHash);
  1001. QString saveFileName;
  1002. saveFileName = "";
  1003. RespUserServiceVerify response1(json);
  1004. // if(response1.getRtnCode()<=0)
  1005. // {
  1006. // QMessageBox::critical(this,"提示",response1.getRtnMemo(),QMessageBox::Ok);
  1007. // return saveFileName;
  1008. // }
  1009. this->setCursor(Qt::WaitCursor);
  1010. json = m_cubews->dlZxshResultFile(ssid,ssoHash);
  1011. this->setCursor(Qt::ArrowCursor);
  1012. RespDlZxshResultFile response(json);
  1013. if(response.getRtnCode()==1)
  1014. {
  1015. QString fileContent = response.getFileContent();
  1016. QByteArray array = QByteArray::fromBase64(fileContent.toAscii());
  1017. saveFileName = savePath + response.getFileName();
  1018. QFile file(saveFileName);
  1019. file.open(QIODevice::WriteOnly);
  1020. file.write(array);
  1021. file.close();
  1022. ZxshDB::updateZxshDealStatus(ssid,"3");
  1023. return saveFileName;
  1024. }
  1025. else
  1026. {
  1027. QMessageBox::critical(this,"提示",response.getRtnMemo(),QMessageBox::Ok);
  1028. return saveFileName;
  1029. }
  1030. }
  1031. bool FormShkjFree::addFileToZip(QString zipName, QStringList files)
  1032. {
  1033. Zip::ErrorCode ec;
  1034. Zip uz;
  1035. QFile file(zipName);
  1036. if(!file.open(QIODevice::WriteOnly)){
  1037. return false ;
  1038. }
  1039. file.close();
  1040. ec = uz.createArchive(zipName);
  1041. if (ec != Zip::Ok) {
  1042. return false;
  1043. }
  1044. ec = uz.addFiles(files);
  1045. if (ec != Zip::Ok) {
  1046. uz.closeArchive();
  1047. return false;
  1048. }
  1049. if (uz.closeArchive() != Zip::Ok) {
  1050. return false;
  1051. }
  1052. return true;
  1053. }
  1054. //add by wzx
  1055. QString FormShkjFree::getIsDown()
  1056. {
  1057. QString isdown;
  1058. if(ui->radioButtonAll->isChecked())
  1059. isdown = "0";
  1060. else if(ui->radioButtonDown->isChecked())
  1061. isdown = "1";
  1062. else if(ui->radioButtonNoDown->isChecked())
  1063. isdown = "2";
  1064. else
  1065. isdown = "0";
  1066. return isdown;
  1067. }
  1068. void FormShkjFree::on_radioButtonAll_clicked()
  1069. {
  1070. query();
  1071. }
  1072. void FormShkjFree::on_radioButtonDown_clicked()
  1073. {
  1074. query();
  1075. }
  1076. void FormShkjFree::on_radioButtonNoDown_clicked()
  1077. {
  1078. query();
  1079. }