ChannelTaskRes.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * resources.getEntityManagerContainer() // 实体管理容器.
  3. * resources.getContext() //上下文根.
  4. * resources.getOrganization() //组织访问接口.
  5. * requestText //请求内容.
  6. * request //请求对象.
  7. */
  8. print("远程调用:渠道任务接收拒绝实时接口");
  9. var File = Java.type('java.io.File');
  10. var Root_Dir_Record = "D:"+File.separator+'FTPFile'+ File.separator + "ChannelTaskRecorder" + File.separator ;
  11. var recordFile = null;
  12. var BranchWorkId = null;
  13. var pw = null;
  14. function createRecordFile(){
  15. if( BranchWorkId == null )return;
  16. var Date = Java.type( "java.util.Date" );
  17. var now = new Date();
  18. var recordPath = Root_Dir_Record +
  19. new java.text.SimpleDateFormat("yyyy").format(now) + File.separator +
  20. new java.text.SimpleDateFormat("MM").format(now) + File.separator +
  21. new java.text.SimpleDateFormat("dd").format(now) + File.separator + "Res";
  22. var recordDir = new File(recordPath);
  23. if (!recordDir.exists()) {
  24. if(!recordDir.mkdirs()){
  25. print( "创建记录文件夹失败:"+ recordPath );
  26. recordDir = null;
  27. }
  28. }
  29. if( recordDir !== null ){
  30. var recordFilePath = recordPath + File.separator + BranchWorkId + ".txt";
  31. recordFile = new File(recordFilePath);
  32. if (recordFile.exists()) { // 如果已存在,删除旧文件
  33. recordFile.delete();
  34. }
  35. if(!recordFile.createNewFile()){
  36. print("不能记录文件:"+recordFilePath);
  37. recordFile = null;
  38. }else{
  39. print("创建记录文件:"+recordFilePath);
  40. }
  41. }
  42. }
  43. function printRecorder( text, notPrint ){
  44. if( !notPrint )print(text);
  45. if( BranchWorkId == null )return;
  46. if( recordFile === null )createRecordFile();
  47. if( recordFile === null )return;
  48. if( pw === null )pw = new java.io.PrintWriter(recordFile, "GBK");
  49. pw.print( text );
  50. pw.write(0x0d);
  51. pw.write(0x0a);
  52. }
  53. function getPureText( str ){
  54. if( str === null )return str;
  55. if( str.substr( 0 , 1 ) === "\"" ){
  56. str = str.substr( 1, str.length - 1 );
  57. }
  58. if( str.substr( str.length - 1 , 1 ) === "\"" ){
  59. str = str.substr( 0, str.length - 1 );
  60. }
  61. return str;
  62. }
  63. function getWorkCompltedId( branchWorkId ){
  64. var filterList = {"filterList": [{
  65. "logic":"and",
  66. "path": "branchWorkId",
  67. "title": "branchWorkId",
  68. "comparison":"equals",
  69. "comparisonTitle":"等于",
  70. "value": branchWorkId,
  71. "formatType":"textValue"
  72. }]};
  73. var json = resources.getWebservicesClient().jaxrsPut('x_query_assemble_surface', "view/flag/workCompletedByBranch/query/channelTask/execute", JSON.stringify( filterList ) );
  74. //var json = resources.getWebservicesClient().jaxrsGet('x_processplatform_assemble_surface', "data/workcompleted/e8db5cba-2d35-4b91-86a2-6c482ed7da55" );
  75. var obj = json.getAsJsonObject();
  76. var grid = obj.get("grid");
  77. if( grid ){
  78. printRecorder("grid="+grid);
  79. var workData = grid.getAsJsonArray();
  80. if( workData.size() > 0 ){
  81. printRecorder("workData="+workData);
  82. var data = workData.get(0);
  83. if( data && data != null ){
  84. var d = data.get("data");
  85. if( d && d!=null ){
  86. var workCompletedId = d.get("workCompletedId");
  87. if( workCompletedId && workCompletedId != null ){
  88. workCompletedId = getPureText(workCompletedId.toString());
  89. return workCompletedId;
  90. }
  91. }
  92. }
  93. }
  94. }
  95. return null;
  96. }
  97. function setWorkData( branchWorkId, dateStr, Task_state ){
  98. var workCompletedId = getWorkCompltedId(branchWorkId);
  99. var text = null;
  100. if( workCompletedId === null ){
  101. text = "根据Sub_task_id'"+branchWorkId+"'不能获取文件";
  102. printRecorder(text);
  103. return text;
  104. }else{
  105. printRecorder("根据branchWorkId'"+branchWorkId+"'获取workCompletedId为"+workCompletedId);
  106. printRecorder( "文件URL:../x_desktop/work.html?workcompletedid="+workCompletedId );
  107. }
  108. var webservicesClient = resources.getWebservicesClient();
  109. try{
  110. webservicesClient.jaxrsPut('x_processplatform_assemble_surface', "data/workcompleted/"+workCompletedId+"/interfaceResTime", dateStr );
  111. webservicesClient.jaxrsPut('x_processplatform_assemble_surface', "data/workcompleted/"+workCompletedId+"/interfaceResStat", Task_state );
  112. printRecorder( "branchWorkId='" + branchWorkId + "' workCompletedId='" + workCompletedId +"'的工作保存完毕" );
  113. return null;
  114. }catch(e){
  115. return e.getMessage();
  116. }
  117. }
  118. function init(){
  119. //var re = {
  120. // "head": {
  121. // "sign" : {
  122. // "service_name" : "ChannelTaskRes",
  123. // "Trans_ido" : "20170724013901"
  124. // }
  125. // },
  126. // "body" : {
  127. // "msg" : {
  128. // "Task_id" : "be4b9546-158b-4c3f-85a5-49d266c7df23",
  129. // "Sub_task_id" : "be4b9546-158b-4c3f-85a5-49d266c7df23",
  130. // "Task_ state" : "1",
  131. // "Time" : "20170724013901"
  132. // }
  133. // }
  134. //}
  135. var text="";
  136. var Trans_ido="";
  137. var Response_code;
  138. try{
  139. print( "requestText="+requestText );
  140. var requestJson = JSON.parse(requestText);
  141. print( "type of requestJson = " + typeof( requestJson ));
  142. if( typeof(requestJson) === "string" ){
  143. requestJson = JSON.parse(requestJson);
  144. }
  145. Trans_ido = requestJson.head.sign.Trans_ido;
  146. var Sub_task_id = requestJson.body.msg.Sub_task_id;
  147. BranchWorkId = Sub_task_id;
  148. var Task_state = requestJson.body.msg.Task_state;
  149. var Time = requestJson.body.msg.Time;
  150. if( BranchWorkId && BranchWorkId != null && BranchWorkId != "" ){
  151. printRecorder( "requestText="+requestText, true );
  152. }
  153. text = setWorkData( Sub_task_id, Time, Task_state );
  154. if( text == null ){
  155. Response_code = "0000";
  156. }else{
  157. Response_code = "8888";
  158. }
  159. }catch(e){
  160. Response_code = "8888";
  161. e.printStackTrace();
  162. if( pw == null ){
  163. print(e.getMessage())
  164. }else{
  165. printRecorder(e.getMessage())
  166. }
  167. text = e.getMessage();
  168. }finally{
  169. var Response_desc = "成功";
  170. if( Response_code == "8888" ){
  171. Response_desc = text || "反馈错误"
  172. }
  173. var responseText = {
  174. "head": {
  175. "sign" : {
  176. "service_name" : "ChannelTaskRes",
  177. "Trans_ido" : Trans_ido
  178. }
  179. },
  180. "body" : {
  181. "msg" : {
  182. "Response_code" : Response_code,
  183. "Response_desc" : Response_desc
  184. }
  185. }
  186. };
  187. if( pw == null ){
  188. print("responseText="+JSON.stringify(responseText))
  189. }else{
  190. printRecorder("responseText="+JSON.stringify(responseText));
  191. pw.close();
  192. }
  193. return responseText;
  194. }
  195. }
  196. init();