mem_memberbase_add.ktr 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <transformation>
  3. <info>
  4. <name>test</name>
  5. <description/>
  6. <extended_description/>
  7. <trans_version/>
  8. <trans_type>Normal</trans_type>
  9. <directory>/</directory>
  10. <parameters>
  11. </parameters>
  12. <log>
  13. <trans-log-table>
  14. <connection/>
  15. <schema/>
  16. <table/>
  17. <size_limit_lines/>
  18. <interval/>
  19. <timeout_days/>
  20. <field>
  21. <id>ID_BATCH</id>
  22. <enabled>Y</enabled>
  23. <name>ID_BATCH</name>
  24. </field>
  25. <field>
  26. <id>CHANNEL_ID</id>
  27. <enabled>Y</enabled>
  28. <name>CHANNEL_ID</name>
  29. </field>
  30. <field>
  31. <id>TRANSNAME</id>
  32. <enabled>Y</enabled>
  33. <name>TRANSNAME</name>
  34. </field>
  35. <field>
  36. <id>STATUS</id>
  37. <enabled>Y</enabled>
  38. <name>STATUS</name>
  39. </field>
  40. <field>
  41. <id>LINES_READ</id>
  42. <enabled>Y</enabled>
  43. <name>LINES_READ</name>
  44. <subject/>
  45. </field>
  46. <field>
  47. <id>LINES_WRITTEN</id>
  48. <enabled>Y</enabled>
  49. <name>LINES_WRITTEN</name>
  50. <subject/>
  51. </field>
  52. <field>
  53. <id>LINES_UPDATED</id>
  54. <enabled>Y</enabled>
  55. <name>LINES_UPDATED</name>
  56. <subject/>
  57. </field>
  58. <field>
  59. <id>LINES_INPUT</id>
  60. <enabled>Y</enabled>
  61. <name>LINES_INPUT</name>
  62. <subject/>
  63. </field>
  64. <field>
  65. <id>LINES_OUTPUT</id>
  66. <enabled>Y</enabled>
  67. <name>LINES_OUTPUT</name>
  68. <subject/>
  69. </field>
  70. <field>
  71. <id>LINES_REJECTED</id>
  72. <enabled>Y</enabled>
  73. <name>LINES_REJECTED</name>
  74. <subject/>
  75. </field>
  76. <field>
  77. <id>ERRORS</id>
  78. <enabled>Y</enabled>
  79. <name>ERRORS</name>
  80. </field>
  81. <field>
  82. <id>STARTDATE</id>
  83. <enabled>Y</enabled>
  84. <name>STARTDATE</name>
  85. </field>
  86. <field>
  87. <id>ENDDATE</id>
  88. <enabled>Y</enabled>
  89. <name>ENDDATE</name>
  90. </field>
  91. <field>
  92. <id>LOGDATE</id>
  93. <enabled>Y</enabled>
  94. <name>LOGDATE</name>
  95. </field>
  96. <field>
  97. <id>DEPDATE</id>
  98. <enabled>Y</enabled>
  99. <name>DEPDATE</name>
  100. </field>
  101. <field>
  102. <id>REPLAYDATE</id>
  103. <enabled>Y</enabled>
  104. <name>REPLAYDATE</name>
  105. </field>
  106. <field>
  107. <id>LOG_FIELD</id>
  108. <enabled>Y</enabled>
  109. <name>LOG_FIELD</name>
  110. </field>
  111. <field>
  112. <id>EXECUTING_SERVER</id>
  113. <enabled>N</enabled>
  114. <name>EXECUTING_SERVER</name>
  115. </field>
  116. <field>
  117. <id>EXECUTING_USER</id>
  118. <enabled>N</enabled>
  119. <name>EXECUTING_USER</name>
  120. </field>
  121. <field>
  122. <id>CLIENT</id>
  123. <enabled>N</enabled>
  124. <name>CLIENT</name>
  125. </field>
  126. </trans-log-table>
  127. <perf-log-table>
  128. <connection/>
  129. <schema/>
  130. <table/>
  131. <interval/>
  132. <timeout_days/>
  133. <field>
  134. <id>ID_BATCH</id>
  135. <enabled>Y</enabled>
  136. <name>ID_BATCH</name>
  137. </field>
  138. <field>
  139. <id>SEQ_NR</id>
  140. <enabled>Y</enabled>
  141. <name>SEQ_NR</name>
  142. </field>
  143. <field>
  144. <id>LOGDATE</id>
  145. <enabled>Y</enabled>
  146. <name>LOGDATE</name>
  147. </field>
  148. <field>
  149. <id>TRANSNAME</id>
  150. <enabled>Y</enabled>
  151. <name>TRANSNAME</name>
  152. </field>
  153. <field>
  154. <id>STEPNAME</id>
  155. <enabled>Y</enabled>
  156. <name>STEPNAME</name>
  157. </field>
  158. <field>
  159. <id>STEP_COPY</id>
  160. <enabled>Y</enabled>
  161. <name>STEP_COPY</name>
  162. </field>
  163. <field>
  164. <id>LINES_READ</id>
  165. <enabled>Y</enabled>
  166. <name>LINES_READ</name>
  167. </field>
  168. <field>
  169. <id>LINES_WRITTEN</id>
  170. <enabled>Y</enabled>
  171. <name>LINES_WRITTEN</name>
  172. </field>
  173. <field>
  174. <id>LINES_UPDATED</id>
  175. <enabled>Y</enabled>
  176. <name>LINES_UPDATED</name>
  177. </field>
  178. <field>
  179. <id>LINES_INPUT</id>
  180. <enabled>Y</enabled>
  181. <name>LINES_INPUT</name>
  182. </field>
  183. <field>
  184. <id>LINES_OUTPUT</id>
  185. <enabled>Y</enabled>
  186. <name>LINES_OUTPUT</name>
  187. </field>
  188. <field>
  189. <id>LINES_REJECTED</id>
  190. <enabled>Y</enabled>
  191. <name>LINES_REJECTED</name>
  192. </field>
  193. <field>
  194. <id>ERRORS</id>
  195. <enabled>Y</enabled>
  196. <name>ERRORS</name>
  197. </field>
  198. <field>
  199. <id>INPUT_BUFFER_ROWS</id>
  200. <enabled>Y</enabled>
  201. <name>INPUT_BUFFER_ROWS</name>
  202. </field>
  203. <field>
  204. <id>OUTPUT_BUFFER_ROWS</id>
  205. <enabled>Y</enabled>
  206. <name>OUTPUT_BUFFER_ROWS</name>
  207. </field>
  208. </perf-log-table>
  209. <channel-log-table>
  210. <connection/>
  211. <schema/>
  212. <table/>
  213. <timeout_days/>
  214. <field>
  215. <id>ID_BATCH</id>
  216. <enabled>Y</enabled>
  217. <name>ID_BATCH</name>
  218. </field>
  219. <field>
  220. <id>CHANNEL_ID</id>
  221. <enabled>Y</enabled>
  222. <name>CHANNEL_ID</name>
  223. </field>
  224. <field>
  225. <id>LOG_DATE</id>
  226. <enabled>Y</enabled>
  227. <name>LOG_DATE</name>
  228. </field>
  229. <field>
  230. <id>LOGGING_OBJECT_TYPE</id>
  231. <enabled>Y</enabled>
  232. <name>LOGGING_OBJECT_TYPE</name>
  233. </field>
  234. <field>
  235. <id>OBJECT_NAME</id>
  236. <enabled>Y</enabled>
  237. <name>OBJECT_NAME</name>
  238. </field>
  239. <field>
  240. <id>OBJECT_COPY</id>
  241. <enabled>Y</enabled>
  242. <name>OBJECT_COPY</name>
  243. </field>
  244. <field>
  245. <id>REPOSITORY_DIRECTORY</id>
  246. <enabled>Y</enabled>
  247. <name>REPOSITORY_DIRECTORY</name>
  248. </field>
  249. <field>
  250. <id>FILENAME</id>
  251. <enabled>Y</enabled>
  252. <name>FILENAME</name>
  253. </field>
  254. <field>
  255. <id>OBJECT_ID</id>
  256. <enabled>Y</enabled>
  257. <name>OBJECT_ID</name>
  258. </field>
  259. <field>
  260. <id>OBJECT_REVISION</id>
  261. <enabled>Y</enabled>
  262. <name>OBJECT_REVISION</name>
  263. </field>
  264. <field>
  265. <id>PARENT_CHANNEL_ID</id>
  266. <enabled>Y</enabled>
  267. <name>PARENT_CHANNEL_ID</name>
  268. </field>
  269. <field>
  270. <id>ROOT_CHANNEL_ID</id>
  271. <enabled>Y</enabled>
  272. <name>ROOT_CHANNEL_ID</name>
  273. </field>
  274. </channel-log-table>
  275. <step-log-table>
  276. <connection/>
  277. <schema/>
  278. <table/>
  279. <timeout_days/>
  280. <field>
  281. <id>ID_BATCH</id>
  282. <enabled>Y</enabled>
  283. <name>ID_BATCH</name>
  284. </field>
  285. <field>
  286. <id>CHANNEL_ID</id>
  287. <enabled>Y</enabled>
  288. <name>CHANNEL_ID</name>
  289. </field>
  290. <field>
  291. <id>LOG_DATE</id>
  292. <enabled>Y</enabled>
  293. <name>LOG_DATE</name>
  294. </field>
  295. <field>
  296. <id>TRANSNAME</id>
  297. <enabled>Y</enabled>
  298. <name>TRANSNAME</name>
  299. </field>
  300. <field>
  301. <id>STEPNAME</id>
  302. <enabled>Y</enabled>
  303. <name>STEPNAME</name>
  304. </field>
  305. <field>
  306. <id>STEP_COPY</id>
  307. <enabled>Y</enabled>
  308. <name>STEP_COPY</name>
  309. </field>
  310. <field>
  311. <id>LINES_READ</id>
  312. <enabled>Y</enabled>
  313. <name>LINES_READ</name>
  314. </field>
  315. <field>
  316. <id>LINES_WRITTEN</id>
  317. <enabled>Y</enabled>
  318. <name>LINES_WRITTEN</name>
  319. </field>
  320. <field>
  321. <id>LINES_UPDATED</id>
  322. <enabled>Y</enabled>
  323. <name>LINES_UPDATED</name>
  324. </field>
  325. <field>
  326. <id>LINES_INPUT</id>
  327. <enabled>Y</enabled>
  328. <name>LINES_INPUT</name>
  329. </field>
  330. <field>
  331. <id>LINES_OUTPUT</id>
  332. <enabled>Y</enabled>
  333. <name>LINES_OUTPUT</name>
  334. </field>
  335. <field>
  336. <id>LINES_REJECTED</id>
  337. <enabled>Y</enabled>
  338. <name>LINES_REJECTED</name>
  339. </field>
  340. <field>
  341. <id>ERRORS</id>
  342. <enabled>Y</enabled>
  343. <name>ERRORS</name>
  344. </field>
  345. <field>
  346. <id>LOG_FIELD</id>
  347. <enabled>N</enabled>
  348. <name>LOG_FIELD</name>
  349. </field>
  350. </step-log-table>
  351. <metrics-log-table>
  352. <connection/>
  353. <schema/>
  354. <table/>
  355. <timeout_days/>
  356. <field>
  357. <id>ID_BATCH</id>
  358. <enabled>Y</enabled>
  359. <name>ID_BATCH</name>
  360. </field>
  361. <field>
  362. <id>CHANNEL_ID</id>
  363. <enabled>Y</enabled>
  364. <name>CHANNEL_ID</name>
  365. </field>
  366. <field>
  367. <id>LOG_DATE</id>
  368. <enabled>Y</enabled>
  369. <name>LOG_DATE</name>
  370. </field>
  371. <field>
  372. <id>METRICS_DATE</id>
  373. <enabled>Y</enabled>
  374. <name>METRICS_DATE</name>
  375. </field>
  376. <field>
  377. <id>METRICS_CODE</id>
  378. <enabled>Y</enabled>
  379. <name>METRICS_CODE</name>
  380. </field>
  381. <field>
  382. <id>METRICS_DESCRIPTION</id>
  383. <enabled>Y</enabled>
  384. <name>METRICS_DESCRIPTION</name>
  385. </field>
  386. <field>
  387. <id>METRICS_SUBJECT</id>
  388. <enabled>Y</enabled>
  389. <name>METRICS_SUBJECT</name>
  390. </field>
  391. <field>
  392. <id>METRICS_TYPE</id>
  393. <enabled>Y</enabled>
  394. <name>METRICS_TYPE</name>
  395. </field>
  396. <field>
  397. <id>METRICS_VALUE</id>
  398. <enabled>Y</enabled>
  399. <name>METRICS_VALUE</name>
  400. </field>
  401. </metrics-log-table>
  402. </log>
  403. <maxdate>
  404. <connection/>
  405. <table/>
  406. <field/>
  407. <offset>0.0</offset>
  408. <maxdiff>0.0</maxdiff>
  409. </maxdate>
  410. <size_rowset>10000</size_rowset>
  411. <sleep_time_empty>50</sleep_time_empty>
  412. <sleep_time_full>50</sleep_time_full>
  413. <unique_connections>N</unique_connections>
  414. <feedback_shown>Y</feedback_shown>
  415. <feedback_size>50000</feedback_size>
  416. <using_thread_priorities>Y</using_thread_priorities>
  417. <shared_objects_file/>
  418. <capture_step_performance>N</capture_step_performance>
  419. <step_performance_capturing_delay>1000</step_performance_capturing_delay>
  420. <step_performance_capturing_size_limit>100</step_performance_capturing_size_limit>
  421. <dependencies>
  422. </dependencies>
  423. <partitionschemas>
  424. </partitionschemas>
  425. <slaveservers>
  426. </slaveservers>
  427. <clusterschemas>
  428. </clusterschemas>
  429. <created_user>-</created_user>
  430. <created_date>2019/06/11 14:33:34.761</created_date>
  431. <modified_user>-</modified_user>
  432. <modified_date>2019/06/11 14:33:34.761</modified_date>
  433. <key_for_session_key>H4sIAAAAAAAAAAMAAAAAAAAAAAA=</key_for_session_key>
  434. <is_key_private>N</is_key_private>
  435. </info>
  436. <notepads>
  437. </notepads>
  438. <connection>
  439. <name>MemberPortal</name>
  440. <server>219.128.77.96</server>
  441. <type>MSSQLNATIVE</type>
  442. <access>Native</access>
  443. <database>MemberPortal</database>
  444. <port>1433</port>
  445. <username>caixukun</username>
  446. <password>Encrypted 2be98afc86aa7f2e4a801a5508cc2fe83</password>
  447. <servername/>
  448. <data_tablespace/>
  449. <index_tablespace/>
  450. <attributes>
  451. <attribute>
  452. <code>FORCE_IDENTIFIERS_TO_LOWERCASE</code>
  453. <attribute>N</attribute>
  454. </attribute>
  455. <attribute>
  456. <code>FORCE_IDENTIFIERS_TO_UPPERCASE</code>
  457. <attribute>N</attribute>
  458. </attribute>
  459. <attribute>
  460. <code>IS_CLUSTERED</code>
  461. <attribute>N</attribute>
  462. </attribute>
  463. <attribute>
  464. <code>MSSQLUseIntegratedSecurity</code>
  465. <attribute>false</attribute>
  466. </attribute>
  467. <attribute>
  468. <code>MSSQL_DOUBLE_DECIMAL_SEPARATOR</code>
  469. <attribute>N</attribute>
  470. </attribute>
  471. <attribute>
  472. <code>PORT_NUMBER</code>
  473. <attribute>1433</attribute>
  474. </attribute>
  475. <attribute>
  476. <code>PRESERVE_RESERVED_WORD_CASE</code>
  477. <attribute>Y</attribute>
  478. </attribute>
  479. <attribute>
  480. <code>QUOTE_ALL_FIELDS</code>
  481. <attribute>N</attribute>
  482. </attribute>
  483. <attribute>
  484. <code>SUPPORTS_BOOLEAN_DATA_TYPE</code>
  485. <attribute>Y</attribute>
  486. </attribute>
  487. <attribute>
  488. <code>SUPPORTS_TIMESTAMP_DATA_TYPE</code>
  489. <attribute>Y</attribute>
  490. </attribute>
  491. <attribute>
  492. <code>USE_POOLING</code>
  493. <attribute>N</attribute>
  494. </attribute>
  495. </attributes>
  496. </connection>
  497. <order>
  498. <hop>
  499. <from>表输入</from>
  500. <to>HTTP client</to>
  501. <enabled>Y</enabled>
  502. </hop>
  503. <hop>
  504. <from>HTTP client</from>
  505. <to>Java 代码</to>
  506. <enabled>Y</enabled>
  507. </hop>
  508. <hop>
  509. <from>Java 代码</from>
  510. <to>Elasticsearch bulk insert</to>
  511. <enabled>Y</enabled>
  512. </hop>
  513. </order>
  514. <step>
  515. <name>Elasticsearch bulk insert</name>
  516. <type>ElasticSearchBulk</type>
  517. <description/>
  518. <distribute>Y</distribute>
  519. <custom_distribution/>
  520. <copies>1</copies>
  521. <partitioning>
  522. <method>none</method>
  523. <schema_name/>
  524. </partitioning>
  525. <general>
  526. <index>crm_memberbase_phoneid</index>
  527. <type>_doc</type>
  528. <batchSize>50000</batchSize>
  529. <timeout>100</timeout>
  530. <timeoutUnit>SECONDS</timeoutUnit>
  531. <isJson>N</isJson>
  532. <idField>phoneid</idField>
  533. <overwriteIfExists>Y</overwriteIfExists>
  534. <useOutput>N</useOutput>
  535. <stopOnError>Y</stopOnError>
  536. </general>
  537. <fields>
  538. </fields>
  539. <servers>
  540. <server>
  541. <address>192.168.50.32</address>
  542. <port>9300</port>
  543. </server>
  544. </servers>
  545. <settings>
  546. <setting>
  547. <name>cluster.name</name>
  548. <value>es</value>
  549. </setting>
  550. </settings>
  551. <attributes/>
  552. <cluster_schema/>
  553. <remotesteps>
  554. <input>
  555. </input>
  556. <output>
  557. </output>
  558. </remotesteps>
  559. <GUI>
  560. <xloc>672</xloc>
  561. <yloc>144</yloc>
  562. <draw>Y</draw>
  563. </GUI>
  564. </step>
  565. <step>
  566. <name>HTTP client</name>
  567. <type>HTTP</type>
  568. <description/>
  569. <distribute>Y</distribute>
  570. <custom_distribution/>
  571. <copies>1</copies>
  572. <partitioning>
  573. <method>none</method>
  574. <schema_name/>
  575. </partitioning>
  576. <url/>
  577. <urlInField>Y</urlInField>
  578. <urlField>Url</urlField>
  579. <encoding>UTF-8</encoding>
  580. <httpLogin/>
  581. <httpPassword>Encrypted </httpPassword>
  582. <proxyHost/>
  583. <proxyPort/>
  584. <socketTimeout>10000</socketTimeout>
  585. <connectionTimeout>10000</connectionTimeout>
  586. <closeIdleConnectionsTime>-1</closeIdleConnectionsTime>
  587. <lookup>
  588. </lookup>
  589. <result>
  590. <name>result</name>
  591. <code/>
  592. <response_time/>
  593. <response_header/>
  594. </result>
  595. <attributes/>
  596. <cluster_schema/>
  597. <remotesteps>
  598. <input>
  599. </input>
  600. <output>
  601. </output>
  602. </remotesteps>
  603. <GUI>
  604. <xloc>272</xloc>
  605. <yloc>128</yloc>
  606. <draw>Y</draw>
  607. </GUI>
  608. </step>
  609. <step>
  610. <name>Java 代码</name>
  611. <type>UserDefinedJavaClass</type>
  612. <description/>
  613. <distribute>Y</distribute>
  614. <custom_distribution/>
  615. <copies>1</copies>
  616. <partitioning>
  617. <method>none</method>
  618. <schema_name/>
  619. </partitioning>
  620. <definitions>
  621. <definition>
  622. <class_type>TRANSFORM_CLASS</class_type>
  623. <class_name>Processor</class_name>
  624. <class_source>import java.sql.*;
  625. import org.pentaho.di.core.database.*;
  626. import org.apache.http.HttpHost;
  627. import org.elasticsearch.ElasticsearchException;
  628. import org.elasticsearch.action.get.GetRequest;
  629. import org.elasticsearch.action.get.GetResponse;
  630. import org.elasticsearch.client.RestHighLevelClient;
  631. import org.elasticsearch.client.RequestOptions;
  632. import org.elasticsearch.client.RestClient;
  633. import org.elasticsearch.common.Strings;
  634. import org.elasticsearch.rest.RestStatus;
  635. import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
  636. import org.elasticsearch.action.update.UpdateRequest;
  637. import org.elasticsearch.action.update.UpdateResponse;
  638. import org.elasticsearch.common.xcontent.XContentBuilder;
  639. import org.elasticsearch.common.xcontent.XContentFactory;
  640. import org.elasticsearch.script.Script;
  641. import java.lang.reflect.InvocationTargetException;
  642. import java.lang.reflect.Method;
  643. import com.microsoft.sqlserver.jdbc.SQLServerException;
  644. Database database = null;
  645. PreparedStatement stat = null;
  646. PreparedStatement stat1 = null;
  647. RestHighLevelClient client = new RestHighLevelClient(
  648. RestClient.builder(
  649. new HttpHost[]{new HttpHost("192.168.50.32", 9200, "http")}));
  650. Integer index = 0;
  651. public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
  652. {
  653. Object[] r = getRow();
  654. if (r == null) {
  655. try {
  656. if(client!=null){
  657. client.close();
  658. }
  659. }
  660. catch(Exception e) {
  661. throw new KettleException(e);
  662. }
  663. setOutputDone();
  664. return false;
  665. }
  666. synchronized(this) {
  667. r = createOutputRow(r, data.outputRowMeta.size());
  668. //获取数据库名和表名
  669. String dbName = "MemberSqlServer";//getInputRowMeta().getString(r, "conname", null );
  670. String tablename = "DataImport_heathytemp";//getInputRowMeta().getString(r, "tablename", null );
  671. String idname = "MemberId";//getInputRowMeta().getString(r, "idname", null );
  672. String sourceidname = "MemberPhone";//getInputRowMeta().getString(r, "sourceidname", null );
  673. String sourcetablename = "Orders";//getInputRowMeta().getString(r, "sourcetablename", null );
  674. if (dbName==null||tablename==null) {
  675. throw new KettleException("Unable to find field with name "+tablename+" in the input row.");
  676. }
  677. //logBasic("table---"+tablename);
  678. if(database == null){
  679. //数据库连接
  680. DatabaseMeta databaseMeta=null;
  681. try {
  682. databaseMeta = getTransMeta().findDatabase(dbName);
  683. if (databaseMeta==null) {
  684. logError("A connection with name "+dbName+" could not be found!");
  685. setErrors(1);
  686. return false;
  687. }
  688. database = new Database(getTrans(), databaseMeta);
  689. database.connect();
  690. //logBasic("success!");
  691. } catch(Exception e) {
  692. logError("Connecting to database "+dbName+" failed.", e);
  693. setErrors(1);
  694. return false;
  695. }
  696. }
  697. //查询表数据
  698. try {
  699. RowMetaInterface idxRowMeta =data.outputRowMeta;
  700. r = createOutputRow(r, data.outputRowMeta.size());
  701. //int index = getInputRowMeta().size();
  702. // Add the column name
  703. String Id = idxRowMeta.getString(r, "phoneid", null);
  704. String DataId = idxRowMeta.getString(r, "result", null);
  705. logBasic("--"+Id);
  706. logBasic("--"+DataId);
  707. logBasic("--"+(DataId == null||DataId.equals("null")));
  708. if(DataId == null||DataId.equals("null")){
  709. return true;
  710. }
  711. int startEmail = DataId.indexOf("buyer_email")+("buyer_email\":\"".length());
  712. int endEmail = DataId.indexOf("\",\"buyer_nick");
  713. int startTradeName = DataId.indexOf("buyer_nick")+("buyer_nick\":\"".length());
  714. int endTradeName = DataId.indexOf("\"\",\"\"buyer_obtain_point_fee");
  715. int startTradeFrom = DataId.indexOf("trade_from")+("trade_from\":\"".length());
  716. int endTradeFrom = DataId.indexOf("\",\"trade_source");
  717. //logBasic("--"+(end-start));
  718. String email = DataId.substring(startEmail,endEmail);
  719. //String tradeName = DataId.substring(startTradeName,endTradeName);
  720. String tradeFrom = DataId.substring(startTradeFrom,endTradeFrom);
  721. logBasic("email--"+email);
  722. //logBasic("tradeName--"+tradeName);
  723. //logBasic("tradeFrom--"+tradeFrom);
  724. logBasic("startEmail--"+startEmail);
  725. logBasic("endEmail--"+endEmail);
  726. logBasic("startTradeName--"+startTradeFrom);
  727. logBasic("endTradeName--"+endTradeFrom);
  728. logBasic("startTradeName--"+startTradeName);
  729. logBasic("endTradeName--"+endTradeName);
  730. Thread.sleep(1000);
  731. GetRequest getRequest = new GetRequest(
  732. "crm_memberbase_phoneid", // Index
  733. "_doc", // Type
  734. Id); // Document id
  735. getRequest.fetchSourceContext(new FetchSourceContext(false)); // 禁用 _source 字段
  736. getRequest.storedFields(new String[]{"_none_"}); // 禁止存储任何字段
  737. boolean exists = client.exists(getRequest,RequestOptions.DEFAULT);
  738. //client.close();
  739. if(exists) {
  740. UpdateRequest updateRequest = new UpdateRequest();
  741. updateRequest.index("crm_memberbase_phoneid");
  742. updateRequest.type("_doc");
  743. updateRequest.id(Id);
  744. updateRequest.doc(XContentFactory.jsonBuilder()
  745. .startObject()
  746. .field("MemEmail", email)
  747. .field("TradeName", "")//tradeName
  748. .field("TradeFrom", "")//tradeFrom
  749. .endObject());
  750. client.update(updateRequest,RequestOptions.DEFAULT);
  751. }
  752. }
  753. catch(SQLServerException e) {
  754. return true;
  755. }catch(Exception e) {
  756. throw new KettleException(e);
  757. }
  758. //释放连接
  759. //if (database!=null) {
  760. // database.disconnect();
  761. //}
  762. // Send the row on to the next step.
  763. }
  764. putRow(data.outputRowMeta, r);
  765. return true;
  766. }</class_source>
  767. </definition>
  768. </definitions>
  769. <fields>
  770. </fields>
  771. <clear_result_fields>N</clear_result_fields>
  772. <info_steps/>
  773. <target_steps/>
  774. <usage_parameters/>
  775. <attributes/>
  776. <cluster_schema/>
  777. <remotesteps>
  778. <input>
  779. </input>
  780. <output>
  781. </output>
  782. </remotesteps>
  783. <GUI>
  784. <xloc>448</xloc>
  785. <yloc>80</yloc>
  786. <draw>Y</draw>
  787. </GUI>
  788. </step>
  789. <step>
  790. <name>表输入</name>
  791. <type>TableInput</type>
  792. <description/>
  793. <distribute>Y</distribute>
  794. <custom_distribution/>
  795. <copies>1</copies>
  796. <partitioning>
  797. <method>none</method>
  798. <schema_name/>
  799. </partitioning>
  800. <connection>MemberPortal</connection>
  801. <sql> SELECT
  802. case when OriginType =6 then concat( 'http://api.360lj.com/taobaodocking/GetOneOrderInfo?tid=',substring(OrdersCode,3,LEN(OrdersCode)-1))
  803. else concat( 'http://api.360lj.com/taobaodocking/GetOneOrderInfo?tid=',substring(OrdersCode,4,LEN(OrdersCode)-1)) end
  804. as Url
  805. ,OriginType
  806. ,Mall.dbo.DesDecryptFixKey('123456','123456e10adc3949ba59abbe56e057f20f883e',AconsigneePhone2 ) as phoneid
  807. FROM mall..orders
  808. WHERE OrdersCode LIKE 'TM%' AND OriginType IN (6,57,58)
  809. AND AconsigneePhone2!=''
  810. AND DateDiff(dd,OrderTime,getdate())&lt;=90
  811. ORDER BY OrderTime DESC</sql>
  812. <limit>0</limit>
  813. <lookup/>
  814. <execute_each_row>N</execute_each_row>
  815. <variables_active>N</variables_active>
  816. <lazy_conversion_active>N</lazy_conversion_active>
  817. <attributes/>
  818. <cluster_schema/>
  819. <remotesteps>
  820. <input>
  821. </input>
  822. <output>
  823. </output>
  824. </remotesteps>
  825. <GUI>
  826. <xloc>144</xloc>
  827. <yloc>112</yloc>
  828. <draw>Y</draw>
  829. </GUI>
  830. </step>
  831. <step_error_handling>
  832. <error>
  833. <source_step>HTTP client</source_step>
  834. <target_step/>
  835. <is_enabled>N</is_enabled>
  836. <nr_valuename/>
  837. <descriptions_valuename/>
  838. <fields_valuename/>
  839. <codes_valuename/>
  840. <max_errors/>
  841. <max_pct_errors/>
  842. <min_pct_rows/>
  843. </error>
  844. </step_error_handling>
  845. <slave-step-copy-partition-distribution>
  846. </slave-step-copy-partition-distribution>
  847. <slave_transformation>N</slave_transformation>
  848. <attributes/>
  849. </transformation>