ERPDocking.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. package utility;
  2. import beans.uploaderpdata.UploadDataToERP_HY;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.data.Row;
  8. import common.data.Rows;
  9. import common.data.SQLFactory;
  10. import org.dom4j.Document;
  11. import utility.tools.WebRequest;
  12. import java.io.BufferedReader;
  13. import java.io.IOException;
  14. import java.io.InputStreamReader;
  15. import java.io.PrintWriter;
  16. import java.net.CookieHandler;
  17. import java.net.CookieManager;
  18. import java.net.HttpURLConnection;
  19. import java.net.URL;
  20. import java.nio.charset.StandardCharsets;
  21. import java.util.HashMap;
  22. public class ERPDocking {
  23. public static boolean loginstatus = false;
  24. String url = "http://192.168.3.89:8001/rest/ws_v2/basicDrp";
  25. public ERPDocking(String siteid) {
  26. if (siteid.equalsIgnoreCase("DLB")) {
  27. url = "http://192.168.3.89:8001/rest/ws_v2/basicDrp";
  28. }
  29. if (siteid.equalsIgnoreCase("CCYOSG")) {
  30. url = "http://192.168.3.89:8009/rest/ws_v2/basicDrp";
  31. // url = "http://124.71.196.182:8001/rest/ws_v2/basicDrp";
  32. }
  33. System.err.println(siteid + ":" + url);
  34. }
  35. /*
  36. crm登陆
  37. */
  38. // private void login() throws YosException {
  39. // if (!loginstatus) {
  40. // /*
  41. // 自动保存cookie
  42. // */
  43. // CookieManager manager = new CookieManager();
  44. // CookieHandler.setDefault(manager);
  45. // String s = new WebRequest().doPost("username=yosAdmin&password=yosAdmin123", "http://crm.meida.com/dmsService/ext/partner/login");
  46. // JSONObject object = JSONObject.parseObject(s);
  47. // if (object.getIntValue("code") == 1) {
  48. // loginstatus = true;
  49. // } else {
  50. // loginstatus = false;
  51. // }
  52. // }
  53. // }
  54. /**
  55. * 获取erp物料档案
  56. *
  57. * @param begindate
  58. * @param pagerows
  59. * @param pagenum
  60. * @return
  61. * @throws YosException
  62. */
  63. public JSONArray getErpItemRows(String begindate, int pagerows, int pagenum) throws YosException {
  64. JSONObject object = new JSONObject();
  65. JSONObject objectdetail = new JSONObject();
  66. objectdetail.put("fstatus", "审核");
  67. objectdetail.put("fmodel", "");
  68. objectdetail.put("fitemname", "");
  69. objectdetail.put("fitemclsnum", "");
  70. objectdetail.put("fitemnos", new JSONArray());
  71. objectdetail.put("pagerows", pagerows);
  72. objectdetail.put("pagenum", pagenum);
  73. objectdetail.put("changedateBeg", begindate);
  74. object.put("access_token", "basicDrp");
  75. object.put("classname", "Titem");
  76. object.put("method", "queryPage");
  77. object.put("content", objectdetail);
  78. HashMap<String, String> map = new HashMap<>();
  79. map.put("content-Type", "application/json");
  80. String result = new WebRequest().doPost(object.toString(), url, map);
  81. JSONObject resultobject = JSONObject.parseObject(result);
  82. // System.out.println(object.toString());
  83. // System.out.println(resultobject.toJSONString());
  84. if (resultobject != null) {
  85. if (resultobject.getString("errcode").equals("0")) {
  86. return resultobject.getJSONObject("results").getJSONArray("list");
  87. } else {
  88. return new JSONArray();
  89. }
  90. } else {
  91. return new JSONArray();
  92. }
  93. }
  94. /**
  95. * 查询Erp库存
  96. *
  97. * @param pagerows
  98. * @param pagenum
  99. * @param fitemnos
  100. * @return
  101. * @throws YosException
  102. */
  103. public JSONArray getErpIcinvbalRows(int pagerows, int pagenum, JSONArray fitemnos) throws YosException {
  104. {
  105. JSONObject object = new JSONObject();
  106. JSONObject objectdetail = new JSONObject();
  107. objectdetail.put("fstockno", "01");
  108. objectdetail.put("fmodel", "");
  109. objectdetail.put("fitemname", "");
  110. objectdetail.put("fitemclsnum", "");
  111. objectdetail.put("fitemnos", fitemnos);
  112. objectdetail.put("pagerows", pagerows);
  113. objectdetail.put("pagenum", pagenum);
  114. object.put("access_token", "basicDrp");
  115. object.put("classname", "Icinvbal");
  116. object.put("method", "queryPage");
  117. object.put("content", objectdetail);
  118. HashMap<String, String> map = new HashMap<>();
  119. map.put("content-Type", "application/json");
  120. String result = new WebRequest().doPost(object.toString(), url, map);
  121. JSONObject resultobject = JSONObject.parseObject(result);
  122. if (resultobject != null) {
  123. if (resultobject.getString("errcode").equals("0")) {
  124. return resultobject.getJSONObject("results").getJSONArray("list");
  125. } else {
  126. return new JSONArray();
  127. }
  128. } else {
  129. return new JSONArray();
  130. }
  131. }
  132. }
  133. /**
  134. * 查询Erp批次库存
  135. *
  136. * @param pagerows
  137. * @param pagenum
  138. * @param fitemnos
  139. * @return
  140. * @throws YosException
  141. */
  142. public JSONArray getErpIcinvbalBatchRows(int pagerows, int pagenum, JSONArray fitemnos) throws YosException {
  143. {
  144. JSONObject object = new JSONObject();
  145. JSONObject objectdetail = new JSONObject();
  146. objectdetail.put("fstockno", "01");
  147. objectdetail.put("fstockname", "");
  148. objectdetail.put("fmodel", "");
  149. objectdetail.put("fitemname", "");
  150. objectdetail.put("fbatchno", "");
  151. objectdetail.put("fitemclsnum", "");
  152. objectdetail.put("onlyFqtyPositive", "true");
  153. objectdetail.put("fitemnos", fitemnos);
  154. objectdetail.put("pagerows", pagerows);
  155. objectdetail.put("pagenum", pagenum);
  156. object.put("access_token", "basicDrp");
  157. object.put("classname", "Icinvbal");
  158. object.put("method", "queryPageOfBatch");
  159. object.put("content", objectdetail);
  160. HashMap<String, String> map = new HashMap<>();
  161. map.put("content-Type", "application/json");
  162. String result = new WebRequest().doPost(object.toString(), url, map);
  163. JSONObject resultobject = JSONObject.parseObject(result);
  164. if (resultobject != null) {
  165. if (resultobject.getString("errcode").equals("0")) {
  166. return resultobject.getJSONObject("results").getJSONArray("list");
  167. } else {
  168. return new JSONArray();
  169. }
  170. } else {
  171. return new JSONArray();
  172. }
  173. }
  174. }
  175. /**
  176. * 创建Erp发货单
  177. *
  178. * @param dispatchRow
  179. * @param dispatchItems
  180. * @return
  181. * @throws YosException
  182. */
  183. public String createErpSainvoice(Row dispatchRow, Rows dispatchItems, Controller controller, long sa_dispatchid) throws YosException {
  184. {
  185. JSONObject object = new JSONObject();
  186. JSONObject objectdetail = new JSONObject();
  187. JSONArray jsonArray = new JSONArray();
  188. object.put("access_token", "basicDrp");
  189. object.put("classname", "Sainvoice");
  190. object.put("method", "createSainvoice");
  191. objectdetail.put("finvonum", dispatchRow.getString("billno"));
  192. objectdetail.put("fagentnum", dispatchRow.getString("agentnum"));
  193. objectdetail.put("fagentname", dispatchRow.getString("enterprisename"));
  194. objectdetail.put("fsonum", dispatchRow.getString("sonum"));
  195. objectdetail.put("fdate", dispatchRow.getString("billdate"));
  196. objectdetail.put("fnotes", dispatchRow.getString("remarks"));
  197. objectdetail.put("fcontact", dispatchRow.getString("name"));
  198. objectdetail.put("fmobilephone", dispatchRow.getString("phonenumber"));
  199. objectdetail.put("faddress", dispatchRow.getString("address"));
  200. objectdetail.put("createby", dispatchRow.getString("createby"));
  201. if (dispatchItems.isNotEmpty()) {
  202. for (Row row : dispatchItems) {
  203. JSONObject jsonObject = new JSONObject();
  204. jsonObject.put("fsonum", row.getString("sonum"));
  205. jsonObject.put("fsorownum", row.getString("sorowno"));
  206. jsonObject.put("fprodnum", row.getString("itemno"));
  207. jsonObject.put("fbatchbnum", row.getString("batchno"));
  208. jsonObject.put("frownum", row.getString("rowno"));
  209. jsonObject.put("fqty", row.getString("qty"));
  210. jsonObject.put("fprice", row.getString("price"));
  211. jsonObject.put("fremarks", row.getString("remarks"));
  212. jsonArray.add(jsonObject);
  213. }
  214. }
  215. objectdetail.put("details", jsonArray);
  216. object.put("content", objectdetail);
  217. HashMap<String, String> map = new HashMap<>();
  218. map.put("content-Type", "application/json");
  219. String result = new WebRequest().doPost(object.toString(), url, map);
  220. JSONObject resultobject = JSONObject.parseObject(result);
  221. saveLog(controller, "sa_dispatch", sa_dispatchid, "创建erp发货单", object.toString(), resultobject, dispatchRow.getString("billno"));
  222. if (resultobject != null) {
  223. if (resultobject.getString("errcode").equals("0")) {
  224. return "true";
  225. } else {
  226. return resultobject.getString("errmsg");
  227. }
  228. } else {
  229. return "false";
  230. }
  231. }
  232. }
  233. /**
  234. * 查询Erp发货单(单个)
  235. *
  236. * @param billno
  237. * @return
  238. * @throws YosException
  239. */
  240. public JSONArray queryErpSainvoice(String billno) throws YosException {
  241. {
  242. JSONObject object = new JSONObject();
  243. JSONObject objectdetail = new JSONObject();
  244. object.put("access_token", "basicDrp");
  245. object.put("classname", "Sainvoice");
  246. object.put("method", "queryOne");
  247. objectdetail.put("finvonum", billno);
  248. object.put("content", objectdetail);
  249. HashMap<String, String> map = new HashMap<>();
  250. map.put("content-Type", "application/json");
  251. String result = new WebRequest().doPost(object.toString(), url, map);
  252. JSONObject resultobject = JSONObject.parseObject(result);
  253. System.out.println(resultobject);
  254. if (resultobject == null || resultobject.getString("errcode").equals("error")) {
  255. return new JSONArray();
  256. } else {
  257. return resultobject.getJSONObject("results").getJSONArray("details");
  258. }
  259. }
  260. }
  261. /**
  262. * 查询Erp发货单(批量)
  263. *
  264. * @param pagerows
  265. * @param pagenum
  266. * @param finvonums
  267. * @param fagentnum
  268. * @param fsonum
  269. * @param fstatus
  270. * @param onlyNeedClosed
  271. * @return
  272. * @throws YosException
  273. */
  274. public JSONArray queryErpSainvoices(int pagerows, int pagenum, JSONArray finvonums, String fagentnum, String
  275. fsonum, String fstatus, boolean onlyNeedClosed, boolean onlyNeedPartialOuts, boolean onlyWithCheckedOuts) throws
  276. YosException {
  277. {
  278. JSONObject object = new JSONObject();
  279. JSONObject objectdetail = new JSONObject();
  280. object.put("access_token", "basicDrp");
  281. object.put("classname", "Sainvoice");
  282. object.put("method", "queryPage");
  283. objectdetail.put("pagenum", pagenum);
  284. objectdetail.put("pagerows", pagerows);
  285. objectdetail.put("finvonums", finvonums);
  286. objectdetail.put("fagentnum", fagentnum);
  287. objectdetail.put("fsonum", fsonum);
  288. objectdetail.put("fstatus", fstatus);
  289. objectdetail.put("onlyNeedClosed", onlyNeedClosed);
  290. objectdetail.put("onlyNeedPartialOuts", onlyNeedPartialOuts);
  291. objectdetail.put("onlyWithCheckedOuts", onlyWithCheckedOuts);
  292. object.put("content", objectdetail);
  293. HashMap<String, String> map = new HashMap<>();
  294. map.put("content-Type", "application/json");
  295. System.out.println(object.toString());
  296. String result = new WebRequest().doPost(object.toString(), url, map);
  297. JSONObject resultobject = JSONObject.parseObject(result);
  298. System.out.println(resultobject);
  299. if (resultobject == null || resultobject.getString("errcode").equals("error")) {
  300. return new JSONArray();
  301. } else {
  302. return resultobject.getJSONObject("results").getJSONArray("list");
  303. }
  304. }
  305. }
  306. /**
  307. * 关闭Erp发货单
  308. *
  309. * @param billno
  310. * @param isManual
  311. * @return
  312. * @throws YosException
  313. */
  314. public String closeErpSainvoice(String billno, boolean isManual, Controller controller, long sa_dispatchid) throws
  315. YosException {
  316. {
  317. JSONObject object = new JSONObject();
  318. JSONObject objectdetail = new JSONObject();
  319. object.put("access_token", "basicDrp");
  320. object.put("classname", "Sainvoice");
  321. object.put("method", "closeSainvoice");
  322. objectdetail.put("finvonum", billno);
  323. objectdetail.put("isManual", isManual);
  324. object.put("content", objectdetail);
  325. HashMap<String, String> map = new HashMap<>();
  326. map.put("content-Type", "application/json");
  327. String result = new WebRequest().doPost(object.toString(), url, map);
  328. JSONObject resultobject = JSONObject.parseObject(result);
  329. saveLog(controller, "sa_dispatch", sa_dispatchid, "关闭发货单", object.toString(), resultobject, billno);
  330. if (resultobject != null) {
  331. if (resultobject.getString("errcode").equals("0")) {
  332. return "true";
  333. } else {
  334. return resultobject.getString("errmsg");
  335. }
  336. } else {
  337. return "false";
  338. }
  339. }
  340. }
  341. /**
  342. * Erp发货单行关闭
  343. *
  344. * @param billno
  345. * @param controller
  346. * @param rowno
  347. * @param itemno
  348. * @param sa_dispatchid
  349. * @return
  350. * @throws YosException
  351. */
  352. public String closeErpSainvoiceRow(String billno, Controller controller, long rowno, String itemno,
  353. long sa_dispatchid) throws YosException {
  354. {
  355. JSONObject object = new JSONObject();
  356. JSONObject objectdetail = new JSONObject();
  357. object.put("access_token", "basicDrp");
  358. object.put("classname", "Sainvoice");
  359. object.put("method", "closeRowOfSainvoice");
  360. objectdetail.put("finvonum", billno);
  361. objectdetail.put("fprodnum", itemno);
  362. objectdetail.put("frownum", rowno);
  363. object.put("content", objectdetail);
  364. HashMap<String, String> map = new HashMap<>();
  365. map.put("content-Type", "application/json");
  366. String result = new WebRequest().doPost(object.toString(), url, map);
  367. JSONObject resultobject = JSONObject.parseObject(result);
  368. saveLog(controller, "sa_dispatch", sa_dispatchid, "发货单行关闭", object.toString(), resultobject, billno);
  369. if (resultobject != null) {
  370. if (resultobject.getString("errcode").equals("0")) {
  371. return "true";
  372. } else {
  373. return resultobject.getString("errmsg");
  374. }
  375. } else {
  376. return resultobject.getString("false");
  377. }
  378. }
  379. }
  380. /**
  381. * 创建Erp退/换货单
  382. *
  383. * @param aftersalesmagRow
  384. * @param aftersalesmagItems
  385. * @return
  386. * @throws YosException
  387. */
  388. public String createErpSareturn(Row aftersalesmagRow, Rows aftersalesmagItems, Controller controller,
  389. long sa_aftersalesmagid) throws YosException {
  390. {
  391. JSONObject object = new JSONObject();
  392. JSONObject objectdetail = new JSONObject();
  393. JSONArray jsonArray = new JSONArray();
  394. object.put("access_token", "basicDrp");
  395. object.put("classname", "Sareturn");
  396. object.put("method", "createSareturn");
  397. objectdetail.put("freturnnum", aftersalesmagRow.getString("billno"));
  398. objectdetail.put("fagentnum", aftersalesmagRow.getString("agentnum"));
  399. objectdetail.put("fagentname", aftersalesmagRow.getString("enterprisename"));
  400. objectdetail.put("faccclsnum", "01");
  401. objectdetail.put("fdate", aftersalesmagRow.getString("billdate"));
  402. objectdetail.put("fnotes", aftersalesmagRow.getString("reason"));
  403. objectdetail.put("createby", aftersalesmagRow.getString("createby"));
  404. if (aftersalesmagRow.getString("type").equals("退货单")) {
  405. objectdetail.put("freturntype", "退货");
  406. } else if (aftersalesmagRow.getString("type").equals("换货单")) {
  407. objectdetail.put("freturntype", "换货");
  408. }
  409. if (aftersalesmagItems.isNotEmpty()) {
  410. for (Row row : aftersalesmagItems) {
  411. JSONObject jsonObject = new JSONObject();
  412. jsonObject.put("fprodnum", row.getString("itemno"));
  413. jsonObject.put("fbatchbnum", row.getString("batchno"));
  414. jsonObject.put("fqty", row.getString("qty"));
  415. jsonObject.put("fprice", row.getString("price"));
  416. jsonObject.put("fremarks", row.getString("reason"));
  417. jsonArray.add(jsonObject);
  418. }
  419. }
  420. objectdetail.put("details", jsonArray);
  421. object.put("content", objectdetail);
  422. HashMap<String, String> map = new HashMap<>();
  423. map.put("content-Type", "application/json");
  424. System.out.println(object.toString());
  425. String result = new WebRequest().doPost(object.toString(), url, map);
  426. JSONObject resultobject = JSONObject.parseObject(result);
  427. saveLog(controller, "sa_aftersalesmag", sa_aftersalesmagid, "创建erp退/换货单", object.toString(), resultobject, aftersalesmagRow.getString("billno"));
  428. if (resultobject != null) {
  429. if (resultobject.getString("errcode").equals("0")) {
  430. return "true";
  431. } else {
  432. return resultobject.getString("errmsg");
  433. }
  434. } else {
  435. return "false";
  436. }
  437. }
  438. }
  439. /**
  440. * 查询Erp退/换货单(单个)
  441. *
  442. * @param billno
  443. * @return
  444. * @throws YosException
  445. */
  446. public JSONArray queryErpSareturn(String billno) throws YosException {
  447. {
  448. JSONObject object = new JSONObject();
  449. JSONObject objectdetail = new JSONObject();
  450. object.put("access_token", "basicDrp");
  451. object.put("classname", "Sareturn");
  452. object.put("method", "queryOne");
  453. objectdetail.put("freturnnum", billno);
  454. object.put("content", objectdetail);
  455. HashMap<String, String> map = new HashMap<>();
  456. map.put("content-Type", "application/json");
  457. String result = new WebRequest().doPost(object.toString(), url, map);
  458. JSONObject resultobject = JSONObject.parseObject(result);
  459. System.out.println(resultobject);
  460. if (resultobject == null || resultobject.getString("errcode").equals("error")) {
  461. return new JSONArray();
  462. } else {
  463. return resultobject.getJSONObject("results").getJSONArray("details");
  464. }
  465. }
  466. }
  467. /**
  468. * 查询Erpt退/换货单(批量)
  469. *
  470. * @param pagerows
  471. * @param pagenum
  472. * @param freturnnums
  473. * @param fagentnum
  474. * @param fsonum
  475. * @param fstatus
  476. * @param onlyNeedClosed
  477. * @return
  478. * @throws YosException
  479. */
  480. public JSONArray queryErpSareturns(int pagerows, int pagenum, JSONArray freturnnums, String fagentnum, String
  481. fsonum, String freturntype, String fstatus, boolean onlyNeedClosed) throws YosException {
  482. {
  483. JSONObject object = new JSONObject();
  484. JSONObject objectdetail = new JSONObject();
  485. object.put("access_token", "basicDrp");
  486. object.put("classname", "Sareturn");
  487. object.put("method", "queryPage");
  488. objectdetail.put("pagenum", pagenum);
  489. objectdetail.put("pagerows", pagerows);
  490. objectdetail.put("freturnnums", freturnnums);
  491. objectdetail.put("fagentnum", fagentnum);
  492. objectdetail.put("fsonum", fsonum);
  493. objectdetail.put("freturntype", freturntype);
  494. objectdetail.put("fstatus", fstatus);
  495. objectdetail.put("onlyNeedClosed", onlyNeedClosed);
  496. object.put("content", objectdetail);
  497. HashMap<String, String> map = new HashMap<>();
  498. map.put("content-Type", "application/json");
  499. System.out.println(object.toString());
  500. String result = new WebRequest().doPost(object.toString(), url, map);
  501. JSONObject resultobject = JSONObject.parseObject(result);
  502. System.out.println(resultobject);
  503. if (resultobject == null || resultobject.getString("errcode").equals("error")) {
  504. return new JSONArray();
  505. } else {
  506. return resultobject.getJSONObject("results").getJSONArray("list");
  507. }
  508. }
  509. }
  510. /**
  511. * 复核Erp退/换货单
  512. *
  513. * @param billno
  514. * @param isManual
  515. * @return
  516. * @throws YosException
  517. */
  518. public String recheckErpSareturn(String billno, boolean isManual, Controller controller, long sa_aftersalesmagid) throws
  519. YosException {
  520. {
  521. JSONObject object = new JSONObject();
  522. JSONObject objectdetail = new JSONObject();
  523. object.put("access_token", "basicDrp");
  524. object.put("classname", "Sareturn");
  525. object.put("method", "closeSareturn");
  526. objectdetail.put("freturnnum", billno);
  527. objectdetail.put("isManual", isManual);
  528. object.put("content", objectdetail);
  529. HashMap<String, String> map = new HashMap<>();
  530. map.put("content-Type", "application/json");
  531. String result = new WebRequest().doPost(object.toString(), url, map);
  532. JSONObject resultobject = JSONObject.parseObject(result);
  533. saveLog(controller, "sa_aftersalesmag", sa_aftersalesmagid, "复核erp退/换货单", object.toString(), resultobject, billno);
  534. if (resultobject != null) {
  535. if (resultobject.getString("errcode").equals("0")) {
  536. return "true";
  537. } else {
  538. return resultobject.getString("errmsg");
  539. }
  540. }else{
  541. return "false";
  542. }
  543. }
  544. }
  545. /**
  546. * 上传日志更新
  547. *
  548. * @param controller
  549. * @param ownertable
  550. * @param ownerid
  551. * @param type
  552. * @param request
  553. * @param response
  554. * @param billno
  555. * @return
  556. */
  557. public static boolean saveLog(Controller controller, String ownertable, long ownerid, String type, String
  558. request,
  559. JSONObject response, String billno) {
  560. boolean issuccess = false;
  561. try {
  562. Rows rows = controller.dbConnect.runSqlQuery(
  563. "select * from sys_erpupdatelog where ownertable='" + ownertable + "' and ownerid=" + ownerid);
  564. SQLFactory sqlFactory;
  565. if (!rows.isEmpty()) {
  566. sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志更新");
  567. sqlFactory.addParameter("sys_erpupdatelogid", rows.get(0).getLong("sys_erpupdatelogid"));
  568. } else {
  569. sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志新增");
  570. sqlFactory.addParameter("sys_erpupdatelogid", controller.createTableID("sys_erpupdatelog"));
  571. }
  572. sqlFactory.addParameter("siteid", controller.siteid);
  573. sqlFactory.addParameter("userid", controller.userid);
  574. sqlFactory.addParameter("username", controller.username);
  575. sqlFactory.addParameter("ownerid", ownerid);
  576. sqlFactory.addParameter("ownertable", ownertable);
  577. sqlFactory.addParameter("type", type);
  578. sqlFactory.addParameter("request", request);
  579. sqlFactory.addParameter("response", response.toJSONString());
  580. if ("0".equals(response.getString("errcode"))) {
  581. sqlFactory.addParameter("erpbillno", billno);
  582. sqlFactory.addParameter("errmsg", "");
  583. issuccess = true;
  584. } else {
  585. sqlFactory.addParameter("erpbillno", "");
  586. sqlFactory.addParameter("errmsg", response.getString("errmsg"));
  587. issuccess = false;
  588. }
  589. sqlFactory.addParameter("status", response.getString("errcode"));
  590. controller.dbConnect.runSqlUpdate(sqlFactory);
  591. } catch (Exception e) {
  592. e.printStackTrace();
  593. }
  594. return issuccess;
  595. }
  596. /**
  597. * 查询销售出库单
  598. *
  599. * @param pagerows
  600. * @param pagenum
  601. * @return
  602. * @throws YosException
  603. */
  604. public JSONArray queryErpStockBill(int pagerows, int pagenum, String fbtname) throws YosException {
  605. {
  606. JSONArray fupdateFlags = new JSONArray();
  607. fupdateFlags.add(0);
  608. fupdateFlags.add(99);
  609. fupdateFlags.add(2);
  610. JSONObject object = new JSONObject();
  611. JSONObject objectdetail = new JSONObject();
  612. object.put("access_token", "basicDrp");
  613. object.put("classname", "TstockbillOuts");
  614. object.put("method", "queryPageForSyncYos");
  615. objectdetail.put("pagenum", pagenum);
  616. objectdetail.put("pagerows", pagerows);
  617. objectdetail.put("fbillnums", new JSONArray());
  618. objectdetail.put("fagentnum", "");
  619. objectdetail.put("fstatus", "审核");
  620. objectdetail.put("frb", "");
  621. objectdetail.put("fstockno", "");
  622. objectdetail.put("fbtname", fbtname);
  623. objectdetail.put("fminperiod", "");
  624. objectdetail.put("fupdateFlags", fupdateFlags);
  625. object.put("content", objectdetail);
  626. HashMap<String, String> map = new HashMap<>();
  627. map.put("content-Type", "application/json");
  628. System.out.println(object.toString());
  629. String result = new WebRequest().doPost(object.toString(), url, map);
  630. JSONObject resultobject = JSONObject.parseObject(result);
  631. System.out.println(resultobject);
  632. if (resultobject == null || resultobject.getString("errcode").equals("error")) {
  633. return new JSONArray();
  634. } else {
  635. return resultobject.getJSONObject("results").getJSONArray("list");
  636. }
  637. }
  638. }
  639. /**
  640. * 更新erp出库单标志
  641. *
  642. * @return
  643. * @throws YosException
  644. */
  645. public String updateErpupdateFlag(JSONArray flags) throws YosException {
  646. {
  647. JSONObject object = new JSONObject();
  648. JSONObject objectdetail = new JSONObject();
  649. object.put("access_token", "basicDrp");
  650. object.put("classname", "TstockbillOuts");
  651. object.put("method", "syncFupdateFlags");
  652. objectdetail.put("flags", flags);
  653. object.put("content", objectdetail);
  654. HashMap<String, String> map = new HashMap<>();
  655. map.put("content-Type", "application/json");
  656. String result = new WebRequest().doPost(object.toString(), url, map);
  657. JSONObject resultobject = JSONObject.parseObject(result);
  658. if (resultobject == null || resultobject.getString("errcode").equals("0")) {
  659. return "true";
  660. } else {
  661. return resultobject.getString("errmsg");
  662. }
  663. }
  664. }
  665. // /**
  666. // * crm账号同步反馈
  667. // *
  668. // * @param id crm账号id
  669. // * @param succ 同步是否成功
  670. // * @param errmsg 错误原因
  671. // * @return
  672. // * @throws YosException
  673. // */
  674. // public boolean feedback1(long id, boolean succ, String errmsg) throws YosException {
  675. // JSONArray array = new JSONArray();
  676. // JSONObject object = new JSONObject();
  677. // object.put("id", id);
  678. // object.put("fupdateFlag", succ ? 99 : 4);
  679. // object.put("fupdateWarnLog", errmsg);
  680. // array.add(object);
  681. // HashMap<String, String> map = new HashMap<>();
  682. // map.put("content-Type", "application/json");
  683. //
  684. // System.out.println("feedback1:"+array.toString());
  685. // String result = new WebRequest().doPost(array.toString(), "http://crm.meida.com/dmsService/ext/partner/userYos/syncFupdateFlags", map);
  686. // JSONObject resultobject = JSONObject.parseObject(result);
  687. // return resultobject.getIntValue("code") == 1;
  688. // }
  689. // /**
  690. // * 获取指定的账号信息
  691. // *
  692. // * @param id crm账号id
  693. // * @return
  694. // * @throws YosException
  695. // */
  696. // public JSONObject getSingleAccount(long id) throws YosException {
  697. // String result = doGet("http://crm.meida.com/dmsService/ext/partner/userYos/getSynUserYos?id=" + id);
  698. // JSONObject resultobject = JSONObject.parseObject(result);
  699. // if (resultobject.getIntValue("code") == 20001) {
  700. // loginstatus = false;
  701. // throw new YosException("crm不在登陆状态");
  702. // } else {
  703. // return resultobject.getJSONObject("data");
  704. // }
  705. // }
  706. //
  707. // /**
  708. // * 更新账号有效期
  709. // *
  710. // * @param id crm账号id
  711. // * @param fexpireTime 账号到期时间
  712. // * @return
  713. // * @throws YosException
  714. // */
  715. // public boolean updateAccount(long id, String fexpireTime) throws YosException {
  716. // JSONObject object = new JSONObject();
  717. // object.put("id", id);
  718. // object.put("fexpireTime", fexpireTime);
  719. // HashMap<String, String> map = new HashMap<>();
  720. // map.put("content-Type", "application/json");
  721. // String result = new WebRequest().doPost(object.toString(), "http://crm.meida.com/dmsService/ext/partner/userYos/editSynUserYos", map);
  722. // JSONObject resultobject = JSONObject.parseObject(result);
  723. // if (resultobject.getIntValue("code") == 20001) {
  724. // loginstatus = false;
  725. // throw new YosException("crm不在登陆状态");
  726. // } else {
  727. // return resultobject.getIntValue("code") == 1;
  728. // }
  729. // }
  730. private String doGet(String url) {
  731. PrintWriter out = null;
  732. BufferedReader in = null;
  733. StringBuilder result = new StringBuilder();
  734. HttpURLConnection conn = null;
  735. try {
  736. URL realUrl = new URL(url);
  737. // 打开和URL之间的连接
  738. conn = (HttpURLConnection) realUrl.openConnection();
  739. conn.setRequestProperty("accept", "*/*");
  740. conn.setRequestProperty("connection", "Keep-Alive");
  741. conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
  742. conn.setConnectTimeout(8000);
  743. in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
  744. String line;
  745. while ((line = in.readLine()) != null) {
  746. result.append(line);
  747. }
  748. } catch (Exception e) {
  749. e.printStackTrace();
  750. System.err.println("[POST请求]向地址:" + url + " 发送数据:发生错误!");
  751. } finally {// 使用finally块来关闭输出流、输入流
  752. if (out != null) {
  753. out.close();
  754. out = null;
  755. }
  756. if (in != null) {
  757. try {
  758. in.close();
  759. } catch (IOException e) {
  760. e.printStackTrace();
  761. }
  762. in = null;
  763. }
  764. if (conn != null) {
  765. conn.disconnect();
  766. conn = null;
  767. }
  768. }
  769. return result.toString();
  770. }
  771. }