ERPDocking.java 31 KB

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