UploadDataToERP_TZ.java 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. /**
  2. *
  3. */
  4. package beans.uploaderpdata;
  5. import org.apache.commons.lang.StringUtils;
  6. import org.apache.log4j.Logger;
  7. import org.dom4j.Document;
  8. import org.dom4j.DocumentHelper;
  9. import beans.brand.Brand;
  10. import beans.uploaderpdata.erpservice.ChangeSalesOrderDataEsoRequestChangeSalesOrderDataEsoRequest;
  11. import beans.uploaderpdata.erpservice.ChangeSalesOrderDataEsoResponseChangeSalesOrderDataEsoResponse;
  12. import beans.uploaderpdata.erpservice.CreateMiscIssueDataESORequestCreateMiscIssueDataESORequest;
  13. import beans.uploaderpdata.erpservice.CreateMiscIssueDataESOResponseCreateMiscIssueDataESOResponse;
  14. import beans.uploaderpdata.erpservice.CreateSalesOrderDataESORequestCreateSalesOrderDataESORequest;
  15. import beans.uploaderpdata.erpservice.CreateSalesOrderDataESOResponseCreateSalesOrderDataESOResponse;
  16. import beans.uploaderpdata.erpservice.CreateSalesReturnEsoRequestCreateSalesReturnEsoRequest;
  17. import beans.uploaderpdata.erpservice.CreateSalesReturnEsoResponseCreateSalesReturnEsoResponse;
  18. import beans.uploaderpdata.erpservice.CreateShippingNoticeESORequestCreateShippingNoticeESORequest;
  19. import beans.uploaderpdata.erpservice.CreateShippingNoticeESOResponseCreateShippingNoticeESOResponse;
  20. import beans.uploaderpdata.erpservice.TIPTOPServiceGateWay;
  21. import beans.uploaderpdata.erpservice.TIPTOPServiceGateWayPortType;
  22. import common.BaseClass;
  23. import common.Controller;
  24. import common.YosException;
  25. import common.data.Row;
  26. import common.data.Rows;
  27. import common.data.RowsMap;
  28. import common.data.SQLFactory;
  29. import java.math.BigDecimal;
  30. import java.text.SimpleDateFormat;
  31. import java.util.ArrayList;
  32. import java.util.Date;
  33. /**
  34. * @author Administrator
  35. *
  36. */
  37. public class UploadDataToERP_TZ extends BaseClass {
  38. private static final String SITEID = "IDCZJ10";
  39. private static Logger logger = Logger.getLogger(UploadDataToERP_TZ.class);
  40. /**
  41. * 订单上传erp服务
  42. */
  43. public static boolean uploadSaorder_post(Controller controller, long uniqueIDValue) throws YosException {
  44. boolean issucess = false;
  45. Rows saorderRows = controller.dbConnect.runSqlQuery(
  46. "select t1.*,t2.projectname,t3.address,t3.phonenumber,t3.name,t3.province,t3.city,t3.county,t4.`name` salername,t4.hrcode,t5.agentnum,t6.erpagentnum,t8.erpagentnum payentcode,t9.erpagentnum recentcode from sa_order t1 left join sa_project t2 on t1.sa_projectid=t2.sa_projectid and t1.siteid=t2.siteid left join sys_enterprise_contacts t3 on t1.rec_contactsid=t3.contactsid and t1.siteid=t3.siteid left join sys_hr t4 on t1.saler_hrid=t4.hrid and t1.siteid=t4.siteid left join sa_agents t5 on t1.sys_enterpriseid=t5.sys_enterpriseid and t1.siteid=t5.siteid left join sys_dataextend t6 on t6.ownertable='sys_enterprise' and t6.ownerid=t5.sys_enterpriseid and t6.siteid=t5.siteid left join sys_enterprise t7 on t7.sys_enterpriseid=t1.pay_enterpriseid and t7.siteid=t1.siteid left join sys_dataextend t8 on t8.ownertable='sys_enterprise' and t8.ownerid=t7.sys_enterpriseid and t8.siteid=t7.siteid left join sys_dataextend t9 on t9.ownertable='sys_enterprise' and t9.ownerid=t3.sys_enterpriseid and t9.siteid=t3.siteid where t1.checkdate is not null and t1.sa_orderid="
  47. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "'");
  48. Rows saorderdetailRows = controller.dbConnect.runSqlQuery(
  49. "select t1.*,t3.erpitemno,t2.standards from sa_orderitems t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid left join plm_itemextend t3 on t1.itemid=t3.itemid and t1.siteid=t3.siteid where t1.sa_orderid="
  50. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "' order by t1.rowno");
  51. ArrayList<Long> ids = saorderdetailRows.toArrayList("itemid", new ArrayList<>());
  52. // 商品领域
  53. RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(controller, ids);
  54. // 品牌
  55. RowsMap brandRowsMap = Brand.getBrandRowsMap(controller, ids);
  56. if (saorderRows.isEmpty()) {
  57. return issucess;
  58. }
  59. String fsonum = saorderRows.get(0).getString("sonum");
  60. String fsaler = saorderRows.get(0).getString("salername");
  61. String hrcode = saorderRows.get(0).getString("hrcode");
  62. String checkdate = getDate_Str1(saorderRows.get(0).getDate("checkdate"));
  63. String fagentnum = saorderRows.get(0).getString("agentnum");
  64. String fcontact = saorderRows.get(0).getString("name");
  65. String fphonenumber = saorderRows.get(0).getString("phonenumber");
  66. String faddress = saorderRows.get(0).getString("address");
  67. String fnotes = saorderRows.get(0).getString("remarks");
  68. String ftype = saorderRows.get(0).getString("type");
  69. String fsaletype = saorderRows.get(0).getString("saletype");
  70. String fprojectname = saorderRows.get(0).getString("projectnote");
  71. String freviewtype = saorderRows.get(0).getString("reviewtype");
  72. String fpayagentnum = saorderRows.get(0).getString("payentcode");
  73. String frecagentnum = saorderRows.get(0).getString("recentcode");
  74. if ("项目订单".equals(ftype)) {
  75. fprojectname = saorderRows.get(0).getString("projectname");
  76. }
  77. String ferptype = "ZSO1";
  78. // switch (ftype) {
  79. // case "标准订单": {
  80. // ftype = "PSO1";
  81. // break;
  82. // }
  83. // default:
  84. // break;
  85. // }
  86. if (!StringUtils.isBlank(saorderRows.get(0).getString("erpagentnum"))) {
  87. fagentnum = saorderRows.get(0).getString("erpagentnum");
  88. }
  89. StringBuffer xmlbuffer = new StringBuffer();
  90. xmlbuffer.append("<Request>");
  91. xmlbuffer.append("<Access>");
  92. xmlbuffer.append("<Authentication user=\"tiptop\" password=\"\"/>");
  93. xmlbuffer.append("<Connection application=\"ESO\" source=\"192.168.10.115\"/>");
  94. xmlbuffer.append("<Organization name=\"" + SITEID + "\"/>");
  95. xmlbuffer.append("<Locale language=\"zh_cn\"/>");
  96. xmlbuffer.append("</Access>");
  97. xmlbuffer.append("<RequestContent>");
  98. xmlbuffer.append("<Document>");
  99. xmlbuffer.append("<RecordSet id=\"1\">");
  100. xmlbuffer.append("<Master name=\"oea_file\">");
  101. xmlbuffer.append("<Record>");
  102. xmlbuffer.append("<Field name=\"oea00\" value=\"\"/>");
  103. xmlbuffer.append("<Field name=\"oea01\" value=\"" + ferptype + "\"/>");// 单别
  104. xmlbuffer.append("<Field name=\"oea02\" value=\"" + checkdate + "\"/>");// 单据日期
  105. xmlbuffer.append("<Field name=\"oea03\" value=\"" + fpayagentnum + "\"/>");// 付款客户编号
  106. xmlbuffer.append("<Field name=\"oea04\" value=\"" + frecagentnum + "\"/>");// 收货客户编号
  107. xmlbuffer.append("<Field name=\"oea10\" value=\"" + fsonum + "\"/>");// 订单编号
  108. xmlbuffer.append("<Field name=\"oea14\" value=\"" + hrcode.toLowerCase() + "\"/>");// 业务员
  109. xmlbuffer.append("<Field name=\"oap041\" value=\"" + fcontact + ";" + fphonenumber + ";" + faddress + "\"/>");// 地址
  110. xmlbuffer.append("<Field name=\"oap042\" value=\"" + saorderRows.get(0).getString("province") + "->"
  111. + saorderRows.get(0).getString("city") + "->" + saorderRows.get(0).getString("county") + "\"/>");// 省市县
  112. xmlbuffer.append("<Field name=\"oap044\" value=\"" + fprojectname + "\"/>");// 项目
  113. xmlbuffer.append("<Field name=\"oeaud01\" value=\"" + fnotes + "\"/>");// 备注
  114. xmlbuffer.append("<Field name=\"oea25\" value=\"" + fsaletype + "\"/>");// 销售分类
  115. xmlbuffer.append("<Field name=\"oeaud10\" value=\"" + freviewtype + "\"/>");// 订单评审类型
  116. xmlbuffer.append("<Detail name=\"oeb_file\" node_id=\"1_1\">");
  117. if (!saorderdetailRows.isEmpty()) {
  118. for (Row row : saorderdetailRows) {
  119. String ferpitemno = row.getString("erpitemno");
  120. String fitemno = row.getString("itemno");
  121. double fqty = row.getDouble("qty");
  122. String fplandate = getDate_Str1(row.getDate("deliverydate"));
  123. String fdetailnotes = row.getString("remarks");
  124. double frateprice = row.getDouble("price");
  125. double frateamount = row.getDouble("amount");
  126. long frownum = row.getLong("rowno");
  127. String fproductstandard = row.getString("standards");
  128. String fieldname = "";
  129. String fbrand = "";
  130. if (!tradefieldRowsMap.get(row.getString("itemid")).isEmpty()) {
  131. fieldname = tradefieldRowsMap.get(row.getString("itemid")).get(0).getString("tradefield");
  132. }
  133. if (!brandRowsMap.get(row.getString("itemid")).isEmpty()) {
  134. fbrand = brandRowsMap.get(row.getString("itemid")).get(0).getString("brandname");
  135. }
  136. xmlbuffer.append("<Record>");
  137. xmlbuffer.append("<Field name=\"oeb04\" value=\"" + ferpitemno + "\"/>");// 料号(ERP商品编号)
  138. xmlbuffer.append("<Field name=\"oeb11\" value=\"" + fitemno + "\"/>");// 客户产品编码(DRP商品编号)
  139. xmlbuffer.append("<Field name=\"oeb12\" value=\"" + fqty + "\"/>");// 数量
  140. xmlbuffer.append("<Field name=\"oeb15\" value=\"" + fplandate + "\"/>");// 交货日期
  141. xmlbuffer.append("<Field name=\"oeb13\" value=\"" + frateprice + "\"/>");// 单价
  142. xmlbuffer.append("<Field name=\"oeb14t\" value=\"" + frateamount + "\"/>");// 金额
  143. xmlbuffer.append("<Field name=\"oebud04\" value=\"" + fsonum + "\"/>");// 订单号
  144. xmlbuffer.append("<Field name=\"oebud05\" value=\"" + frownum + "\"/>");// 行号
  145. xmlbuffer.append("<Field name=\"oeb30\" value=\"\"/>");// 预计归还日期
  146. xmlbuffer.append("<Field name=\"oao06\" value=\"" + fieldname + "->" + fproductstandard + "->" + fbrand
  147. + "->" + fdetailnotes + "\"/>");
  148. xmlbuffer.append("</Record>");
  149. }
  150. }
  151. xmlbuffer.append("</Detail>");
  152. xmlbuffer.append("</Record>");
  153. xmlbuffer.append("</Master>");
  154. xmlbuffer.append("</RecordSet>");
  155. xmlbuffer.append("</Document>");
  156. xmlbuffer.append("</RequestContent>");
  157. xmlbuffer.append("</Request>");
  158. logger.info("订单上传请求" + fsonum + ":" + xmlbuffer.toString());
  159. try {
  160. TIPTOPServiceGateWay gateWay = new TIPTOPServiceGateWay();
  161. TIPTOPServiceGateWayPortType portType = gateWay.getTIPTOPServiceGateWayPortType();
  162. CreateSalesOrderDataESORequestCreateSalesOrderDataESORequest esoRequest = new CreateSalesOrderDataESORequestCreateSalesOrderDataESORequest();
  163. esoRequest.setRequest(xmlbuffer.toString());
  164. CreateSalesOrderDataESOResponseCreateSalesOrderDataESOResponse esoResponse = portType
  165. .createSalesOrderDataESO(esoRequest);
  166. String result = esoResponse.getResponse();
  167. logger.info("订单上传返回" + fsonum + ":" + result);
  168. Document document = DocumentHelper.parseText(result);
  169. issucess = saveLog(controller, "sa_order", uniqueIDValue, "订单上传", xmlbuffer.toString(), document);
  170. issucess = saveDataextend(controller, "sa_order", uniqueIDValue, document);
  171. } catch (Exception e) {
  172. logger.info("订单上传错误" + fsonum + ":" + e.getMessage());
  173. e.printStackTrace();
  174. }
  175. return issucess;
  176. }
  177. /**
  178. * 订单变更上传erp服务
  179. */
  180. public static boolean uploadSaorderChange_post(Controller controller, long uniqueIDValue) throws YosException {
  181. boolean issucess = false;
  182. Rows orderitemsChangeRows = controller.dbConnect.runSqlQuery(
  183. "select t1.*,t2.sonum,t7.hrcode from sa_orderitems_change t1 left join sa_order t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid left join sys_hr t7 on t7.siteid=t1.siteid and t1.createuserid=t7.userid where t1.sa_orderitems_changeid="
  184. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "'");
  185. Rows orderitemsChangemxRows = controller.dbConnect.runSqlQuery(
  186. "select t.*,t3.erpitemno,t1.rowno from sa_orderitems_changemx t left join sa_orderitems t1 on t.sa_orderitemsid=t1.sa_orderitemsid and t.siteid=t1.siteid left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid left join plm_itemextend t3 on t.itemid=t3.itemid and t.siteid=t3.siteid where t.sa_orderitems_changeid="
  187. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "' order by t1.rowno");
  188. if (orderitemsChangeRows.isEmpty()) {
  189. return issucess;
  190. }
  191. Rows erpupdatelogRows = controller.dbConnect
  192. .runSqlQuery("select * from sys_dataextend where ownertable='sa_order' and ownerid="
  193. + orderitemsChangeRows.get(0).getLong("sa_orderid") + " order by changedate desc");
  194. if (erpupdatelogRows.isEmpty()) {
  195. return issucess;
  196. }
  197. String fsonum = orderitemsChangeRows.get(0).getString("sonum");
  198. String changeby = orderitemsChangeRows.get(0).getString("hrcode").toLowerCase();
  199. String fdate = getDate_Str1(orderitemsChangeRows.get(0).getDate("createdate"));
  200. boolean isjiean = orderitemsChangeRows.get(0).getString("remarks").equals("订单结案变更");
  201. String ferpbillno = erpupdatelogRows.get(0).getString("erpbillno");
  202. StringBuffer xmlbuffer = new StringBuffer();
  203. xmlbuffer.append("<Request>");
  204. xmlbuffer.append("<Access>");
  205. xmlbuffer.append("<Authentication user=\"tiptop\" password=\"\"/>");
  206. xmlbuffer.append("<Connection application=\"ESO\" source=\"192.168.10.115\"/>");
  207. xmlbuffer.append("<Organization name=\"" + SITEID + "\"/>");
  208. xmlbuffer.append("<Locale language=\"zh_cn\"/>");
  209. xmlbuffer.append("</Access>");
  210. xmlbuffer.append("<RequestContent>");
  211. xmlbuffer.append("<Document>");
  212. xmlbuffer.append("<RecordSet id=\"1\">");
  213. xmlbuffer.append("<Master name=\"oep_file\">");
  214. xmlbuffer.append("<Record>");
  215. xmlbuffer.append("<Field name=\"oep01\" value=\"" + ferpbillno + "\"/>");// 订单编号
  216. xmlbuffer.append("<Field name=\"oep04\" value=\"" + fdate + "\"/>");// 单据日期
  217. xmlbuffer.append("<Field name=\"oep12\" value=\"" + changeby + "\"/>");// 变更人员
  218. xmlbuffer.append("<Field name=\"oep13\" value=\"" + "37" + "\"/>");// 理由码代码
  219. xmlbuffer.append("<Detail name=\"oeq_file\" node_id=\"1_1\">");
  220. for (Row row : orderitemsChangemxRows) {
  221. int frownum = row.getInteger("rowno");
  222. BigDecimal fqty = row.getBigDecimal("newvalue");
  223. xmlbuffer.append("<Record>");
  224. xmlbuffer.append("<Field name=\"oeq03\" value=\"" + frownum + "\"/>");// 行号
  225. xmlbuffer.append("<Field name=\"oeq12a\" value=\"" + fqty + "\"/>");// 变更后数量
  226. xmlbuffer.append("<Field name=\"oeq13a\" value=\"" + "" + "\"/>");// 变更后单价
  227. xmlbuffer.append("<Field name=\"oeq15a\" value=\"" + "" + "\"/>");// 变更后交货日期
  228. xmlbuffer.append("<Field name=\"oeq50\" value=\"" + "" + "\"/>");// 备注
  229. xmlbuffer.append("<Field name=\"oequd06\" value=\"" + (isjiean ? "Y" : "N") + "\"/>");// 是否结案
  230. xmlbuffer.append("</Record>");
  231. }
  232. xmlbuffer.append("</Detail>");
  233. xmlbuffer.append("</Record>");
  234. xmlbuffer.append("</Master>");
  235. xmlbuffer.append("</RecordSet>");
  236. xmlbuffer.append("</Document>");
  237. xmlbuffer.append("</RequestContent>");
  238. xmlbuffer.append("</Request>");
  239. logger.info("订单变更上传请求" + fsonum + ":" + xmlbuffer.toString());
  240. try {
  241. TIPTOPServiceGateWay gateWay = new TIPTOPServiceGateWay();
  242. TIPTOPServiceGateWayPortType portType = gateWay.getTIPTOPServiceGateWayPortType();
  243. ChangeSalesOrderDataEsoRequestChangeSalesOrderDataEsoRequest esoRequest = new ChangeSalesOrderDataEsoRequestChangeSalesOrderDataEsoRequest();
  244. esoRequest.setRequest(xmlbuffer.toString());
  245. ChangeSalesOrderDataEsoResponseChangeSalesOrderDataEsoResponse esoResponse = portType
  246. .changeSalesOrderDataEso(esoRequest);
  247. String result = esoResponse.getResponse();
  248. logger.info("订单变更上传返回" + fsonum + result);
  249. Document document = DocumentHelper.parseText(result);
  250. issucess = saveLog(controller, "sa_orderitems_change", uniqueIDValue, "订单变更", xmlbuffer.toString(),
  251. document);
  252. issucess = saveDataextend(controller, "sa_orderitems_change", uniqueIDValue, document);
  253. } catch (Exception e) {
  254. logger.info("订单上传错误" + fsonum + e.getMessage());
  255. e.printStackTrace();
  256. }
  257. return issucess;
  258. }
  259. /**
  260. * 杂发单上传erp服务
  261. */
  262. public static boolean uploadSaorder_ZF_post(Controller controller, long uniqueIDValue) throws YosException {
  263. boolean issucess = false;
  264. Rows saorderRows = controller.dbConnect.runSqlQuery(
  265. "select t1.*,t2.projectname,t3.address,t3.phonenumber,t3.name,t3.province,t3.city,t3.county,t4.`name` salername,t5.agentnum,t6.erpagentnum,t7.hrcode from sa_order t1 left join sa_project t2 on t1.sa_projectid=t2.sa_projectid and t1.siteid=t2.siteid left join sys_enterprise_contacts t3 on t1.rec_contactsid=t3.contactsid and t1.siteid=t3.siteid left join sys_hr t4 on t1.saler_hrid=t4.hrid and t1.siteid=t4.siteid left join sa_agents t5 on t1.sys_enterpriseid=t5.sys_enterpriseid and t1.siteid=t5.siteid left join sys_dataextend t6 on t6.ownertable='sys_enterprise' and t6.ownerid=t5.sys_enterpriseid and t6.siteid=t5.siteid left join sys_hr t7 on t7.siteid=t1.siteid and t1.changeuserid=t7.userid where t1.checkdate is not null and t1.sa_orderid="
  266. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "'");
  267. Rows saorderdetailRows = controller.dbConnect.runSqlQuery(
  268. "select t1.*,t3.erpitemno,t4.stockno from sa_orderitems t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid left join plm_itemextend t3 on t1.itemid=t3.itemid and t1.siteid=t3.siteid left join st_stock t4 on t1.stockid=t4.stockid and t1.siteid=t4.siteid where t1.sa_orderid="
  269. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "' order by t1.rowno");
  270. if (saorderRows.isEmpty()) {
  271. return issucess;
  272. }
  273. String fsonum = saorderRows.get(0).getString("sonum");
  274. String checkdate = getDate_Str1(saorderRows.get(0).getDate("checkdate"));
  275. String fnotes = saorderRows.get(0).getString("remarks");
  276. String freviewtype = saorderRows.get(0).getString("reviewtype");
  277. StringBuffer xmlbuffer = new StringBuffer();
  278. xmlbuffer.append("<Request>");
  279. xmlbuffer.append("<Access>");
  280. xmlbuffer.append("<Authentication user=\"tiptop\" password=\"\"/>");
  281. xmlbuffer.append("<Connection application=\"ESO\" source=\"192.168.10.115\"/>");
  282. xmlbuffer.append("<Organization name=\"" + SITEID + "\"/>");
  283. xmlbuffer.append("<Locale language=\"zh_cn\"/>");
  284. xmlbuffer.append("</Access>");
  285. xmlbuffer.append("<RequestContent>");
  286. xmlbuffer.append("<Document>");
  287. xmlbuffer.append("<RecordSet id=\"1\">");
  288. xmlbuffer.append("<Master name=\"ina_file\">");
  289. xmlbuffer.append("<Record>");
  290. xmlbuffer.append("<Field name=\"ina00\" value=\"1\"/>");// 单据类型
  291. xmlbuffer.append("<Field name=\"ina01\" value=\"ZWI1\"/>");// 单据编号
  292. xmlbuffer.append("<Field name=\"inaud06\" value=\"" + fsonum + "\"/>");// 单据编号
  293. xmlbuffer.append("<Field name=\"ina03\" value=\"" + checkdate + "\"/>");// 单据日期
  294. xmlbuffer.append("<Field name=\"ina07\" value=\"" + fnotes + "\"/>");// 备注
  295. xmlbuffer.append(
  296. "<Field name=\"ina11\" value=\"" + saorderRows.get(0).getString("hrcode").toLowerCase() + "\"/>");// 申请人
  297. // xmlbuffer.append("<Field name=\"ina04\" value=\"" + "J61000" + "\"/>");//申请部门
  298. xmlbuffer.append("<Field name=\"oeaud10\" value=\"" + freviewtype + "\"/>");// 订单评审类型
  299. xmlbuffer.append("<Detail name=\"inb_file\" node_id=\"1_1\">");
  300. if (!saorderdetailRows.isEmpty()) {
  301. for (Row row : saorderdetailRows) {
  302. String ferpitemno = row.getString("erpitemno");
  303. String warehouse = row.getString("stockno");
  304. String location = row.getString("position");
  305. String lot = row.getString("batchno");
  306. double fqty = row.getDouble("qty");
  307. xmlbuffer.append("<Record>");
  308. xmlbuffer.append("<Field name=\"inb04\" value=\"" + ferpitemno + "\"/>");// 料号(ERP商品编号)
  309. xmlbuffer.append("<Field name=\"inb05\" value=\"" + warehouse + "\"/>");// 仓库
  310. xmlbuffer.append("<Field name=\"inb06\" value=\"" + location + "\"/>");// 库位
  311. xmlbuffer.append("<Field name=\"inb07\" value=\"" + lot + "\"/>");// 批号
  312. xmlbuffer.append("<Field name=\"inb09\" value=\"" + fqty + "\"/>");// 异动数量
  313. xmlbuffer.append("<Field name=\"inb15\" value=\"" + "A070" + "\"/>");// 理由码
  314. xmlbuffer.append("</Record>");
  315. }
  316. }
  317. xmlbuffer.append("</Detail>");
  318. xmlbuffer.append("</Record>");
  319. xmlbuffer.append("</Master>");
  320. xmlbuffer.append("</RecordSet>");
  321. xmlbuffer.append("</Document>");
  322. xmlbuffer.append("</RequestContent>");
  323. xmlbuffer.append("</Request>");
  324. logger.info("杂发单上传请求" + fsonum + xmlbuffer.toString());
  325. try {
  326. TIPTOPServiceGateWay gateWay = new TIPTOPServiceGateWay();
  327. TIPTOPServiceGateWayPortType portType = gateWay.getTIPTOPServiceGateWayPortType();
  328. CreateMiscIssueDataESORequestCreateMiscIssueDataESORequest esoRequest = new CreateMiscIssueDataESORequestCreateMiscIssueDataESORequest();
  329. esoRequest.setRequest(xmlbuffer.toString());
  330. CreateMiscIssueDataESOResponseCreateMiscIssueDataESOResponse esoResponse = portType
  331. .createMiscIssueDataESO(esoRequest);
  332. String result = esoResponse.getResponse();
  333. logger.info("杂发单上传请求" + fsonum + result);
  334. Document document = DocumentHelper.parseText(result);
  335. issucess = saveLog(controller, "sa_order", uniqueIDValue, "样品订单", xmlbuffer.toString(), document);
  336. issucess = saveDataextend(controller, "sa_order", uniqueIDValue, document);
  337. } catch (Exception e) {
  338. logger.info("订单上传错误" + fsonum + e.getMessage());
  339. e.printStackTrace();
  340. }
  341. return issucess;
  342. }
  343. /**
  344. * 借出单上传erp服务
  345. */
  346. public static boolean uploadBorrow_post(Controller controller, long uniqueIDValue) throws YosException {
  347. boolean issucess = false;
  348. Rows saorderRows = controller.dbConnect.runSqlQuery(
  349. "select t1.*,t2.projectname,t3.address,t3.phonenumber,t3.name,t3.province,t3.city,t3.county,t4.`name` salername,t4.hrcode,t5.agentnum,t6.erpagentnum,t8.erpagentnum payentcode,t9.erpagentnum recentcode from sa_order t1 left join sa_project t2 on t1.sa_projectid=t2.sa_projectid and t1.siteid=t2.siteid left join sys_enterprise_contacts t3 on t1.rec_contactsid=t3.contactsid and t1.siteid=t3.siteid left join sys_hr t4 on t1.saler_hrid=t4.hrid and t1.siteid=t4.siteid left join sa_agents t5 on t1.sys_enterpriseid=t5.sys_enterpriseid and t1.siteid=t5.siteid left join sys_dataextend t6 on t6.ownertable='sys_enterprise' and t6.ownerid=t5.sys_enterpriseid and t6.siteid=t5.siteid left join sys_enterprise t7 on t7.sys_enterpriseid=t1.pay_enterpriseid and t7.siteid=t1.siteid left join sys_dataextend t8 on t8.ownertable='sys_enterprise' and t8.ownerid=t7.sys_enterpriseid and t8.siteid=t7.siteid left join sys_dataextend t9 on t9.ownertable='sys_enterprise' and t9.ownerid=t3.sys_enterpriseid and t9.siteid=t3.siteid where t1.checkdate is not null and t1.sa_orderid="
  350. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "'");
  351. Rows saorderdetailRows = controller.dbConnect.runSqlQuery(
  352. "select t1.*,t3.erpitemno from sa_orderitems t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid left join plm_itemextend t3 on t1.itemid=t3.itemid and t1.siteid=t3.siteid where t1.sa_orderid="
  353. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "' order by t1.rowno");
  354. if (saorderRows.isEmpty()) {
  355. return issucess;
  356. }
  357. Row saorder = saorderRows.get(0);
  358. String fsonum = saorder.getString("sonum");
  359. String fsaler = saorder.getString("salername");
  360. String hrcode = saorder.getString("hrcode");
  361. String checkdate = getDate_Str1(saorder.getDate("checkdate"));
  362. String fagentnum = saorder.getString("agentnum");
  363. String fcontact = saorder.getString("name");
  364. String fphonenumber = saorder.getString("phonenumber");
  365. String faddress = saorder.getString("faddress");
  366. String fnotes = saorder.getString("remarks");
  367. String fprojectname = "";
  368. String freviewtype = saorderRows.get(0).getString("reviewtype");
  369. String fpayagentnum = saorderRows.get(0).getString("payentcode");
  370. String frecagentnum = saorderRows.get(0).getString("recentcode");
  371. String ftype = saorder.getString("type");
  372. // String ferptype = "ZSO1";
  373. String ferptype = "ZSF1";
  374. if (!StringUtils.isBlank(saorderRows.get(0).getString("erpagentnum"))) {
  375. fagentnum = saorderRows.get(0).getString("erpagentnum");
  376. }
  377. StringBuffer xmlbuffer = new StringBuffer();
  378. xmlbuffer.append("<Request>");
  379. xmlbuffer.append("<Access>");
  380. xmlbuffer.append("<Authentication user=\"tiptop\" password=\"\"/>");
  381. xmlbuffer.append("<Connection application=\"ESO\" source=\"192.168.10.115\"/>");
  382. xmlbuffer.append("<Organization name=\"" + SITEID + "\"/>");
  383. xmlbuffer.append("<Locale language=\"zh_cn\"/>");
  384. xmlbuffer.append("</Access>");
  385. xmlbuffer.append("<RequestContent>");
  386. xmlbuffer.append("<Document>");
  387. xmlbuffer.append("<RecordSet id=\"1\">");
  388. xmlbuffer.append("<Master name=\"oea_file\">");
  389. xmlbuffer.append("<Record>");
  390. xmlbuffer.append("<Field name=\"oea00\" value=\"" + 8 + "\"/>");
  391. xmlbuffer.append("<Field name=\"oea01\" value=\"" + ferptype + "\"/>");// 单别
  392. xmlbuffer.append("<Field name=\"oea02\" value=\"" + checkdate + "\"/>");// 单据日期
  393. xmlbuffer.append("<Field name=\"oea03\" value=\"" + fpayagentnum + "\"/>");// 付款客户编号
  394. xmlbuffer.append("<Field name=\"oea04\" value=\"" + frecagentnum + "\"/>");// 收货客户编号
  395. xmlbuffer.append("<Field name=\"oea10\" value=\"" + fsonum + "\"/>");// 借出单号
  396. xmlbuffer.append("<Field name=\"oea14\" value=\"" + hrcode.toLowerCase() + "\"/>");// 业务员
  397. xmlbuffer.append("<Field name=\"oap041\" value=\"" + fcontact + ";" + fphonenumber + ";" + faddress + "\"/>");// 地址
  398. xmlbuffer.append("<Field name=\"oap042\" value=\"" + saorder.getString("province") + "->"
  399. + saorder.getString("city") + "->" + saorder.getString("county") + "\"/>");// 省市县
  400. xmlbuffer.append("<Field name=\"oap044\" value=\"" + fprojectname + "\"/>");// 项目
  401. xmlbuffer.append("<Field name=\"oeaud01\" value=\"" + fnotes + "\"/>");// 备注
  402. xmlbuffer.append("<Field name=\"oeaud10\" value=\"" + freviewtype + "\"/>");// 订单评审类型
  403. xmlbuffer.append("<Detail name=\"oeb_file\" node_id=\"1_1\">");
  404. if (!saorderdetailRows.isEmpty()) {
  405. for (Row row : saorderdetailRows) {
  406. String ferpitemno = row.getString("erpitemno");
  407. String fitemno = row.getString("itemno");
  408. double fqty = row.getDouble("qty");
  409. String fplandate = getDate_Str1(row.getDate("deliverydate"));
  410. String fdetailnotes = row.getString("remarks");
  411. double frateprice = row.getDouble("price");
  412. double frateamount = row.getDouble("amount");
  413. long frownum = row.getLong("rowno");
  414. xmlbuffer.append("<Record>");
  415. xmlbuffer.append("<Field name=\"oeb04\" value=\"" + ferpitemno + "\"/>");// 料号(ERP商品编号)
  416. xmlbuffer.append("<Field name=\"oeb11\" value=\"" + fitemno + "\"/>");// 客户产品编码(DRP商品编号)
  417. xmlbuffer.append("<Field name=\"oeb12\" value=\"" + fqty + "\"/>");// 数量
  418. xmlbuffer.append("<Field name=\"oeb15\" value=\"" + fplandate + "\"/>");// 交货日期
  419. xmlbuffer.append("<Field name=\"oeb13\" value=\"" + frateprice + "\"/>");// 单价
  420. xmlbuffer.append("<Field name=\"oeb14t\" value=\"" + frateamount + "\"/>");// 金额
  421. xmlbuffer.append("<Field name=\"oebud04\" value=\"" + fsonum + "\"/>");// 借出单号
  422. xmlbuffer.append("<Field name=\"oebud05\" value=\"" + frownum + "\"/>");// 行号
  423. String fbackdate = getDate_Str1(row.getDate("toolbackdate"));
  424. xmlbuffer.append("<Field name=\"oeb30\" value=\"" + fbackdate + "\"/>");// 预计归还日期
  425. xmlbuffer.append("</Record>");
  426. }
  427. }
  428. xmlbuffer.append("</Detail>");
  429. xmlbuffer.append("</Record>");
  430. xmlbuffer.append("</Master>");
  431. xmlbuffer.append("</RecordSet>");
  432. xmlbuffer.append("</Document>");
  433. xmlbuffer.append("</RequestContent>");
  434. xmlbuffer.append("</Request>");
  435. logger.info("借出单上传请求" + fsonum + xmlbuffer.toString());
  436. try {
  437. TIPTOPServiceGateWay gateWay = new TIPTOPServiceGateWay();
  438. TIPTOPServiceGateWayPortType portType = gateWay.getTIPTOPServiceGateWayPortType();
  439. CreateSalesOrderDataESORequestCreateSalesOrderDataESORequest esoRequest = new CreateSalesOrderDataESORequestCreateSalesOrderDataESORequest();
  440. esoRequest.setRequest(xmlbuffer.toString());
  441. CreateSalesOrderDataESOResponseCreateSalesOrderDataESOResponse esoResponse = portType
  442. .createSalesOrderDataESO(esoRequest);
  443. String result = esoResponse.getResponse();
  444. logger.info("借出单上传请求" + fsonum + result);
  445. Document document = DocumentHelper.parseText(result);
  446. issucess = saveLog(controller, "sa_order", uniqueIDValue, "工具借用", xmlbuffer.toString(), document);
  447. issucess = saveDataextend(controller, "sa_order", uniqueIDValue, document);
  448. } catch (Exception e) {
  449. e.printStackTrace();
  450. logger.info("借出单上传错误" + fsonum + e.getMessage());
  451. }
  452. return issucess;
  453. }
  454. /**
  455. * 借货转销售上传erp服务
  456. */
  457. public static boolean uploadBorrowToSale_post(Controller controller, long uniqueIDValue) throws YosException {
  458. boolean issucess = false;
  459. Rows aftersalesmagRows = controller.dbConnect.runSqlQuery(
  460. "select t1.*,t2.sonum from sa_aftersalesmag t1 left join sa_order t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid where t1.sa_aftersalesmagid="
  461. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "'");
  462. Rows aftersalesmagdetailRows = controller.dbConnect.runSqlQuery(
  463. "select t1.*,t2.rowno from sa_aftersalesmag_items t1 left join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.sa_aftersalesmagid="
  464. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "' order by t2.rowno");
  465. if (aftersalesmagRows.isEmpty()) {
  466. return issucess;
  467. }
  468. if (StringUtils.isBlank(aftersalesmagRows.get(0).getString("sonum"))) {
  469. return issucess;
  470. }
  471. Row taftersalesmag = aftersalesmagRows.get(0);
  472. Rows erpupdatelogRows = controller.dbConnect
  473. .runSqlQuery("select * from sys_erpupdatelog where ownertable='sa_order' and ownerid="
  474. + aftersalesmagRows.get(0).getLong("sa_orderid") + "order by createdate desc");
  475. if (erpupdatelogRows.isEmpty()) {
  476. return issucess;
  477. }
  478. String ferpbillno = erpupdatelogRows.get(0).getString("erpbillno");
  479. String fbillnum = taftersalesmag.getString("billno");
  480. String checkdate = getDate_Str1(taftersalesmag.getDate("checkdate"));
  481. StringBuffer xmlbuffer = new StringBuffer();
  482. xmlbuffer.append("<Request>");
  483. xmlbuffer.append("<Access>");
  484. xmlbuffer.append("<Authentication user=\"tiptop\" password=\"\"/>");
  485. xmlbuffer.append("<Connection application=\"ESO\" source=\"192.168.10.115\"/>");
  486. xmlbuffer.append("<Organization name=\"" + SITEID + "\"/>");
  487. xmlbuffer.append("<Locale language=\"zh_cn\"/>");
  488. xmlbuffer.append("</Access>");
  489. xmlbuffer.append("<RequestContent>");
  490. xmlbuffer.append("<Document>");
  491. xmlbuffer.append("<RecordSet id=\"1\">");
  492. xmlbuffer.append("<Master name=\"oea_file\">");
  493. xmlbuffer.append("<Record>");
  494. xmlbuffer.append("<Field name=\"oea00\" value=\"" + 9 + "\"/>");
  495. xmlbuffer.append("<Field name=\"oea01\" value=\"" + "" + "\"/>");// 单别
  496. xmlbuffer.append("<Field name=\"oea02\" value=\"" + checkdate + "\"/>");// 单据日期
  497. xmlbuffer.append("<Field name=\"oea10\" value=\"" + fbillnum + "\"/>");// 单号
  498. xmlbuffer.append("<Field name=\"oea12\" value=\"" + ferpbillno + "\"/>");// 原借出单号
  499. xmlbuffer.append("<Detail name=\"oeb_file\" node_id=\"1_1\">");
  500. if (aftersalesmagdetailRows.isEmpty()) {
  501. for (Row row : aftersalesmagdetailRows) {
  502. double fqty = row.getDouble("qty");
  503. double frateprice = row.getDouble("price");
  504. double frateamount = row.getDouble("amount");
  505. int fsorownum = row.getInteger("rowno");
  506. xmlbuffer.append("<Record>");
  507. xmlbuffer.append("<Field name=\"oeb71\" value=\"" + fsorownum + "\"/>");// 原借出单行号
  508. xmlbuffer.append("<Field name=\"oeb12\" value=\"" + fqty + "\"/>");// 数量
  509. xmlbuffer.append("<Field name=\"oeb13\" value=\"" + frateprice + "\"/>");// 单价
  510. xmlbuffer.append("<Field name=\"oeb14t\" value=\"" + frateamount + "\"/>");// 金额
  511. xmlbuffer.append("</Record>");
  512. }
  513. }
  514. xmlbuffer.append("</Detail>");
  515. xmlbuffer.append("</Record>");
  516. xmlbuffer.append("</Master>");
  517. xmlbuffer.append("</RecordSet>");
  518. xmlbuffer.append("</Document>");
  519. xmlbuffer.append("</RequestContent>");
  520. xmlbuffer.append("</Request>");
  521. logger.info("借货转销售上传请求" + fbillnum + xmlbuffer.toString());
  522. try {
  523. TIPTOPServiceGateWay gateWay = new TIPTOPServiceGateWay();
  524. TIPTOPServiceGateWayPortType portType = gateWay.getTIPTOPServiceGateWayPortType();
  525. CreateSalesOrderDataESORequestCreateSalesOrderDataESORequest esoRequest = new CreateSalesOrderDataESORequestCreateSalesOrderDataESORequest();
  526. esoRequest.setRequest(xmlbuffer.toString());
  527. CreateSalesOrderDataESOResponseCreateSalesOrderDataESOResponse esoResponse = portType
  528. .createSalesOrderDataESO(esoRequest);
  529. String result = esoResponse.getResponse();
  530. logger.info("借货转销售上传请求" + fbillnum + result);
  531. Document document = DocumentHelper.parseText(result);
  532. issucess = saveLog(controller, "sa_aftersalesmag", uniqueIDValue, "返退单", xmlbuffer.toString(), document);
  533. issucess = saveDataextend(controller, "sa_aftersalesmag", uniqueIDValue, document);
  534. } catch (Exception e) {
  535. logger.info("借货转销售错误" + fbillnum + e.getMessage());
  536. e.printStackTrace();
  537. }
  538. return issucess;
  539. }
  540. /**
  541. * 借货退回上传erp服务
  542. */
  543. public static boolean uploadBorrowToReturn_post(Controller controller, long uniqueIDValue) throws YosException {
  544. boolean issucess = false;
  545. Rows aftersalesmagRows = controller.dbConnect.runSqlQuery(
  546. "select t1.*,t2.sonum from sa_aftersalesmag t1 left join sa_order t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid where t1.sa_aftersalesmagid="
  547. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "'");
  548. Rows aftersalesmagdetailRows = controller.dbConnect.runSqlQuery(
  549. "select t1.*,t2.rowno,t2.itemno from sa_aftersalesmag_items t1 left join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.sa_aftersalesmagid="
  550. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "' order by t2.rowno");
  551. if (aftersalesmagRows.isEmpty()) {
  552. return issucess;
  553. }
  554. if (StringUtils.isBlank(aftersalesmagRows.get(0).getString("sonum"))) {
  555. return issucess;
  556. }
  557. Row taftersalesmag = aftersalesmagRows.get(0);
  558. Rows erpupdatelogRows = controller.dbConnect
  559. .runSqlQuery("select * from sys_erpupdatelog where ownertable='sa_order' and ownerid="
  560. + aftersalesmagRows.get(0).getLong("sa_orderid") + "order by createdate desc");
  561. if (erpupdatelogRows.isEmpty()) {
  562. return issucess;
  563. }
  564. String ferpbillno = erpupdatelogRows.get(0).getString("erpbillno");
  565. String fbillnum = taftersalesmag.getString("billno");
  566. String checkdate = getDate_Str1(taftersalesmag.getDate("checkdate"));
  567. StringBuffer xmlbuffer = new StringBuffer();
  568. xmlbuffer.append("<Request>");
  569. xmlbuffer.append("<Access>");
  570. xmlbuffer.append("<Authentication user=\"tiptop\" password=\"\"/>");
  571. xmlbuffer.append("<Connection application=\"ESO\" source=\"192.168.10.115\"/>");
  572. xmlbuffer.append("<Organization name=\"" + SITEID + "\"/>");
  573. xmlbuffer.append("<Locale language=\"zh_cn\"/>");
  574. xmlbuffer.append("</Access>");
  575. xmlbuffer.append("<RequestContent>");
  576. xmlbuffer.append("<Document>");
  577. xmlbuffer.append("<RecordSet id=\"1\">");
  578. xmlbuffer.append("<Master name=\"oha_file\">");
  579. xmlbuffer.append("<Record>");
  580. xmlbuffer.append("<Field name=\"oha01\" value=\"" + "" + "\"/>");// 单别
  581. xmlbuffer.append("<Field name=\"oha02\" value=\"" + checkdate + "\"/>");// 单据日期
  582. xmlbuffer.append("<Field name=\"oha05\" value=\"" + "5" + "\"/>");// 销退类型
  583. xmlbuffer.append("<Field name=\"oha09\" value=\"" + "6" + "\"/>");// 销退方式
  584. xmlbuffer.append("<Field name=\"oha16\" value=\"" + ferpbillno + "\"/>");// 借出单号
  585. xmlbuffer.append("<Detail name=\"ohb_file\" node_id=\"1_1\">");
  586. if (aftersalesmagdetailRows.isEmpty()) {
  587. for (Row row : aftersalesmagdetailRows) {
  588. String fitemno = row.getString("itemno");
  589. double fqty = row.getDouble("qty");
  590. int fsorownum = row.getInteger("rowno");
  591. xmlbuffer.append("<Record>");
  592. xmlbuffer.append("<Field name=\"ohb04\" value=\"" + fitemno + "\"/>");// 料号
  593. xmlbuffer.append("<Field name=\"ohb09\" value=\"" + "W11" + "\"/>");// 仓库
  594. xmlbuffer.append("<Field name=\"ohb091\" value=\"" + "" + "\"/>");// 库位
  595. xmlbuffer.append("<Field name=\"ohb092\" value=\"" + "" + "\"/>");// 批号
  596. xmlbuffer.append("<Field name=\"ohb12\" value=\"" + fqty + "\"/>");// 数量
  597. xmlbuffer.append("<Field name=\"ohb31\" value=\"" + ferpbillno + "\"/>");// 借出单号
  598. xmlbuffer.append("<Field name=\"ohb32\" value=\"" + fsorownum + "\"/>");// 借出单号项次
  599. xmlbuffer.append("<Field name=\"ohb50\" value=\"" + "A210" + "\"/>");// 理由编号号
  600. xmlbuffer.append("</Record>");
  601. }
  602. }
  603. xmlbuffer.append("</Detail>");
  604. xmlbuffer.append("</Record>");
  605. xmlbuffer.append("</Master>");
  606. xmlbuffer.append("</RecordSet>");
  607. xmlbuffer.append("</Document>");
  608. xmlbuffer.append("</RequestContent>");
  609. xmlbuffer.append("</Request>");
  610. logger.info("借货退回上传请求" + fbillnum + xmlbuffer.toString());
  611. try {
  612. TIPTOPServiceGateWay gateWay = new TIPTOPServiceGateWay();
  613. TIPTOPServiceGateWayPortType portType = gateWay.getTIPTOPServiceGateWayPortType();
  614. CreateSalesReturnEsoRequestCreateSalesReturnEsoRequest esoRequest = new CreateSalesReturnEsoRequestCreateSalesReturnEsoRequest();
  615. esoRequest.setRequest(xmlbuffer.toString());
  616. CreateSalesReturnEsoResponseCreateSalesReturnEsoResponse esoResponse = portType
  617. .createSalesReturnEso(esoRequest);
  618. String result = esoResponse.getResponse();
  619. logger.info("借货退回上传请求" + fbillnum + result);
  620. Document document = DocumentHelper.parseText(result);
  621. issucess = saveLog(controller, "sa_aftersalesmag", uniqueIDValue, "借货退回", xmlbuffer.toString(), document);
  622. issucess = saveDataextend(controller, "sa_aftersalesmag", uniqueIDValue, document);
  623. } catch (Exception e) {
  624. logger.info("借货退回上传错误" + fbillnum + e.getMessage());
  625. e.printStackTrace();
  626. }
  627. return issucess;
  628. }
  629. /**
  630. * 发货单上传erp服务
  631. */
  632. public static boolean uploadSainvoice_post(Controller controller, long uniqueIDValue) throws YosException {
  633. boolean issucess = false;
  634. Rows dispatchRows = controller.dbConnect.runSqlQuery(
  635. "select t1.*,t2.sonum,t3.address,t3.province,t3.city,t3.county from sa_dispatch t1 left join sa_order t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid left join sys_enterprise_contacts t3 on t1.rec_contactsid=t3.contactsid and t1.siteid=t3.siteid where t1.sa_dispatchid="
  636. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "'");
  637. Rows dispatchdetailRows = controller.dbConnect.runSqlQuery(
  638. "select t1.*,t3.erpitemno,t2.rowno sorowno,t2.itemname from sa_dispatch_items t1 left join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid left join plm_itemextend t3 on t1.itemid=t3.itemid and t1.siteid=t3.siteid where t1.sa_dispatchid="
  639. + uniqueIDValue + " and t1.siteid='" + controller.siteid + "' order by t1.rowno");
  640. if (dispatchRows.isEmpty()) {
  641. return issucess;
  642. }
  643. Row sainvoice = dispatchRows.get(0);
  644. String fsonum = sainvoice.getString("sonum");
  645. String finvonum = sainvoice.getString("billno");
  646. String recheckdate = getDate_Str1(sainvoice.getDate("recheckdate"));
  647. String fdate = getDate_Str1(sainvoice.getDate("billdate"));
  648. String faddress = sainvoice.getString("address");
  649. String fnotes = sainvoice.getString("remarks");
  650. String ftype = "ZSA1";
  651. StringBuffer xmlbuffer = new StringBuffer();
  652. xmlbuffer.append("<Request>");
  653. xmlbuffer.append("<Access>");
  654. xmlbuffer.append("<Authentication user=\"tiptop\" password=\"\"/>");
  655. xmlbuffer.append("<Connection application=\"ESO\" source=\"192.168.10.115\"/>");
  656. xmlbuffer.append("<Organization name=\"" + SITEID + "\"/>");
  657. xmlbuffer.append("<Locale language=\"zh_cn\"/>");
  658. xmlbuffer.append("</Access>");
  659. xmlbuffer.append("<RequestContent>");
  660. xmlbuffer.append("<Document>");
  661. xmlbuffer.append("<RecordSet id=\"1\">");
  662. xmlbuffer.append("<Master name=\"oga_file\">");
  663. xmlbuffer.append("<Record>");
  664. xmlbuffer.append("<Field name=\"oga01\" value=\"" + ftype + "\"/>");
  665. xmlbuffer.append("<Field name=\"oga02\" value=\"" + recheckdate + "\"/>");
  666. xmlbuffer.append("<Field name=\"oga16\" value=\"" + fsonum + "\"/>");
  667. xmlbuffer.append("<Field name=\"oap041\" value=\"" + faddress + "\"/>");
  668. xmlbuffer.append("<Field name=\"oap042\" value=\"" + sainvoice.getString("province") + "->"
  669. + sainvoice.getString("city") + "->" + sainvoice.getString("county") + "\"/>");
  670. xmlbuffer.append("<Field name=\"ogaud01\" value=\"" + fnotes + "\"/>");
  671. xmlbuffer.append("<Field name=\"ogaud02\" value=\"" + finvonum + "\"/>");
  672. xmlbuffer.append("<Detail name=\"ogb_file\" node_id=\"1_1\">");
  673. if (!dispatchdetailRows.isEmpty()) {
  674. for (Row row : dispatchdetailRows) {
  675. String ferpitemno = row.getString("erpitemno");
  676. double fqty = row.getDouble("qty");
  677. // String fplandate = getDate_Str11(detailpao.getDate("fplandate"));
  678. int frownum = row.getInteger("rowno");
  679. int fsorownum = row.getInteger("sorowno");
  680. String fitemname = row.getString("itemname");
  681. xmlbuffer.append("<Record>");
  682. xmlbuffer.append("<Field name=\"ogb03\" value=\"" + frownum + "\"/>");
  683. xmlbuffer.append("<Field name=\"ogb04\" value=\"" + ferpitemno + "\"/>");
  684. xmlbuffer.append("<Field name=\"ogb12\" value=\"" + fqty + "\"/>");
  685. xmlbuffer.append("<Field name=\"ogb31\" value=\"" + fsonum + "\"/>");
  686. xmlbuffer.append("<Field name=\"ogb32\" value=\"" + fsorownum + "\"/>");
  687. xmlbuffer.append("<Field name=\"ogb1003\" value=\"" + fdate + "\"/>");
  688. xmlbuffer.append("<Field name=\"ogbud01\" value=\"" + fitemname + "\"/>");
  689. xmlbuffer.append("</Record>");
  690. }
  691. }
  692. xmlbuffer.append("</Detail>");
  693. xmlbuffer.append("</Record>");
  694. xmlbuffer.append("</Master>");
  695. xmlbuffer.append("</RecordSet>");
  696. xmlbuffer.append("</Document>");
  697. xmlbuffer.append("</RequestContent>");
  698. xmlbuffer.append("</Request>");
  699. logger.info("发货单上传" + finvonum + xmlbuffer.toString());
  700. try {
  701. TIPTOPServiceGateWay gateWay = new TIPTOPServiceGateWay();
  702. TIPTOPServiceGateWayPortType portType = gateWay.getTIPTOPServiceGateWayPortType();
  703. CreateShippingNoticeESORequestCreateShippingNoticeESORequest esoRequest = new CreateShippingNoticeESORequestCreateShippingNoticeESORequest();
  704. esoRequest.setRequest(xmlbuffer.toString());
  705. CreateShippingNoticeESOResponseCreateShippingNoticeESOResponse esoResponse = portType
  706. .createShippingNoticeESO(esoRequest);
  707. String result = esoResponse.getResponse();
  708. logger.info("发货单返回" + finvonum + result);
  709. Document document = DocumentHelper.parseText(result);
  710. issucess = saveLog(controller, "sa_dispatch", uniqueIDValue, "发货单", xmlbuffer.toString(), document);
  711. issucess = saveDataextend(controller, "sa_dispatch", uniqueIDValue, document);
  712. } catch (Exception e) {
  713. logger.info("发货单上传错误" + finvonum + e.getMessage());
  714. e.printStackTrace();
  715. }
  716. return issucess;
  717. }
  718. /**
  719. * 上传日志更新
  720. *
  721. * @param controller
  722. * @param ownertable
  723. * @param ownerid
  724. * @param type
  725. * @param request
  726. * @param document
  727. * @return
  728. */
  729. public static boolean saveLog(Controller controller, String ownertable, long ownerid, String type, String request,
  730. Document document) {
  731. boolean issuccess = false;
  732. try {
  733. SQLFactory sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志新增");
  734. sqlFactory.addParameter("sys_erpupdatelogid", controller.createTableID("sys_erpupdatelog"));
  735. sqlFactory.addParameter("siteid", controller.siteid);
  736. sqlFactory.addParameter("userid", controller.userid);
  737. sqlFactory.addParameter("username", controller.username);
  738. sqlFactory.addParameter("ownerid", ownerid);
  739. sqlFactory.addParameter("ownertable", ownertable);
  740. sqlFactory.addParameter("type", type);
  741. sqlFactory.addParameter("request", request);
  742. sqlFactory.addParameter("response", document.asXML());
  743. String status = document.getRootElement().element("Execution").element("Status").attribute("code")
  744. .getText();
  745. if ("0".equals(status)) {
  746. String ferpbillno = document.getRootElement().element("ResponseContent").element("Parameter")
  747. .element("Record").element("Field").attribute("value").getText();
  748. sqlFactory.addParameter("erpbillno", ferpbillno);
  749. sqlFactory.addParameter("errmsg", "");
  750. issuccess = true;
  751. } else {
  752. String ferrmsg = document.getRootElement().element("Execution").element("Status")
  753. .attribute("description").getText();
  754. sqlFactory.addParameter("erpbillno", 0);
  755. sqlFactory.addParameter("errmsg", ferrmsg);
  756. issuccess = false;
  757. }
  758. sqlFactory.addParameter("status", status);
  759. controller.dbConnect.runSqlUpdate(sqlFactory);
  760. } catch (Exception e) {
  761. e.printStackTrace();
  762. }
  763. return issuccess;
  764. }
  765. /**
  766. * 上传日志更新
  767. *
  768. * @param controller
  769. * @param ownertable
  770. * @param ownerid
  771. * @param type
  772. * @param request
  773. * @param document
  774. * @return
  775. */
  776. public static boolean saveDataextend(Controller controller, String ownertable, long ownerid, Document document) {
  777. boolean issuccess = false;
  778. try {
  779. Rows rows = controller.dbConnect.runSqlQuery(
  780. "select * from sys_dataextend where ownertable='" + ownertable + "' and ownerid=" + ownerid);
  781. SQLFactory sqlFactory;
  782. if (!rows.isEmpty()) {
  783. sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp数据扩展信息更新");
  784. sqlFactory.addParameter("sys_dataextendid", rows.get(0).getLong("sys_dataextendid"));
  785. } else {
  786. sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp数据扩展信息新增");
  787. sqlFactory.addParameter("sys_dataextendid", controller.createTableID("sys_dataextend"));
  788. }
  789. sqlFactory.addParameter("siteid", controller.siteid);
  790. sqlFactory.addParameter("userid", controller.userid);
  791. sqlFactory.addParameter("username", controller.username);
  792. sqlFactory.addParameter("ownerid", ownerid);
  793. sqlFactory.addParameter("ownertable", ownertable);
  794. String status = document.getRootElement().element("Execution").element("Status").attribute("code")
  795. .getText();
  796. logger.info("0".equals(status));
  797. if ("0".equals(status)) {
  798. String ferpbillno = document.getRootElement().element("ResponseContent").element("Parameter")
  799. .element("Record").element("Field").attribute("value").getText();
  800. sqlFactory.addParameter("erpbillno", ferpbillno);
  801. logger.info("上传日志" + sqlFactory.getSQL());
  802. controller.dbConnect.runSqlUpdate(sqlFactory);
  803. issuccess = true;
  804. } else {
  805. issuccess = false;
  806. }
  807. } catch (Exception e) {
  808. e.printStackTrace();
  809. }
  810. return issuccess;
  811. }
  812. public static String getDate_Str1(Date date) {
  813. if (date == null) {
  814. return "";
  815. }
  816. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  817. return format.format(date.getTime());
  818. }
  819. }