test_query.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 tid = 5161, sOrder = 9;
  14. const stage = await querySql('SELECT * FROM zh_stage where tid = ? and `order` = ?', [tid, sOrder]);
  15. const rptArchive = await querySql('SELECT * FROM zh_rpt_archive where stage_id = ?', [stage[0].id]);
  16. for (const ra of rptArchive) {
  17. ra.content = ra.content ? JSON.parse(ra.content) : [];
  18. console.log(BaseUtil.getFileName('rptArchive.json'));
  19. await saveJSON(ra, BaseUtil.getFileName('rptArchive.json'));
  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.parse(rptRole[0].rel_content));
  25. // }
  26. // }
  27. // await saveJSON(roleContent, BaseUtil.getFileName('roleContent.json'));
  28. }
  29. const roleContent = [];
  30. const rptRole = await querySql('SELECT * FROM zh_role_rpt_rel WHERE sid = ?', [stage[0].id]);
  31. for (const rp of rptRole) {
  32. if (rp.rel_content) roleContent.push(JSON.parse(rp.rel_content));
  33. }
  34. await saveJSON(roleContent, BaseUtil.getFileName('roleContent.json'));
  35. const rptSign = await querySql('SELECT * FROM zh_rpt_archive_encryption where stage_id = ?', [stage[0].id]);
  36. for (const rs of rptSign) {
  37. rs.content = rs.content ? JSON.parse(rs.content) : [];
  38. console.log(BaseUtil.getFileName('rptSign.json'));
  39. await saveJSON(rs, BaseUtil.getFileName('rptSign.json'));
  40. }
  41. };
  42. const findRole = async function() {
  43. const role = await querySql('SELECT * FROM zh_role_rpt_rel');
  44. for (const r of role) {
  45. const roleContent = r.rel_content ? JSON.parse(r.rel_content) : [];
  46. for (const rc of roleContent) {
  47. if (rc.sign_date) console.log(rc.sign_date, rc.sign_date_format);
  48. }
  49. }
  50. };
  51. const doCompleteTest = async function() {
  52. try {
  53. await loadReportArchiveData();
  54. // await findRole();
  55. } catch (err) {
  56. console.log(err);
  57. }
  58. BaseUtil.closePool();
  59. };
  60. doCompleteTest();