test_query.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // 计算变更令,正负变更数
  2. const defaultInfo = require('../app/const/tender_info');
  3. const BaseUtil = require('./baseUtils');
  4. const querySql = BaseUtil.querySql;
  5. const ZhCalc = BaseUtil.ZhCalc;
  6. const saveJSON = async function(obj, file) {
  7. let defineStr = JSON.stringify(obj, '', '\t');
  8. await BaseUtil.saveBufferFile(defineStr, file);
  9. };
  10. const loadReportArchiveData = async function() {
  11. //const tid = 4417, sOrder = 2;
  12. const tid = 3698, sOrder = 7;
  13. const stage = await querySql('SELECT * FROM zh_stage where tid = ? and `order` = ?', [tid, sOrder]);
  14. const rptArchive = await querySql('SELECT * FROM zh_rpt_archive where stage_id = ?', [stage[0].id]);
  15. for (const ra of rptArchive) {
  16. ra.content = ra.content ? JSON.parse(ra.content) : [];
  17. console.log(BaseUtil.getFileName('rptArchive.json'));
  18. await saveJSON(ra, BaseUtil.getFileName('rptArchive.json'));
  19. const roleContent = [];
  20. for (const c of ra.content) {
  21. console.log(c.rpt_id, stage[0].id);
  22. const rptRole = await querySql('SELECT * FROM zh_role_rpt_rel WHERE sid = ? and rpt_id = ?', [stage[0].id, c.rpt_id]);
  23. if (rptRole.length > 0) {
  24. if (rptRole[0].rel_content) roleContent.push(JSON.stringify(rptRole[0].rel_content));
  25. }
  26. }
  27. await saveJSON(roleContent, BaseUtil.getFileName('roleContent.json'));
  28. }
  29. const rptSign = await querySql('SELECT * FROM zh_rpt_archive_encryption where stage_id = ?', [stage[0].id]);
  30. for (const rs of rptSign) {
  31. rs.content = rs.content ? JSON.parse(rs.content) : [];
  32. console.log(BaseUtil.getFileName('rptSign.json'));
  33. await saveJSON(rs, BaseUtil.getFileName('rptSign.json'));
  34. }
  35. };
  36. const doCompleteTest = async function() {
  37. try {
  38. await loadReportArchiveData();
  39. } catch (err) {
  40. console.log(err);
  41. }
  42. BaseUtil.closePool();
  43. };
  44. doCompleteTest();