ERPDocking.java 31 KB

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