123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897 |
- package utility;
- import beans.uploaderpdata.UploadDataToERP_HY;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import common.BaseClass;
- import common.Controller;
- import common.YosException;
- import common.data.Row;
- import common.data.Rows;
- import common.data.SQLFactory;
- import org.dom4j.Document;
- import utility.tools.WebRequest;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.CookieHandler;
- import java.net.CookieManager;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.nio.charset.StandardCharsets;
- import java.util.HashMap;
- public class ERPDocking extends BaseClass {
- public static boolean loginstatus = false;
- String url = "";
- public ERPDocking(String siteid) throws YosException {
- Rows rows = dbConnect.runSqlQuery("SELECT erp_url from sys_site_parameter WHERE siteid='" + siteid + "'");
- if(!siteid.equalsIgnoreCase("lsa")){
- if (rows.isNotEmpty()) {
- url = rows.get(0).getString("erp_url");
- }
- System.err.println(siteid + ":" + url);
- }
- }
- public String getUrl() {
- return url;
- }
- /*
- crm登陆
- */
- // private void login() throws YosException {
- // if (!loginstatus) {
- // /*
- // 自动保存cookie
- // */
- // CookieManager manager = new CookieManager();
- // CookieHandler.setDefault(manager);
- // String s = new WebRequest().doPost("username=yosAdmin&password=yosAdmin123", "http://crm.meida.com/dmsService/ext/partner/login");
- // JSONObject object = JSONObject.parseObject(s);
- // if (object.getIntValue("code") == 1) {
- // loginstatus = true;
- // } else {
- // loginstatus = false;
- // }
- // }
- // }
- /**
- * 获取erp物料档案
- *
- * @param begindate
- * @param pagerows
- * @param pagenum
- * @return
- * @throws YosException
- */
- public JSONArray getErpItemRows(String begindate, int pagerows, int pagenum) throws YosException {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- objectdetail.put("fstatus", "审核");
- objectdetail.put("fmodel", "");
- objectdetail.put("fitemname", "");
- objectdetail.put("fitemclsnum", "");
- objectdetail.put("fitemnos", new JSONArray());
- objectdetail.put("pagerows", pagerows);
- objectdetail.put("pagenum", pagenum);
- objectdetail.put("changedateBeg", begindate);
- object.put("access_token", "basicDrp");
- object.put("classname", "Titem");
- object.put("method", "queryPage");
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- // System.out.println(object.toString());
- // System.out.println(resultobject.toJSONString());
- if (resultobject != null) {
- if (resultobject.getString("errcode").equals("0")) {
- return resultobject.getJSONObject("results").getJSONArray("list");
- } else {
- return new JSONArray();
- }
- } else {
- return new JSONArray();
- }
- }
- /**
- * 查询Erp库存
- *
- * @param pagerows
- * @param pagenum
- * @param fitemnos
- * @return
- * @throws YosException
- */
- public JSONArray getErpIcinvbalRows(int pagerows, int pagenum, JSONArray fitemnos) throws YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- objectdetail.put("fstockno", "01");
- objectdetail.put("fmodel", "");
- objectdetail.put("fitemname", "");
- objectdetail.put("fitemclsnum", "");
- objectdetail.put("fitemnos", fitemnos);
- objectdetail.put("pagerows", pagerows);
- objectdetail.put("pagenum", pagenum);
- object.put("access_token", "basicDrp");
- object.put("classname", "Icinvbal");
- object.put("method", "queryPage");
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- if (resultobject != null) {
- if (resultobject.getString("errcode").equals("0")) {
- return resultobject.getJSONObject("results").getJSONArray("list");
- } else {
- return new JSONArray();
- }
- } else {
- return new JSONArray();
- }
- }
- }
- /**
- * 查询Erp批次库存
- *
- * @param pagerows
- * @param pagenum
- * @param fitemnos
- * @return
- * @throws YosException
- */
- public JSONArray getErpIcinvbalBatchRows(int pagerows, int pagenum, JSONArray fitemnos) throws YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- objectdetail.put("fstockno", "01");
- objectdetail.put("fstockname", "");
- objectdetail.put("fmodel", "");
- objectdetail.put("fitemname", "");
- objectdetail.put("fbatchno", "");
- objectdetail.put("fitemclsnum", "");
- objectdetail.put("onlyFqtyPositive", "true");
- objectdetail.put("fitemnos", fitemnos);
- objectdetail.put("pagerows", pagerows);
- objectdetail.put("pagenum", pagenum);
- object.put("access_token", "basicDrp");
- object.put("classname", "Icinvbal");
- object.put("method", "queryPageOfBatch");
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- if (resultobject != null) {
- if (resultobject.getString("errcode").equals("0")) {
- return resultobject.getJSONObject("results").getJSONArray("list");
- } else {
- return new JSONArray();
- }
- } else {
- return new JSONArray();
- }
- }
- }
- /**
- * 查询Erp批次库存
- *
- * @param pagerows
- * @param pagenum
- * @param fitemnos
- * @return
- * @throws YosException
- */
- public JSONArray getErpIcinvbalBatchRowsforbatchno(int pagerows, int pagenum, JSONArray fitemnos,String fbatchno) throws YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- objectdetail.put("fstockno", "01");
- objectdetail.put("fstockname", "");
- objectdetail.put("fmodel", "");
- objectdetail.put("fitemname", "");
- objectdetail.put("fbatchno", fbatchno);
- objectdetail.put("fitemclsnum", "");
- objectdetail.put("onlyFqtyPositive", "true");
- objectdetail.put("fitemnos", fitemnos);
- objectdetail.put("pagerows", pagerows);
- objectdetail.put("pagenum", pagenum);
- object.put("access_token", "basicDrp");
- object.put("classname", "Icinvbal");
- object.put("method", "queryPageOfBatch");
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- if (resultobject != null) {
- if (resultobject.getString("errcode").equals("0")) {
- return resultobject.getJSONObject("results").getJSONArray("list");
- } else {
- return new JSONArray();
- }
- } else {
- return new JSONArray();
- }
- }
- }
- /**
- * 创建Erp发货单
- *
- * @param dispatchRow
- * @param dispatchItems
- * @return
- * @throws YosException
- */
- public String createErpSainvoice(Row dispatchRow, Rows dispatchItems, Controller controller, long sa_dispatchid) throws YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- JSONArray jsonArray = new JSONArray();
- object.put("access_token", "basicDrp");
- object.put("classname", "Sainvoice");
- object.put("method", "createSainvoice");
- objectdetail.put("finvonum", dispatchRow.getString("billno"));
- objectdetail.put("fagentnum", dispatchRow.getString("agentnum"));
- objectdetail.put("fagentname", dispatchRow.getString("enterprisename"));
- objectdetail.put("fsonum", dispatchRow.getString("sonum"));
- objectdetail.put("fdate", dispatchRow.getString("billdate"));
- objectdetail.put("fnotes", dispatchRow.getString("remarks"));
- objectdetail.put("fcontact", dispatchRow.getString("name"));
- objectdetail.put("fmobilephone", dispatchRow.getString("phonenumber"));
- objectdetail.put("faddress", dispatchRow.getString("address"));
- objectdetail.put("createby", dispatchRow.getString("createby"));
- if (dispatchItems.isNotEmpty()) {
- for (Row row : dispatchItems) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("fsonum", row.getString("sonum"));
- jsonObject.put("fsorownum", row.getString("sorowno"));
- jsonObject.put("fprodnum", row.getString("itemno"));
- jsonObject.put("fbatchbnum", row.getString("batchno"));
- jsonObject.put("frownum", row.getString("rowno"));
- jsonObject.put("fqty", row.getString("qty"));
- jsonObject.put("fprice", row.getString("price"));
- jsonObject.put("fremarks", row.getString("remarks"));
- jsonArray.add(jsonObject);
- }
- }
- objectdetail.put("details", jsonArray);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- saveLog(controller, "sa_dispatch", sa_dispatchid, "创建erp发货单", object.toString(), resultobject, dispatchRow.getString("billno"));
- if (resultobject != null) {
- if (resultobject.getString("errcode").equals("0")) {
- return "true";
- } else {
- return resultobject.getString("errmsg");
- }
- } else {
- return "false";
- }
- }
- }
- /**
- * 查询Erp发货单(单个)
- *
- * @param billno
- * @return
- * @throws YosException
- */
- public JSONArray queryErpSainvoice(String billno) throws YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- object.put("access_token", "basicDrp");
- object.put("classname", "Sainvoice");
- object.put("method", "queryOne");
- objectdetail.put("finvonum", billno);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- System.out.println(resultobject);
- if (resultobject == null || resultobject.getString("errcode").equals("error")) {
- return new JSONArray();
- } else {
- return resultobject.getJSONObject("results").getJSONArray("details");
- }
- }
- }
- /**
- * 查询Erp发货单(批量)
- *
- * @param pagerows
- * @param pagenum
- * @param finvonums
- * @param fagentnum
- * @param fsonum
- * @param fstatus
- * @param onlyNeedClosed
- * @return
- * @throws YosException
- */
- public JSONArray queryErpSainvoices(int pagerows, int pagenum, JSONArray finvonums, String fagentnum, String
- fsonum, String fstatus, boolean onlyNeedClosed, boolean onlyNeedPartialOuts, boolean onlyWithCheckedOuts) throws
- YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- object.put("access_token", "basicDrp");
- object.put("classname", "Sainvoice");
- object.put("method", "queryPage");
- objectdetail.put("pagenum", pagenum);
- objectdetail.put("pagerows", pagerows);
- objectdetail.put("finvonums", finvonums);
- objectdetail.put("fagentnum", fagentnum);
- objectdetail.put("fsonum", fsonum);
- objectdetail.put("fstatus", fstatus);
- objectdetail.put("onlyNeedClosed", onlyNeedClosed);
- objectdetail.put("onlyNeedPartialOuts", onlyNeedPartialOuts);
- objectdetail.put("onlyWithCheckedOuts", onlyWithCheckedOuts);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- System.out.println(object.toString());
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- System.out.println(resultobject);
- if (resultobject == null || resultobject.getString("errcode").equals("error")) {
- return new JSONArray();
- } else {
- return resultobject.getJSONObject("results").getJSONArray("list");
- }
- }
- }
- /**
- * 关闭Erp发货单
- *
- * @param billno
- * @param isManual
- * @return
- * @throws YosException
- */
- public String closeErpSainvoice(String billno, boolean isManual, Controller controller, long sa_dispatchid) throws
- YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- object.put("access_token", "basicDrp");
- object.put("classname", "Sainvoice");
- object.put("method", "closeSainvoice");
- objectdetail.put("finvonum", billno);
- objectdetail.put("isManual", isManual);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- saveLog(controller, "sa_dispatch", sa_dispatchid, "关闭发货单", object.toString(), resultobject, billno);
- if (resultobject != null) {
- if (resultobject.getString("errcode").equals("0")) {
- return "true";
- } else {
- return resultobject.getString("errmsg");
- }
- } else {
- return "false";
- }
- }
- }
- /**
- * Erp发货单行关闭
- *
- * @param billno
- * @param controller
- * @param rowno
- * @param itemno
- * @param sa_dispatchid
- * @return
- * @throws YosException
- */
- public String closeErpSainvoiceRow(String billno, Controller controller, long rowno, String itemno,
- long sa_dispatchid) throws YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- object.put("access_token", "basicDrp");
- object.put("classname", "Sainvoice");
- object.put("method", "closeRowOfSainvoice");
- objectdetail.put("finvonum", billno);
- objectdetail.put("fprodnum", itemno);
- objectdetail.put("frownum", rowno);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- saveLog(controller, "sa_dispatch", sa_dispatchid, "发货单行关闭", object.toString(), resultobject, billno);
- if (resultobject != null) {
- if (resultobject.getString("errcode").equals("0")) {
- return "true";
- } else {
- return resultobject.getString("errmsg");
- }
- } else {
- return resultobject.getString("false");
- }
- }
- }
- /**
- * 创建Erp退/换货单
- *
- * @param aftersalesmagRow
- * @param aftersalesmagItems
- * @return
- * @throws YosException
- */
- public String createErpSareturn(Row aftersalesmagRow, Rows aftersalesmagItems, Controller controller,
- long sa_aftersalesmagid) throws YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- JSONArray jsonArray = new JSONArray();
- object.put("access_token", "basicDrp");
- object.put("classname", "Sareturn");
- object.put("method", "createSareturn");
- objectdetail.put("freturnnum", aftersalesmagRow.getString("billno"));
- objectdetail.put("fagentnum", aftersalesmagRow.getString("agentnum"));
- objectdetail.put("fagentname", aftersalesmagRow.getString("enterprisename"));
- objectdetail.put("faccclsnum", "01");
- objectdetail.put("fdate", aftersalesmagRow.getString("billdate"));
- objectdetail.put("fnotes", aftersalesmagRow.getString("reason"));
- objectdetail.put("createby", aftersalesmagRow.getString("createby"));
- if (aftersalesmagRow.getString("type").equals("退货单")) {
- objectdetail.put("freturntype", "退货");
- } else if (aftersalesmagRow.getString("type").equals("换货单")) {
- objectdetail.put("freturntype", "换货");
- }
- if (aftersalesmagItems.isNotEmpty()) {
- for (Row row : aftersalesmagItems) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("fprodnum", row.getString("itemno"));
- jsonObject.put("fbatchbnum", row.getString("batchno"));
- jsonObject.put("fqty", row.getString("qty"));
- jsonObject.put("fprice", row.getString("price"));
- jsonObject.put("fremarks", row.getString("reason"));
- jsonArray.add(jsonObject);
- }
- }
- objectdetail.put("details", jsonArray);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- System.out.println(object.toString());
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- saveLog(controller, "sa_aftersalesmag", sa_aftersalesmagid, "创建erp退/换货单", object.toString(), resultobject, aftersalesmagRow.getString("billno"));
- if (resultobject != null) {
- if (resultobject.getString("errcode").equals("0")) {
- return "true";
- } else {
- return resultobject.getString("errmsg");
- }
- } else {
- return "false";
- }
- }
- }
- /**
- * 查询Erp退/换货单(单个)
- *
- * @param billno
- * @return
- * @throws YosException
- */
- public JSONArray queryErpSareturn(String billno) throws YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- object.put("access_token", "basicDrp");
- object.put("classname", "Sareturn");
- object.put("method", "queryOne");
- objectdetail.put("freturnnum", billno);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- System.out.println(resultobject);
- if (resultobject == null || resultobject.getString("errcode").equals("error")) {
- return new JSONArray();
- } else {
- return resultobject.getJSONObject("results").getJSONArray("details");
- }
- }
- }
- /**
- * 查询Erpt退/换货单(批量)
- *
- * @param pagerows
- * @param pagenum
- * @param freturnnums
- * @param fagentnum
- * @param fsonum
- * @param fstatus
- * @param onlyNeedClosed
- * @return
- * @throws YosException
- */
- public JSONArray queryErpSareturns(int pagerows, int pagenum, JSONArray freturnnums, String fagentnum, String
- fsonum, String freturntype, String fstatus, boolean onlyNeedClosed) throws YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- object.put("access_token", "basicDrp");
- object.put("classname", "Sareturn");
- object.put("method", "queryPage");
- objectdetail.put("pagenum", pagenum);
- objectdetail.put("pagerows", pagerows);
- objectdetail.put("freturnnums", freturnnums);
- objectdetail.put("fagentnum", fagentnum);
- objectdetail.put("fsonum", fsonum);
- objectdetail.put("freturntype", freturntype);
- objectdetail.put("fstatus", fstatus);
- objectdetail.put("onlyNeedClosed", onlyNeedClosed);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- System.out.println(object.toString());
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- System.out.println(resultobject);
- if (resultobject == null || resultobject.getString("errcode").equals("error")) {
- return new JSONArray();
- } else {
- return resultobject.getJSONObject("results").getJSONArray("list");
- }
- }
- }
- /**
- * 复核Erp退/换货单
- *
- * @param billno
- * @param isManual
- * @return
- * @throws YosException
- */
- public String recheckErpSareturn(String billno, boolean isManual, Controller controller, long sa_aftersalesmagid) throws
- YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- object.put("access_token", "basicDrp");
- object.put("classname", "Sareturn");
- object.put("method", "closeSareturn");
- objectdetail.put("freturnnum", billno);
- objectdetail.put("isManual", isManual);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- saveLog(controller, "sa_aftersalesmag", sa_aftersalesmagid, "复核erp退/换货单", object.toString(), resultobject, billno);
- if (resultobject != null) {
- if (resultobject.getString("errcode").equals("0")) {
- return "true";
- } else {
- return resultobject.getString("errmsg");
- }
- } else {
- return "false";
- }
- }
- }
- /**
- * 上传日志更新
- *
- * @param controller
- * @param ownertable
- * @param ownerid
- * @param type
- * @param request
- * @param response
- * @param billno
- * @return
- */
- public static boolean saveLog(Controller controller, String ownertable, long ownerid, String type, String
- request,
- JSONObject response, String billno) {
- boolean issuccess = false;
- try {
- Rows rows = controller.dbConnect.runSqlQuery(
- "select * from sys_erpupdatelog where ownertable='" + ownertable + "' and ownerid=" + ownerid);
- SQLFactory sqlFactory;
- if (!rows.isEmpty()) {
- sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志更新");
- sqlFactory.addParameter("sys_erpupdatelogid", rows.get(0).getLong("sys_erpupdatelogid"));
- } else {
- sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志新增");
- sqlFactory.addParameter("sys_erpupdatelogid", controller.createTableID("sys_erpupdatelog"));
- }
- sqlFactory.addParameter("siteid", controller.siteid);
- sqlFactory.addParameter("userid", controller.userid);
- sqlFactory.addParameter("username", controller.username);
- sqlFactory.addParameter("ownerid", ownerid);
- sqlFactory.addParameter("ownertable", ownertable);
- sqlFactory.addParameter("type", type);
- sqlFactory.addParameter("request", request);
- sqlFactory.addParameter("response", response.toJSONString());
- if ("0".equals(response.getString("errcode"))) {
- sqlFactory.addParameter("erpbillno", billno);
- sqlFactory.addParameter("errmsg", "");
- issuccess = true;
- } else {
- sqlFactory.addParameter("erpbillno", "");
- sqlFactory.addParameter("errmsg", response.getString("errmsg"));
- issuccess = false;
- }
- sqlFactory.addParameter("status", response.getString("errcode"));
- logger.info("sql:"+sqlFactory.getSQL());
- controller.dbConnect.runSqlUpdate(sqlFactory);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return issuccess;
- }
- /**
- * 查询销售出库单
- *
- * @param pagerows
- * @param pagenum
- * @return
- * @throws YosException
- */
- public JSONArray queryErpStockBill(int pagerows, int pagenum, String fbtname) throws YosException {
- {
- JSONArray fupdateFlags = new JSONArray();
- fupdateFlags.add(0);
- fupdateFlags.add(99);
- fupdateFlags.add(2);
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- object.put("access_token", "basicDrp");
- object.put("classname", "TstockbillOuts");
- object.put("method", "queryPageForSyncYos");
- objectdetail.put("pagenum", pagenum);
- objectdetail.put("pagerows", pagerows);
- objectdetail.put("fbillnums", new JSONArray());
- objectdetail.put("fagentnum", "");
- objectdetail.put("fstatus", "审核");
- objectdetail.put("frb", "");
- objectdetail.put("fstockno", "");
- objectdetail.put("fbtname", fbtname);
- objectdetail.put("fminperiod", "");
- objectdetail.put("fupdateFlags", fupdateFlags);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- System.out.println(object.toString());
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- System.out.println(resultobject);
- if (resultobject == null || resultobject.getString("errcode").equals("error")) {
- return new JSONArray();
- } else {
- return resultobject.getJSONObject("results").getJSONArray("list");
- }
- }
- }
- /**
- * 更新erp出库单标志
- *
- * @return
- * @throws YosException
- */
- public String updateErpupdateFlag(JSONArray flags) throws YosException {
- {
- JSONObject object = new JSONObject();
- JSONObject objectdetail = new JSONObject();
- object.put("access_token", "basicDrp");
- object.put("classname", "TstockbillOuts");
- object.put("method", "syncFupdateFlags");
- objectdetail.put("flags", flags);
- object.put("content", objectdetail);
- HashMap<String, String> map = new HashMap<>();
- map.put("content-Type", "application/json");
- String result = new WebRequest().doPost(object.toString(), url, map);
- JSONObject resultobject = JSONObject.parseObject(result);
- if (resultobject != null) {
- if (resultobject.getString("errcode").equals("0")) {
- return "true";
- } else {
- return resultobject.getString("errmsg");
- }
- } else {
- return "false";
- }
- }
- }
- // /**
- // * crm账号同步反馈
- // *
- // * @param id crm账号id
- // * @param succ 同步是否成功
- // * @param errmsg 错误原因
- // * @return
- // * @throws YosException
- // */
- // public boolean feedback1(long id, boolean succ, String errmsg) throws YosException {
- // JSONArray array = new JSONArray();
- // JSONObject object = new JSONObject();
- // object.put("id", id);
- // object.put("fupdateFlag", succ ? 99 : 4);
- // object.put("fupdateWarnLog", errmsg);
- // array.add(object);
- // HashMap<String, String> map = new HashMap<>();
- // map.put("content-Type", "application/json");
- //
- // System.out.println("feedback1:"+array.toString());
- // String result = new WebRequest().doPost(array.toString(), "http://crm.meida.com/dmsService/ext/partner/userYos/syncFupdateFlags", map);
- // JSONObject resultobject = JSONObject.parseObject(result);
- // return resultobject.getIntValue("code") == 1;
- // }
- // /**
- // * 获取指定的账号信息
- // *
- // * @param id crm账号id
- // * @return
- // * @throws YosException
- // */
- // public JSONObject getSingleAccount(long id) throws YosException {
- // String result = doGet("http://crm.meida.com/dmsService/ext/partner/userYos/getSynUserYos?id=" + id);
- // JSONObject resultobject = JSONObject.parseObject(result);
- // if (resultobject.getIntValue("code") == 20001) {
- // loginstatus = false;
- // throw new YosException("crm不在登陆状态");
- // } else {
- // return resultobject.getJSONObject("data");
- // }
- // }
- //
- // /**
- // * 更新账号有效期
- // *
- // * @param id crm账号id
- // * @param fexpireTime 账号到期时间
- // * @return
- // * @throws YosException
- // */
- // public boolean updateAccount(long id, String fexpireTime) throws YosException {
- // JSONObject object = new JSONObject();
- // object.put("id", id);
- // object.put("fexpireTime", fexpireTime);
- // HashMap<String, String> map = new HashMap<>();
- // map.put("content-Type", "application/json");
- // String result = new WebRequest().doPost(object.toString(), "http://crm.meida.com/dmsService/ext/partner/userYos/editSynUserYos", map);
- // JSONObject resultobject = JSONObject.parseObject(result);
- // if (resultobject.getIntValue("code") == 20001) {
- // loginstatus = false;
- // throw new YosException("crm不在登陆状态");
- // } else {
- // return resultobject.getIntValue("code") == 1;
- // }
- // }
- private String doGet(String url) {
- PrintWriter out = null;
- BufferedReader in = null;
- StringBuilder result = new StringBuilder();
- HttpURLConnection conn = null;
- try {
- URL realUrl = new URL(url);
- // 打开和URL之间的连接
- conn = (HttpURLConnection) realUrl.openConnection();
- conn.setRequestProperty("accept", "*/*");
- conn.setRequestProperty("connection", "Keep-Alive");
- conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
- conn.setConnectTimeout(8000);
- in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
- String line;
- while ((line = in.readLine()) != null) {
- result.append(line);
- }
- } catch (Exception e) {
- e.printStackTrace();
- System.err.println("[POST请求]向地址:" + url + " 发送数据:发生错误!");
- } finally {// 使用finally块来关闭输出流、输入流
- if (out != null) {
- out.close();
- out = null;
- }
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- in = null;
- }
- if (conn != null) {
- conn.disconnect();
- conn = null;
- }
- }
- return result.toString();
- }
- }
|