package com.yem.wm.utils; import com.alibaba.fastjson.JSONArray; import com.kingdee.bos.openapi.third.OpenApi; import com.kingdee.bos.openapi.third.OpenApiFactory; import com.kingdee.bos.openapi.third.OpenApiInfo; import com.kingdee.bos.openapi.third.ctx.CommonLogin; import com.kingdee.bos.openapi.third.login.EASLoginContext; import com.yem.ensign.common.DateUtils; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.exception.KDBizException; import kd.bos.exception.KDException; import kd.bos.orm.query.QCP; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.DispatchServiceHelper; import kd.bos.servicehelper.QueryServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.message.SOAPHeaderElement; import org.jetbrains.annotations.NotNull; import javax.xml.namespace.QName; import java.math.BigDecimal; import java.rmi.RemoteException; import java.sql.Types; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; public class RequestEAS { public static List> exeSql(String sql) { List> list = null; String cnNumber = "eas850"; list = DispatchServiceHelper.invokeBizService( "isc", "iscb", "ISCDataCopyService", "executeQuerySQL", new Object[]{cnNumber, sql.toString(), null, null, 1}); return list; } /** * @param groupNum 客户分类编码 * @return * @decription 获取该分类下最大的编码 */ public static List> getMaxCustomerNum(String groupNum) { List> list = null; String sql = "SELECT fnumber FROM t_bd_customer where fnumber LIKE '" + groupNum + "%' order by fnumber desc"; String cnNumber = "eas850"; list = DispatchServiceHelper.invokeBizService( "isc", "iscb", "ISCDataCopyService", "executeQuerySQL", new Object[]{cnNumber, sql.toString(), null, null, 1}); return list; } /** * 生成客户 * * @param xml * @return */ public static String generateCustomer(String xml) { { String aa = null; DynamicObject connObj = QueryServiceHelper.queryOne("isc_database_link", "server_ip,server_port,data_center,user,newpwd,http_protocal", new QFilter[]{new QFilter("number", QCP.equals, "eas850")}); if (connObj == null) { throw new KDException("未获取到EAS链接配置,请联系系统管理员"); } else { String server_ip = connObj.getString("server_ip"); String server_port = connObj.getString("server_port"); String http_protocal = connObj.getString("http_protocal"); String data_center = connObj.getString("data_center"); String user = connObj.getString("user"); String newpwd = connObj.getString("newpwd"); try { Service s = new Service(); Call call = (Call) s.createCall(); WSContext rs = login(server_ip, server_port, http_protocal, data_center, user, newpwd, call); //调用业务接口 call.setOperationName("importCustomerData"); //暂存 //call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSSCMWebServiceFacade?wsdl");//改 //审核 call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSImportCustomerFacade?wsdl");//改 call.setReturnQName(new QName("", "importCustomerData")); call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //设置登录返回的session在soap头 "http://login.webservice.bos.kingdee.com"是固定的 SOAPHeaderElement header = new SOAPHeaderElement(http_protocal + "://login.webservice.bos.kingdee.com", "SessionId", rs.getSessionId()); call.addHeader(header); aa = (String) call.invoke(new Object[]{xml}); call.setOperationName("logout"); call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/EASLogin?wsdl");//ip改 // call.setReturnType(new QName("urn:client","WSContext"));//改 // call.setReturnClass(WSContext.class);//改 call.setReturnQName(new QName("", "logoutReturn"));//改 //超时 call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //登出接口参数 call.invoke(new Object[]{user, "eas", data_center, "l2"});//根据实际调整 System.out.println("登出成功"); //清理 call.clearOperation(); } catch (Exception e) { // TODO Auto-generated catch block throw new KDException("接口调用失败,异常信息如下:" + e.getMessage()); } } return aa; } } /** * 分配客户 * * @param xml * @return */ public static String assignCustomer(String xml) { { String aa = null; DynamicObject connObj = QueryServiceHelper.queryOne("isc_database_link", "server_ip,server_port,data_center,user,newpwd,http_protocal", new QFilter[]{new QFilter("number", QCP.equals, "eas850")}); if (connObj == null) { throw new KDException("未获取到EAS链接配置,请联系系统管理员"); } else { String server_ip = connObj.getString("server_ip"); String server_port = connObj.getString("server_port"); String http_protocal = connObj.getString("http_protocal"); String data_center = connObj.getString("data_center"); String user = connObj.getString("user"); String newpwd = connObj.getString("newpwd"); try { Service s = new Service(); Call call = (Call) s.createCall(); WSContext rs = login(server_ip, server_port, http_protocal, data_center, user, newpwd, call); //调用业务接口 call.setOperationName("assignCustomer"); //暂存 //call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSSCMWebServiceFacade?wsdl");//改 //审核 call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSAssignCustomerFacade?wsdl");//改 call.setReturnQName(new QName("", "assignCustomer")); call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //设置登录返回的session在soap头 "http://login.webservice.bos.kingdee.com"是固定的 SOAPHeaderElement header = new SOAPHeaderElement(http_protocal + "://login.webservice.bos.kingdee.com", "SessionId", rs.getSessionId()); call.addHeader(header); aa = (String) call.invoke(new Object[]{xml}); call.setOperationName("logout"); call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/EASLogin?wsdl");//ip改 // call.setReturnType(new QName("urn:client","WSContext"));//改 // call.setReturnClass(WSContext.class);//改 call.setReturnQName(new QName("", "logoutReturn"));//改 //超时 call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //登出接口参数 call.invoke(new Object[]{user, "eas", data_center, "l2"});//根据实际调整 System.out.println("登出成功"); //清理 call.clearOperation(); } catch (Exception e) { // TODO Auto-generated catch block throw new KDException("接口调用失败,异常信息如下:" + e.getMessage()); } } return aa; } } public static String InventoryListServiceFacadeGetData(String json) { DynamicObject connObj = QueryServiceHelper.queryOne("isc_database_link", "server_ip,server_port,data_center,user,newpwd,http_protocal", new QFilter[]{new QFilter("number", QCP.equals, "eas850")}); if (connObj == null) { throw new KDException("未获取到EAS链接配置,请联系系统管理员"); } String server_ip = connObj.getString("server_ip"); int server_port = connObj.getInt("server_port"); String http_protocal = connObj.getString("http_protocal"); String data_center = connObj.getString("data_center"); String user = connObj.getString("user"); String newpwd = connObj.getString("newpwd"); EASLoginContext loginCtx = new EASLoginContext.Builder(server_ip, server_port, new CommonLogin.Builder(user, newpwd, data_center, "l2").appid("cosmic") .build()).https(false)//是否https .build(); OpenApiInfo info = new OpenApiInfo(); info.setApi("InventoryListServiceFacade-getData"); JSONArray data = new JSONArray(); data.add(json.toString()); info.setData(data.toString()); OpenApi openApi = OpenApiFactory.getService(loginCtx); String result = null; try { result = openApi.invoke(info); } catch (Exception e) { throw new KDBizException("查询及时库存异常!" + e.getMessage()); } System.out.println("----------result:" + result); return result; } /** * 获取EAS调拨成本价 * * @param materialNum 物料编码 * @param inNum 调入组织编码 * @param outNum 调出组织编码 * @param date 业务日期 * @return * @deprecated EAS中审核、启用的价格政策,过滤条件为分录生效失效时间、物料编码、出入组织 */ public static List> getTransferCostPrice(String materialNum, String inNum, String outNum, Date date) { List> list = null; String cnNumber = "eas850"; java.sql.Date date1 = new java.sql.Date(date.getTime()); // String sql = "SELECT FID, FNUMBER, FNAME, FCREATETIME FROM T_ISC_DEMO_BASEDATA_1@ISCB WHERE FNUMBER = ? AND FNAME = ?"; String sql = "select h.fnumber,e.FPRICE,o.FNUMBER inorg, o1.fnumber outorg,m.FNUMBER mnumber,h.FPRICECOMPOSITIONPRIORITY " + "from T_SCM_PricePolicyEntry e \n" + "LEFT OUTER JOIN T_BD_MATERIAL m on e.FMATERIALID = m.fid \n" + "LEFT OUTER JOIN T_BD_CUSTOMER c ON E.FCUSTOMERID = C.FID \n" + "left join t_org_baseunit o on c.FINTERNALCOMPANYID = o.fid \n" + "LEFT JOIN T_SCM_PricePolicy h ON E.FPARENTID = H.FID\n" + "left join t_org_baseunit o1 on h.FSALEORGUNITID =o1.fid\n" + "where h.FBLOCKEDSTATUS = 1 and h.FCHECKEDSTATUS = 2 \n" + "and m.FNUMBER = ? and o.fnumber = ? and o1.fnumber = ?\n" + "and e.FEFFECTIVEDATE <=? and e.FEXPIREDATE>=? \n" + "order by h.FPRICECOMPOSITIONPRIORITY,e.FEFFECTIVEDATE"; List values = Arrays.asList(materialNum, inNum, outNum, date1, date1); List types = Arrays.asList(Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.DATE, Types.DATE); try { list = DispatchServiceHelper.invokeBizService( "isc", "iscb", "ISCDataCopyService", "executeQuerySQL", new Object[]{cnNumber, sql, values, types, 100}); } catch (Exception e) { throw new KDBizException("查询调拨成本单价异常!" + e.getMessage()); } return list; } /** * @param cusid * @param isc_value_conver_ruleNum 值转换规则编码(客户id转换:Customer(eas-cq)_NE23,组织id转换99070662-01) * @return */ public static Long getCustomerByEASID(String cusid, String isc_value_conver_ruleNum) { //cloudId: 云编码 //appId: 应用编码 //serviceInterfaceName: 服务接口名 Map o = DispatchServiceHelper.invokeBizService("isc", "iscb", "ISCDataCopyService", "findMappingValue", new Object[]{isc_value_conver_ruleNum, "FQgAAAeZryO/DAQO", 0}); Boolean success = (Boolean) o.get("success"); if (success) { return (Long) o.get("data"); } return null; } /** * 通过EASID查询组织编码 * * @param orgEASId * @return */ public static String getOrgNum(String orgEASId) { String orgNum = null; String sql = "select fnumber from T_ORG_BaseUnit where fid =?"; List values = Arrays.asList(orgEASId); List types = Arrays.asList(Types.VARCHAR); String cnNumber = "eas850"; try { List> list = DispatchServiceHelper.invokeBizService( "isc", "iscb", "ISCDataCopyService", "executeQuerySQL", new Object[]{cnNumber, sql, values, types, 100}); for (Map map : list) { orgNum = (String) map.get("fnumber"); } } catch (Exception e) { throw new KDBizException("查询组织异常!" + e.getMessage()); } return orgNum; } public static String getService(String json, String type) { String aa = null; DynamicObject connObj = QueryServiceHelper.queryOne("isc_database_link", "server_ip,server_port,data_center,user,newpwd,http_protocal", new QFilter[]{new QFilter("number", QCP.equals, "eas850")}); if (connObj == null) { throw new KDException("未获取到EAS链接配置,请联系系统管理员"); } else { String server_ip = connObj.getString("server_ip"); String server_port = connObj.getString("server_port"); String http_protocal = connObj.getString("http_protocal"); String data_center = connObj.getString("data_center"); String user = connObj.getString("user"); String newpwd = connObj.getString("newpwd"); try { Service s = new Service(); Call call = (Call) s.createCall(); WSContext rs = login(server_ip, server_port, http_protocal, data_center, user, newpwd, call); //调用业务接口 call.setOperationName("importBill"); //暂存 // call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSSCMWebServiceFacade?wsdl");//改 //审核 call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSSCMWebServiceExtFacade?wsdl");//改 call.setReturnQName(new QName("", "importBill")); call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //设置登录返回的session在soap头 "http://login.webservice.bos.kingdee.com"是固定的 SOAPHeaderElement header = new SOAPHeaderElement(http_protocal + "://login.webservice.bos.kingdee.com", "SessionId", rs.getSessionId()); call.addHeader(header); aa = (String) call.invoke(new Object[]{type, json, 1}); call.setOperationName("logout"); call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/EASLogin?wsdl");//ip改 // call.setReturnType(new QName("urn:client","WSContext"));//改 // call.setReturnClass(WSContext.class);//改 call.setReturnQName(new QName("", "logoutReturn"));//改 //超时 call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //登出接口参数 call.invoke(new Object[]{user, "eas", data_center, "l2"});//根据实际调整 System.out.println("登出成功"); //清理 call.clearOperation(); } catch (Exception e) { // TODO Auto-generated catch block throw new KDException("接口调用失败,异常信息如下:" + e.getMessage()); } } return aa; } public static String getSaveService(String json, String type) { String aa = null; DynamicObject connObj = QueryServiceHelper.queryOne("isc_database_link", "server_ip,server_port,data_center,user,newpwd,http_protocal", new QFilter[]{new QFilter("number", QCP.equals, "eas850")}); if (connObj == null) { throw new KDException("未获取到EAS链接配置,请联系系统管理员"); } else { String server_ip = connObj.getString("server_ip"); String server_port = connObj.getString("server_port"); String http_protocal = connObj.getString("http_protocal"); String data_center = connObj.getString("data_center"); String user = connObj.getString("user"); String newpwd = connObj.getString("newpwd"); try { Service s = new Service(); Call call = (Call) s.createCall(); WSContext rs = login(server_ip, server_port, http_protocal, data_center, user, newpwd, call); //调用业务接口 call.setOperationName("importBill"); //暂存 // call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSSCMWebServiceFacade?wsdl");//改 //审核 call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSSCMWebServiceExtFacade?wsdl");//改 call.setReturnQName(new QName("", "importBill")); call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //设置登录返回的session在soap头 "http://login.webservice.bos.kingdee.com"是固定的 SOAPHeaderElement header = new SOAPHeaderElement(http_protocal + "://login.webservice.bos.kingdee.com", "SessionId", rs.getSessionId()); call.addHeader(header); aa = (String) call.invoke(new Object[]{type, json, 1}); call.setOperationName("logout"); call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/EASLogin?wsdl");//ip改 // call.setReturnType(new QName("urn:client","WSContext"));//改 // call.setReturnClass(WSContext.class);//改 call.setReturnQName(new QName("", "logoutReturn"));//改 //超时 call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //登出接口参数 call.invoke(new Object[]{user, "eas", data_center, "l2"});//根据实际调整 System.out.println("登出成功"); //清理 call.clearOperation(); } catch (Exception e) { // TODO Auto-generated catch block throw new KDException("接口调用失败,异常信息如下:" + e.getMessage()); } } return aa; } @NotNull private static WSContext login(String server_ip, String server_port, String http_protocal, String data_center, String user, String newpwd, Call call) throws RemoteException { call.setOperationName("login"); call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/EASLogin?wsdl"); call.setReturnType(new QName("urn:client", "WSContext")); call.setReturnClass(WSContext.class); call.setReturnQName(new QName("", "loginReturn")); //超时 call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //登陆接口参数 WSContext rs = (WSContext) call.invoke(new Object[]{user, newpwd, "eas", data_center, "l2", Integer.valueOf(1)}); if (rs.getSessionId() == null) { throw new KDException("EAS登录失败请联系系统管理员,查看集成云链接配置!"); } System.out.println(rs.getSessionId()); //清理 call.clearOperation(); return rs; } public static String getServiceUnAudit(String json, String type) { String aa = null; DynamicObject connObj = QueryServiceHelper.queryOne("isc_database_link", "server_ip,server_port,data_center,user,newpwd,http_protocal", new QFilter[]{new QFilter("number", QCP.equals, "eas850")}); if (connObj == null) { throw new KDException("未获取到EAS链接配置,请联系系统管理员"); } else { String server_ip = connObj.getString("server_ip"); String server_port = connObj.getString("server_port"); String http_protocal = connObj.getString("http_protocal"); String data_center = connObj.getString("data_center"); String user = connObj.getString("user"); String newpwd = connObj.getString("newpwd"); try { Service s = new Service(); Call call = (Call) s.createCall(); WSContext rs = login(server_ip, server_port, http_protocal, data_center, user, newpwd, call); //调用业务接口 call.setOperationName("deleteBill"); //暂存 //call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSSCMWebServiceFacade?wsdl");//改 //审核 call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSSCMWebServiceExtFacade?wsdl");//改 call.setReturnQName(new QName("", "deleteBill")); call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //设置登录返回的session在soap头 "http://login.webservice.bos.kingdee.com"是固定的 SOAPHeaderElement header = new SOAPHeaderElement(http_protocal + "://login.webservice.bos.kingdee.com", "SessionId", rs.getSessionId()); call.addHeader(header); aa = (String) call.invoke(new Object[]{type, json}); call.setOperationName("logout"); call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/EASLogin?wsdl");//ip改 // call.setReturnType(new QName("urn:client","WSContext"));//改 // call.setReturnClass(WSContext.class);//改 call.setReturnQName(new QName("", "logoutReturn"));//改 //超时 call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //登出接口参数 call.invoke(new Object[]{user, "eas", data_center, "l2"});//根据实际调整 System.out.println("登出成功"); //清理 call.clearOperation(); } catch (Exception e) { // TODO Auto-generated catch block throw new KDException("接口调用失败,异常信息如下:" + e.getMessage()); } } return aa; } /** * 调用EAS接口公共方法 * * @param xml 入参 * @param OperationName 方法名称 * @return */ public static String genEASUtils(String xml, String OperationName) { { String aa = null; DynamicObject connObj = QueryServiceHelper.queryOne("isc_database_link", "server_ip,server_port,data_center,user,newpwd,http_protocal", new QFilter[]{new QFilter("number", QCP.equals, "eas850")}); if (connObj == null) { throw new KDException("未获取到EAS链接配置,请联系系统管理员"); } else { String server_ip = connObj.getString("server_ip"); String server_port = connObj.getString("server_port"); String http_protocal = connObj.getString("http_protocal"); String data_center = connObj.getString("data_center"); String user = connObj.getString("user"); String newpwd = connObj.getString("newpwd"); try { Service s = new Service(); Call call = (Call) s.createCall(); WSContext rs = login(server_ip, server_port, http_protocal, data_center, user, newpwd, call); //调用业务接口 call.setOperationName(OperationName); //暂存 //call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSSCMWebServiceFacade?wsdl");//改 //审核 call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/WSImportCustomerCompanyFacade?wsdl");//改 call.setReturnQName(new QName("", OperationName)); call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //设置登录返回的session在soap头 "http://login.webservice.bos.kingdee.com"是固定的 SOAPHeaderElement header = new SOAPHeaderElement(http_protocal + "://login.webservice.bos.kingdee.com", "SessionId", rs.getSessionId()); call.addHeader(header); aa = (String) call.invoke(new Object[]{xml}); call.setOperationName("logout"); call.setTargetEndpointAddress(http_protocal + "://" + server_ip + ":" + server_port + "/ormrpc/services/EASLogin?wsdl");//ip改 // call.setReturnType(new QName("urn:client","WSContext"));//改 // call.setReturnClass(WSContext.class);//改 call.setReturnQName(new QName("", "logoutReturn"));//改 //超时 call.setTimeout(Integer.valueOf(1000 * 600000 * 60)); call.setMaintainSession(true); //登出接口参数 call.invoke(new Object[]{user, "eas", data_center, "l2"});//根据实际调整 System.out.println("登出成功"); //清理 call.clearOperation(); } catch (Exception e) { // TODO Auto-generated catch block throw new KDException("接口调用失败,异常信息如下:" + e.getMessage()); } } return aa; } } }