1 .oa 外部数据源配置好
取数据源名称
引用key 固定写法 datasource.A_nc
datasource.数据源名称
getConnection("datasource.A_nc",xf);//A账
2 引用方式
package weaver.interfaces.jphr;import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import javax.xml.namespace.QName;import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.utils.StringUtils;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.ObjectMapper;import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.StaticObj;
import weaver.interfaces.datasource.DataSource;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;/***/
public class PriceauditAction17 extends BaseBean implements Action {@Overridepublic String execute(RequestInfo info) {RequestInfo requestInfo = info;try {String requestid = requestInfo.getRequestid();//流程请求idString tablename = requestInfo.getRequestManager().getBillTableName();//流程表单数据库表RecordSet rs = new RecordSet();StringBuffer sbSql = new StringBuffer("select id ");sbSql.append(" ,lsh ");//编号sbSql.append(" ,xf ");//采购组织sbSql.append(" ,qdrq ");//签订日期sbSql.append(" ,gf ");//供应商sbSql.append(" ,gysbm ");//供应商编码sbSql.append(" ,ssrq ");//生效日期 sbSql.append(" ,sxrq ");//失效日期sbSql.append(" ,sb ");//税比sbSql.append(" from "+tablename+" a where 1=1 ");sbSql.append(" and a.requestid = "+ requestid);writeLog("价格协商纪要查询sql:"+sbSql);rs.execute(sbSql.toString() );//获取流程表单信息Map<String,Object> map = new HashMap<>();String mainid ="";//主表idString lsh ="";//编号String xf = "";//采购组织String qdrq = "";//签订日期String gf = "";//供应商String gysbm = "";//供应商编码String ssrq = "";//生效日期 String sxrq = "";//失效日期String sb = "";//税比double decimalValue = 0;//税比if (rs.next()) {mainid =rs.getString("id");//主表idlsh =rs.getString("lsh");//编号xf =rs.getString("xf");//需方 采购组织qdrq =rs.getString("qdrq");//签订日期gf =rs.getString("gf");//供应商gysbm =rs.getString("gysbm");//供应商编码ssrq =rs.getString("ssrq");//生效日期 sxrq =rs.getString("sxrq");//失效日期sb =rs.getString("sb");//税比//转换百分比=================SString percentage = sb; // 输入要转换的百分比字符串if (percentage.endsWith("%")) {int value = Integer.parseInt(percentage.substring(0, percentage.length() - 1));decimalValue = ((double)value / 100);writeLog("转换后的小数值为:" + decimalValue);} else {String msg_decimal = "比率是无效的百分比格式";writeLog(msg_decimal);String tmpstr=convertEncodingFormat(msg_decimal, "GBK","GBK");requestInfo.getRequestManager().setMessagecontent("错误信息:"+tmpstr);requestInfo.getRequestManager().setMessageid(requestid);return Action.FAILURE_AND_CONTINUE;}//转换百分比================EString org_code = "";//采购组织编码;if(!"".equals(xf) && null != xf) {writeLog("需方 采购组织 PK值:"+xf);if("0001A11000000000GJOI".equals(xf)) {//山东org_code = getConnection("datasource.A_nc",xf);//A账}else if("0001A110000000003F5U".equals(xf)) {//湖北org_code = getConnection("datasource.A_nc",xf);//A账}else if("0001A110000000003F4U".equals(xf)) {//四川org_code = getConnection("datasource.A_nc",xf);//A账}else {org_code = getConnection("datasource.jpnc",xf);//B账}writeLog("需方 采购组织org_code:"+org_code);}map.put("pk_org_code", org_code);map.put("pk_dept_code","");map.put("dbilldate",qdrq);map.put("pk_bizpsn_code","");map.put("bsctype","N");map.put("vmemo","OA价格协商纪要流程编号:"+ lsh);}//供应商编码if(!"".equals(gysbm) && null != gysbm) {String supplier_num = "";writeLog("供应商编码:"+gysbm);if("SD001".equals(xf)) {//山东supplier_num = getConnectionCodeSupplierNum("datasource.A_nc",gysbm);//A账}else if("HB002".equals(gysbm)) {//湖北supplier_num = getConnectionCodeSupplierNum("datasource.A_nc",gysbm);//A账}else if("SC001".equals(gysbm)) {//四川supplier_num = getConnectionCodeSupplierNum("datasource.A_nc",gysbm);//A账}else {supplier_num = getConnectionCodeSupplierNum("datasource.jpnc",gysbm);//B账}if(supplier_num.equals("1")) {}else {String tmpstr=convertEncodingFormat("供应商编码NC系统不存在!", "GBK","GBK");requestInfo.getRequestManager().setMessagecontent("错误信息:"+tmpstr);requestInfo.getRequestManager().setMessageid(requestid);writeLog("NC interface msg:FAIL 供应商编码NC系统不存在!");return Action.FAILURE_AND_CONTINUE;}}else {String tmpstr=convertEncodingFormat("供应商编码不能为空", "GBK","GBK");requestInfo.getRequestManager().setMessagecontent("错误信息:"+tmpstr);requestInfo.getRequestManager().setMessageid(requestid);writeLog("NC interface msg:FAIL 供应商编码不能为空");return Action.FAILURE_AND_CONTINUE;}//物料 =============================SRecordSet rs2 = new RecordSet();StringBuffer sbSql_dt = new StringBuffer("select id ");sbSql_dt.append(" ,wlbm ");//物料编码sbSql_dt.append(" ,wlmc ");//物料名称sbSql_dt.append(" ,dw ");//单位sbSql_dt.append(" ,yj ");//原价sbSql_dt.append(" ,xj ");//现价sbSql_dt.append(" ,bz ");//行备注sbSql_dt.append(" ,shxrq ");//生效sbSql_dt.append(" ,sxrq ");//失效日期sbSql_dt.append(" from "+tablename+"_dt1 a where 1=1 ");sbSql_dt.append(" and mainid = "+ mainid);writeLog("价格协商纪要查询sql:"+sbSql_dt);rs2.execute(sbSql_dt.toString() );List<Map<String,Object>> materialList = new ArrayList<Map<String,Object>>();while (rs2.next()) {String wlbm=rs2.getString("wlbm");String xj=rs2.getString("xj");String bz=rs2.getString("bz");String ssrq_dt=rs2.getString("shxrq");String sxrq_dt=rs2.getString("sxrq");Map<String,Object> expMap1 = new HashMap<String,Object>();expMap1.put("cmaterialoid_code", wlbm);//物料编码expMap1.put("supplier_code", gysbm);//供应商编码expMap1.put("nqttaxprice", xj);//含税价expMap1.put("vmemo_b", bz);//行备注expMap1.put("border", "Y");//预订 默认预订 YexpMap1.put("dqtvaliddate", ssrq);//生效时间 用主表的expMap1.put("dqtinvaliddate", sxrq);//失效时间 用主表的expMap1.put("vbdef2", decimalValue + "");//税比 用主表的materialList.add(expMap1);}map.put("body", materialList);//物料 =============================EObjectMapper mapper = new ObjectMapper();String jsonStr = mapper.writeValueAsString(map);writeLog("NC interface msg jsonStr 入参:"+ jsonStr);Service service=new Service();Call call = (Call)service.createCall();//String IP_PORT = "192.168.1.133:633";//B账 192.168.1.2:633 A账 192.168.130.15:633 本地测试192.168.18.35:80 String IP_PORT = "192.168.1.2:633";//B账 192.168.1.2:633 A账 192.168.130.15:633 本地测试192.168.18.35:80 //0001A110000000003F4U 四川金彭车业有限公司 SC001//0001A11000000000GJOI 山东金彭新能源科技有限公司 SD001//0001A110000000003F5U 湖北金彭车业有限公司 HB002if("0001A11000000000GJOI".equals(xf)) {//山东IP_PORT = "192.168.130.15:633";}else if("0001A110000000003F5U".equals(xf)) {//湖北IP_PORT = "192.168.130.15:633";}else if("0001A110000000003F4U".equals(xf)) {//四川IP_PORT = "192.168.130.15:633";}String URL = "http://"+IP_PORT+"/uapws/service/JpncinterfaceService";writeLog("NC interface msg URL:"+ URL);call.setTargetEndpointAddress(new java.net.URL(URL));call.setOperationName(new QName("http://jpncinterface.itf.nc/IJpncInterface", "getNcInterface"));call.addParameter("ordertype", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);call.addParameter("operationtype", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);call.addParameter("orderform", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);String result = null;result=(String)call.invoke(new Object[]{"priceaudit","Insert", jsonStr});writeLog("NC interface msg:"+ result);if ( result.contains("\"$successful\":\"Y\"") ) {writeLog("NC interface msg:SUCCESS: "+result);}else{String tmpstr=convertEncodingFormat(result.trim(), "GBK","GBK");requestInfo.getRequestManager().setMessagecontent("错误信息:"+tmpstr);requestInfo.getRequestManager().setMessageid(requestid);writeLog("NC interface msg:FAIL"+result);return Action.FAILURE_AND_CONTINUE;} } catch (Exception e) { writeLog("异常:"+e.getMessage()+"");} return Action.SUCCESS;}/*** * @param datasource* @return*/public static String getConnection(String datasource,String pk_org){String org_code = "";//调用数据源生成jdbc链接DataSource jpnc = (DataSource) StaticObj.getServiceByFullname((datasource), DataSource.class);//local为配置的数据源标识Connection conn = null ;ResultSet rswb = null ;try{conn = jpnc.getConnection();rswb = conn.createStatement().executeQuery("select pk_org,name,code from jpncdb1.org_orgs where dr=0 and islastversion='Y' and pk_org = '"+pk_org+"'");while(rswb.next()){org_code = rswb.getString("code");//writeLog("业务单元编码:"+rswb.getString("code"));break;}rswb.close();}catch(Exception e){e.getStackTrace();//writeLog(e);}finally{try {conn.close();} catch (SQLException e) {}}return org_code;}/*** * @return*/public static String getConnectionCodeSupplierNum(String datasource,String code){String supplier_num = "";//调用数据源生成jdbc链接DataSource jpnc = (DataSource) StaticObj.getServiceByFullname((datasource), DataSource.class);//local为配置的数据源标识Connection conn = null ;ResultSet rswb = null ;try{conn = jpnc.getConnection();rswb = conn.createStatement().executeQuery("select count(1) supplier_num from jpncdb1.bd_supplier where code = '"+code+"'");while(rswb.next()){supplier_num = rswb.getString("supplier_num");break;}rswb.close();}catch(Exception e){e.getStackTrace();//writeLog(e);}finally{try {conn.close();} catch (SQLException e) {}}return supplier_num;}public static String convertEncodingFormat(String str, String formatFrom, String FormatTo) {String result = null;if (!(str == null || str.length() == 0)) {try {result = new String(str.getBytes(formatFrom), FormatTo);} catch (UnsupportedEncodingException e) {e.printStackTrace();}}return result;}}