ChannelTaskDetail.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * resources.getEntityManagerContainer() // 实体管理容器.
  3. * resources.getContext() //上下文根.
  4. * resources.getOrganization() //组织访问接口.
  5. * requestText //请求内容.
  6. * request //请求对象.
  7. */
  8. printLog("运行代理渠道任务明细下发文件");
  9. load("nashorn:mozilla_compat.js");
  10. var File = Java.type('java.io.File');
  11. var Root_Dir = "D:"+File.separator+'FTPFile'+ File.separator + "ChannelTask" + File.separator + "Detail" + File.separator;
  12. var Root_Dir_Record = "D:"+File.separator+'FTPFile'+ File.separator + "ChannelTaskRecorder" + File.separator ;
  13. function getSeq( nowStr ){
  14. var str = resources.getWebservicesClient().jaxrsGet( "x_processplatform_assemble_surface",
  15. "applicationdict/ChannelTaskDetail_Seq/application/channelTaskProcess/seq/data" );
  16. str = getPureText( str.toString() );
  17. var arr = str.split("-");
  18. var seq = 0;
  19. if( arr.length > 1 && arr[0] === nowStr )seq = parseInt( arr[1] );
  20. seq ++;
  21. var seqStr = "0000" + seq;
  22. seqStr = seqStr.substr(seqStr.length - 4, 4 );
  23. resources.getWebservicesClient().jaxrsPut( "x_processplatform_assemble_surface",
  24. "applicationdict/ChannelTaskDetail_Seq/application/channelTaskProcess/seq/data", nowStr+"-"+seqStr );
  25. return seqStr;
  26. }
  27. function createRecordFloder(){
  28. var Date = Java.type( "java.util.Date" );
  29. var now = new Date();
  30. var recordPath = Root_Dir_Record +
  31. new java.text.SimpleDateFormat("yyyy").format(now) + File.separator +
  32. new java.text.SimpleDateFormat("MM").format(now) + File.separator +
  33. new java.text.SimpleDateFormat("dd").format(now) + File.separator + "Detail";
  34. var recordDir = new File(recordPath);
  35. if (!recordDir.exists()) {
  36. if(!recordDir.mkdirs()){
  37. print( "创建记录文件夹失败:"+ recordPath )
  38. return null;
  39. }
  40. }
  41. return recordDir;
  42. }
  43. function createFile(){
  44. var Date = Java.type( "java.util.Date" );
  45. var now = new Date();
  46. var nowStr = new java.text.SimpleDateFormat("yyyyMMdd").format(now);
  47. var seq = getSeq( nowStr );
  48. var path = Root_Dir + nowStr + '_ChannelTaskDetail_' + ( seq || '0001' ) + '.REQ';
  49. print( "path="+path );
  50. var file = new File(path );
  51. if (file.exists()) { // 如果已存在,删除旧文件
  52. file.delete();
  53. }
  54. if(!file.createNewFile()){
  55. printLog("不能创建文件:"+path);
  56. return null;
  57. }else{
  58. printLog("创建文件:"+path);
  59. return file;
  60. }
  61. }
  62. function printLog( text ){
  63. print( text );
  64. }
  65. function setWorkFlag( workCompletedId, fileName ){
  66. printLog( "设置标志位" );
  67. if( fileName === "" ){
  68. resources.getWebservicesClient().jaxrsPut('x_processplatform_assemble_surface', "data/workcompleted/"+workCompletedId+"/interfaceStatus", "detailNone" );
  69. }else{
  70. resources.getWebservicesClient().jaxrsPut('x_processplatform_assemble_surface', "data/workcompleted/"+workCompletedId+"/interfaceStatus", "detailDone" );
  71. resources.getWebservicesClient().jaxrsPut('x_processplatform_assemble_surface', "data/workcompleted/"+workCompletedId+"/File_Name", fileName );
  72. }
  73. }
  74. function getWorkData(){
  75. var filterList = {"filterList": [{
  76. "logic":"and",
  77. "path": "interfaceStatus",
  78. "title": "接口状态",
  79. "comparison":"equals",
  80. "comparisonTitle":"等于",
  81. "value": "wait",
  82. "formatType":"textValue"
  83. }]};
  84. //var filterList = {"filterList": [] };
  85. var json = resources.getWebservicesClient().jaxrsPut('x_query_assemble_surface', "view/flag/workCompletedByBranch/query/channelTask/execute", JSON.stringify( filterList ) );
  86. //var json = resources.getWebservicesClient().jaxrsGet('x_processplatform_assemble_surface', "data/workcompleted/e8db5cba-2d35-4b91-86a2-6c482ed7da55" );
  87. var obj = json.getAsJsonObject();
  88. return obj.get("grid");
  89. }
  90. function getNumberData( workId, branch ){
  91. var filterList = { filterList : [{
  92. "logic":"and",
  93. "path": "workId",
  94. "title": "workId",
  95. "comparison":"equals",
  96. "comparisonTitle":"等于",
  97. "value": workId,
  98. "formatType":"textValue"
  99. },{
  100. "logic":"and",
  101. "path": "branch",
  102. "title": "branch",
  103. "comparison":"equals",
  104. "comparisonTitle":"等于",
  105. "value": branch,
  106. "formatType":"textValue"
  107. }]};
  108. var json = resources.getWebservicesClient().jaxrsPut('x_query_assemble_surface', encodeURI("view/flag/byPhoneNumber/query/channelTask/execute"), JSON.stringify( filterList ) );
  109. //print( "getNumberData="+json.get("grid") );
  110. var grid = json.get("grid");
  111. return grid.getAsJsonArray();
  112. }
  113. function isEmpty( str ){
  114. if( str === null )return true;
  115. var s = str.trim();
  116. if( s === "\"\"" )return true;
  117. if( s.equals("\"\"") )return true;
  118. if( s === "" )return true;
  119. if( s.equals("") )return true;
  120. return false;
  121. }
  122. function getPureText( str ){
  123. if( str === null )return str;
  124. if( str.substr( 0 , 1 ) === "\"" ){
  125. str = str.substr( 1, str.length - 1 );
  126. }
  127. if( str.substr( str.length - 1 , 1 ) === "\"" ){
  128. str = str.substr( 0, str.length - 1 );
  129. }
  130. return str;
  131. }
  132. function ouputNumberList( numberList, workId, branchWorkId, numberCount ){
  133. var file = createFile();
  134. if( file === null )return null;
  135. printLog( "输出数据" );
  136. var pw = new java.io.PrintWriter(file, "GBK");
  137. //pw.print("TOTAL_NUM:");
  138. pw.print( numberCount || numberList.size() );
  139. pw.write(0x0d);
  140. pw.write(0x0a);
  141. pw.write(0x0d);
  142. pw.write(0x0a);
  143. var iter = numberList.iterator();
  144. //2、通过循环迭代
  145. //hasNext():判断是否存在下一个元素
  146. while(iter.hasNext()){
  147. //如果存在,则调用next实现迭代
  148. var obj = iter.next(); //把Object型强转成int型
  149. var data = obj.get("data");
  150. var number = getPureText( data.get("subject").toString() );
  151. //pw.print("SERIAL_NUMBER:");
  152. pw.print( number );
  153. pw.print("|");
  154. //pw.print("Task_id:");
  155. pw.print( workId );
  156. pw.print("|");
  157. //pw.print("Sub_task_id:");
  158. pw.print( branchWorkId );
  159. pw.write(0x0d);
  160. pw.write(0x0a);
  161. }
  162. pw.close();
  163. return file;
  164. }
  165. function init(){
  166. var FileUtils = Java.type( "org.apache.commons.io.FileUtils" );
  167. var workList = getWorkData();
  168. print( "workList="+workList );
  169. if( workList.size() > 0 ){
  170. var recorderDir = createRecordFloder();
  171. }
  172. var iter = workList.iterator();
  173. //2、通过循环迭代
  174. //hasNext():判断是否存在下一个元素
  175. while(iter.hasNext()){
  176. //如果存在,则调用next实现迭代
  177. var obj = iter.next(); //把Object型强转成int型
  178. var data = obj.get("data");
  179. var branch = data.get("currentUnit").toString();
  180. var workId = data.get("provinceWorkId").toString();
  181. if( isEmpty( workId ) )workId = data.get("cityWorkId").toString();
  182. if( isEmpty( workId ) )workId = data.get("countyWorkId").toString();
  183. if( isEmpty( workId ) )workId = data.get("branchWorkId").toString();
  184. var branchWorkId = data.get("branchWorkId").toString();
  185. var numberCount = data.get("numberCount").toString();
  186. var workCompletedId = data.get("workCompletedId").toString();
  187. workCompletedId = getPureText(workCompletedId);
  188. print("workId="+workId);
  189. print("branch="+branch);
  190. var file = null;
  191. if( !isEmpty( workId ) && !isEmpty( branch ) ){
  192. workId = getPureText( workId );
  193. branch = getPureText( branch );
  194. branchWorkId = getPureText( branchWorkId );
  195. numberCount = getPureText(numberCount);
  196. var numberList = getNumberData( workId, branch );
  197. if( numberList.size() > 0 ){
  198. file = ouputNumberList( numberList, workId, branchWorkId, numberCount );
  199. }else{
  200. print( '根据workId='+workId + ",branch="+ branch + "未找到号码!" );
  201. }
  202. }
  203. if( workCompletedId && workCompletedId !== "" && file!== null ){
  204. setWorkFlag(workCompletedId, file.getName());
  205. if( recorderDir!==null ){
  206. try{
  207. FileUtils.copyFileToDirectory( file, recorderDir );
  208. print("明细文件拷贝到记录文件夹成功:"+recorderDir.getCanonicalPath());
  209. }catch(e){
  210. e.printStackTrace();
  211. print("明细文件拷贝到记录文件夹出错:"+recorderDir.getCanonicalPath() + " 错误:"+e.getMessage())
  212. }
  213. }
  214. print( '根据workId='+workId + ",branch="+ branch + "下发明细文件成功!" );
  215. }
  216. }
  217. }
  218. init();