ERPDocking.java 34 KB

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