test_query.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 = 11;
  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. if (rptArchive.indexOf(ra) === 0) {
  29. const rptTpl = await querySql('SELECT * FROM zh_rpt_tpl where id = ?', [ra.content[0].rpt_id]);
  30. rptTpl[0].rpt_content = rptTpl[0].rpt_content ? JSON.parse(rptTpl[0].rpt_content) : {};
  31. console.log('rptTpl.json');
  32. await saveJSON(rptTpl[0], BaseUtil.getFileName('rptTpl.json'));
  33. }
  34. }
  35. const roleContent = [];
  36. const rptRole = await querySql('SELECT * FROM zh_role_rpt_rel WHERE sid = ?', [stage[0].id]);
  37. for (const rp of rptRole) {
  38. if (rp.rel_content) roleContent.push(JSON.parse(rp.rel_content));
  39. }
  40. await saveJSON(roleContent, BaseUtil.getFileName('roleContent.json'));
  41. const rptSign = await querySql('SELECT * FROM zh_rpt_archive_encryption where stage_id = ?', [stage[0].id]);
  42. for (const rs of rptSign) {
  43. rs.content = rs.content ? JSON.parse(rs.content) : [];
  44. console.log(BaseUtil.getFileName('rptSign.json'));
  45. await saveJSON(rs, BaseUtil.getFileName('rptSign.json'));
  46. }
  47. };
  48. const findRole = async function() {
  49. const role = await querySql('SELECT * FROM zh_role_rpt_rel');
  50. for (const r of role) {
  51. const roleContent = r.rel_content ? JSON.parse(r.rel_content) : [];
  52. for (const rc of roleContent) {
  53. if (rc.sign_date) console.log(rc.sign_date, rc.sign_date_format);
  54. }
  55. }
  56. };
  57. const doCompleteTest = async function() {
  58. try {
  59. await loadReportArchiveData();
  60. // await findRole();
  61. } catch (err) {
  62. console.log(err);
  63. }
  64. BaseUtil.closePool();
  65. };
  66. doCompleteTest();