报备.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // /cncc/action/report JSON数据导入程序
  2. // 2022-09-29T07:53:58.254Z 由 JsonImportGen.js 自动生成,请勿手动修改
  3. // 输入输出参数格式化
  4. input = INPUT;
  5. try {
  6. input = decodeURIComponent(input);
  7. } catch(e) {}
  8. try {
  9. input = base64.decode(input);
  10. } catch(e) {}
  11. try {
  12. input = JSON.parse(input);
  13. input = JSON.parse(input);
  14. } catch(e) {}
  15. output = {};
  16. istesting = false;
  17. function teststore() {
  18. // 输入JSON临时存入DFS
  19. dir = "/opt/cncc/action/report";
  20. dtm = new Date().toJSON().replace(/[\-\:\.TZ ]/mg, "");
  21. fn = dir + "/" + dtm;
  22. if (input.id) {
  23. fn += "." + input.id;
  24. } else {
  25. fn += "_" + _.random(0, 1000000);
  26. }
  27. fn += ".json";
  28. dfs.write(fn, JSON.stringify(input, " ", 4));
  29. output.filename = fn;
  30. // 刪除旧交件
  31. files = dfs.readdir(dir);
  32. dt = Date.now() - 1000 * 3600 * 24 * 10;
  33. for (i = 0; i < files.length; i++) {
  34. if (files[i].mtime < dt) {
  35. dfs.remove(files[i].fullname);
  36. }
  37. }
  38. // 留最后10个
  39. files.sort(function(a,b){ return a.mtime-b.mtime; });
  40. for (i = 0; i < files.length-10; i++) {
  41. dfs.remove(files[i].fullname);
  42. }
  43. }
  44. // 主执行阶段
  45. try {
  46. if (istesting) {
  47. teststore();
  48. }
  49. // 数据合法性检查
  50. if (!input.id) {
  51. throw ("输入参数必须为对象,且指定属性id");
  52. }
  53. if (!input.idUnique) {
  54. throw ("输入参数必须为对象,且指定属性idUnique");
  55. }
  56. // mql定义
  57. mql = `insert into /cncc/action/report (
  58. j_accept_group_dep_id,
  59. j_accept_group_dep_name,
  60. j_accept_user_dep_id,
  61. j_accept_user_dep_name,
  62. j_accept_user_group,
  63. j_accept_user_group_id,
  64. j_accept_user_id,
  65. j_accept_user_real_name,
  66. j_close_time,
  67. j_countersign_dep_id_list,
  68. j_countersign_dep_name_list,
  69. j_countersign_role_id_list,
  70. j_countersign_role_name_list,
  71. j_create_time,
  72. j_create_user_dep_id,
  73. j_create_user_dep_name,
  74. j_create_user_id,
  75. j_create_user_real_name,
  76. j_current_process_user_id,
  77. j_current_process_user_real_name,
  78. j_data_center_id_list,
  79. j_data_center_name_list,
  80. j_expected_end_time,
  81. j_expected_start_time,
  82. j_id_unique,
  83. j_is_countersign,
  84. j_is_valid,
  85. j_participator_report_content_handle,
  86. j_process_current_user_list,
  87. j_process_definition_key,
  88. j_process_instance_id,
  89. j_process_status_name_list,
  90. j_regulation_type,
  91. j_report_content,
  92. j_report_source,
  93. j_report_status,
  94. j_report_summary,
  95. j_report_type,
  96. j_report_user_contact,
  97. j_reportcol,
  98. j_update_time,
  99. jid
  100. ) values (
  101. ?,
  102. ?,
  103. ?,
  104. ?,
  105. ?,
  106. ?,
  107. ?,
  108. ?,
  109. ?,
  110. ?,
  111. ?,
  112. ?,
  113. ?,
  114. ?,
  115. ?,
  116. ?,
  117. ?,
  118. ?,
  119. ?,
  120. ?,
  121. ?,
  122. ?,
  123. ?,
  124. ?,
  125. ?,
  126. ?,
  127. ?,
  128. ?,
  129. ?,
  130. ?,
  131. ?,
  132. ?,
  133. ?,
  134. ?,
  135. ?,
  136. ?,
  137. ?,
  138. ?,
  139. ?,
  140. ?,
  141. ?,
  142. ?
  143. )`;
  144. // 执行mql
  145. ret = odb.mql(mql,
  146. JSON.stringify(input.acceptGroupDepId, " ", 4), // null
  147. JSON.stringify(input.acceptGroupDepName, " ", 4), // null
  148. JSON.stringify(input.acceptUserDepId, " ", 4), // null
  149. ""+input.acceptUserDepName, // 支付系统事业部>运维系统部
  150. JSON.stringify(input.acceptUserGroup, " ", 4), // null
  151. JSON.stringify(input.acceptUserGroupId, " ", 4), // null
  152. input.acceptUserId, // 605
  153. ""+input.acceptUserRealName, // 杨春雷
  154. input.closeTime, // null
  155. JSON.stringify(input.countersignDepIdList, " ", 4), // null
  156. JSON.stringify(input.countersignDepNameList, " ", 4), // null
  157. ""+input.countersignRoleIdList, //
  158. ""+input.countersignRoleNameList, //
  159. input.createTime, // 2022-09-27 09:00:43
  160. input.createUserDepId, // 92
  161. ""+input.createUserDepName, // 支付系统事业部>运维系统部
  162. input.createUserId, // 605
  163. ""+input.createUserRealName, // 杨春雷
  164. JSON.stringify(input.currentProcessUserId, " ", 4), // null
  165. JSON.stringify(input.currentProcessUserRealName, " ", 4), // null
  166. ""+input.dataCenterIdList, // 261
  167. ""+input.dataCenterNameList, // 北京NPC
  168. input.expectedEndTime, // 2022-09-28 00:00:00
  169. input.expectedStartTime, // 2022-09-27 00:00:00
  170. ""+input.idUnique, // RX1000007047
  171. input.isCountersign, // 0
  172. input.isValid, // 1
  173. JSON.stringify(input.participatorReportContentHandle, " ", 4), // null
  174. ""+input.processCurrentUserList, // 杨春雷
  175. JSON.stringify(input.processDefinitionKey, " ", 4), // null
  176. ""+input.processInstanceId, // 1539041
  177. ""+input.processStatusNameList, // 创建人提出报备
  178. ""+input.regulationType, // 支付系统
  179. ""+input.reportContent, // 报备内容
  180. JSON.stringify(input.reportSource, " ", 4), // null
  181. ""+input.reportStatus, //
  182. ""+input.reportSummary, // 报备摘要
  183. ""+input.reportType, // 参与者
  184. JSON.stringify(input.reportUserContact, " ", 4), // null
  185. JSON.stringify(input.reportcol, " ", 4), // null
  186. input.updateTime, // 2022-09-27 09:01:28
  187. input.id // 1000007047
  188. );
  189. // 打印完成信息
  190. output.info={
  191. id: input.id,
  192. idUnique: input.idUnique
  193. };
  194. log.info(output.info);
  195. } catch(e) {
  196. if (typeof(e) == "object") {
  197. output.error = e;
  198. } else if (typeof(e) == "string") {
  199. output.error = "插库错误:" + e;
  200. } else {
  201. output.error = JSON.stringify(e);
  202. }
  203. log.error(output.error);
  204. }
  205. // 返回输出信息
  206. OUTPUT = output;