GetEmployeeInfoMain.java 8.79 KB
package com.ruoyi.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.xml.namespace.QName;

import com.ruoyi.domain.TJkEmployeeinfo;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
 * 获取金蝶人员表数据
 * 
 * @author Administrator
 *
 */
public class GetEmployeeInfoMain {
	Log logger = LogFactory.getLog(GetEmployeeInfoMain.class);

	public static List<TJkEmployeeinfo> getemployeeInfo() {
		List<TJkEmployeeinfo> list = new ArrayList<TJkEmployeeinfo>();
		// 提供接口的地址
		String url = "http://58.247.254.22:31/PJDataInterface/PJDataService.asmx";
		// 域名,这是在server定义的--不知道的可以问接口提供方,他们一并提供这个
		String soapaction = "http://www.pd-transport.com/";

		String unintCode = "KD01.0111";
		String iDCard = "";

		Service service = new Service();
		try {
			Call call = (Call) service.createCall();
			call.setTargetEndpointAddress(url);
			call.setOperationName(new QName(soapaction, "GetEmployee")); // 设置要调用哪个方法
			call.addParameter(new QName(soapaction, "UnintCode"), // 设置要传递的参数--要和接口方提供的参数名一致
					org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
			call.addParameter(new QName(soapaction, "IDCard"), // 设置要传递的参数
					org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
			call.setReturnType(new QName(soapaction, "GetEmployee"), String.class); // 要返回的数据类型(自定义类型,我这边接口提供方给我返回的是json字符串,所以我用string类型接收。这个地方一定要设置好,不然各种报错很崩溃)

			call.setUseSOAPAction(true);
			call.setSOAPActionURI(soapaction + "GetEmployee");
// 调用方法并传递参数-传递的参数和设置的参数要对应,顺序不能搞错了
			String strResult = (String) call.invoke(new Object[] { unintCode, iDCard });
			Document doc = null;
			doc = DocumentHelper.parseText(strResult);// 获取根节点
			Element rootElt = doc.getRootElement();
			Iterator iter = (Iterator) rootElt.elementIterator("Emp");
			while (iter.hasNext()) {
				TJkEmployeeinfo emp = new TJkEmployeeinfo();
				Element recordEle = (Element) iter.next();
				String emp_id = recordEle.elementTextTrim("EM_ID");
				String companyName = recordEle.elementTextTrim("CompanyName");
				String departmentName = recordEle.elementTextTrim("DepartmentName");
				String positName = recordEle.elementTextTrim("PositName");
				String code = recordEle.elementTextTrim("Code");
				String employeeName = recordEle.elementTextTrim("EmployeeName");
				String age = recordEle.elementTextTrim("Age");
				String status = recordEle.elementTextTrim("Status");
				String unitFullName = recordEle.elementTextTrim("UnitFullName");
				String inPositType = recordEle.elementTextTrim("InPositType");
				String iDCardID = recordEle.elementTextTrim("IDCardID");
				String sexType = recordEle.elementTextTrim("SexType");
				String nationName = recordEle.elementTextTrim("NationName");
				String nativePlace = recordEle.elementTextTrim("NativePlace");
				String birthday = recordEle.elementTextTrim("Birthday");
				String politicsStatus = recordEle.elementTextTrim("PoliticsStatus");
				String marridStatus = recordEle.elementTextTrim("MarridStatus");
				String startWordTime = recordEle.elementTextTrim("StartWordTime");
				String telphone = recordEle.elementTextTrim("Telphone");
				String mobile = recordEle.elementTextTrim("Mobile");
				String hRMS_USERFIELD_3 = recordEle.elementTextTrim("HRMS_USERFIELD_3");
				String hRMS_USERFIELD_47 = recordEle.elementTextTrim("HRMS_USERFIELD_47");
				String hRMS_USERFIELD_40 = recordEle.elementTextTrim("HRMS_USERFIELD_40");
				String hRMS_USERFIELD_45 = recordEle.elementTextTrim("HRMS_USERFIELD_45");
				String hRMS_USERFIELD_41 = recordEle.elementTextTrim("HRMS_USERFIELD_41");
				String fname = recordEle.elementTextTrim("Fname");
				String enterDeptDate = recordEle.elementTextTrim("EnterDeptDate");
				String enterGroupDate = recordEle.elementTextTrim("EnterGroupDate");
				String inpositionDate = recordEle.elementTextTrim("InpositionDate");
				String emptypecls = recordEle.elementTextTrim("Emptypecls");
				String enterDate = recordEle.elementTextTrim("EnterDate");
				String contractDate = recordEle.elementTextTrim("ContractDate");
				if (emp_id != null && !emp_id.equals("") && !emp_id.equals("null"))
					emp.setEmId(emp_id);
				if (companyName != null && !companyName.equals("") && !companyName.equals("null"))
					emp.setCompanyname(companyName);
				if (departmentName != null && !departmentName.equals("") && !departmentName.equals("null"))
					emp.setDepartmentname(departmentName);
				if (positName != null && !positName.equals("") && !positName.equals("null"))
					emp.setPositname(positName);
				if (code != null && !code.equals("") && !code.equals("null"))
					emp.setCode(code.replace("04-", ""));
				if (employeeName != null && !employeeName.equals("") && !employeeName.equals("null"))
					emp.setEmployeename(employeeName);
				if (age != null && !age.equals("") && !age.equals("null"))
					emp.setAge(Integer.parseInt(age));
				if (status != null && !status.equals("") && !status.equals("null"))
					emp.setStatus(status);
				if (unitFullName != null && !unitFullName.equals("") && !unitFullName.equals("null"))
					emp.setUnitfullname(unitFullName);
				if (inPositType != null && !inPositType.equals("") && !inPositType.equals("null"))
					emp.setInposittype(inPositType);
				if (iDCardID != null && !iDCardID.equals("") && !iDCardID.equals("null"))
					emp.setIdcardid(iDCardID.toUpperCase());
				if (sexType != null && !sexType.equals("") && !sexType.equals("null"))
					emp.setSextype(sexType);
				if (nationName != null && !nationName.equals("") && !nationName.equals("null"))
					emp.setNationname(nationName);
				if (nativePlace != null && !nativePlace.equals("") && !nativePlace.equals("null"))
					emp.setNativeplace(nativePlace);
				if (birthday != null && !birthday.equals("") && !birthday.equals("null"))
					emp.setBirthday(ConstDateUtil.parseDate(birthday,"yyyy-MM-dd"));
				if (politicsStatus != null && !politicsStatus.equals("") && !politicsStatus.equals("null"))
					emp.setPoliticsstatus(politicsStatus);
				if (marridStatus != null && !marridStatus.equals("") && !marridStatus.equals("null"))
					emp.setMarridstatus(marridStatus);
				if (startWordTime != null && !startWordTime.equals("") && !startWordTime.equals("null"))
					emp.setStartwordtime(ConstDateUtil.parseDate(startWordTime,"yyyy-MM-dd"));
				if (telphone != null && !telphone.equals("") && !telphone.equals("null"))
					emp.setTelphone(telphone);
				if (mobile != null && !mobile.equals("") && !mobile.equals("null"))
					emp.setMobile(mobile);
				if (hRMS_USERFIELD_3 != null && !hRMS_USERFIELD_3.equals("") && !hRMS_USERFIELD_3.equals("null"))
					emp.setHrmsUserfield3(hRMS_USERFIELD_3);
				if (hRMS_USERFIELD_47 != null && !hRMS_USERFIELD_47.equals("") && !hRMS_USERFIELD_47.equals("null"))
					emp.setHrmsUserfield47(hRMS_USERFIELD_47);
				if (hRMS_USERFIELD_40 != null && !hRMS_USERFIELD_40.equals("") && !hRMS_USERFIELD_40.equals("null"))
					emp.setHrmsUserfield40(hRMS_USERFIELD_40);
				if (hRMS_USERFIELD_45 != null && !hRMS_USERFIELD_45.equals("") && !hRMS_USERFIELD_45.equals("null"))
					emp.setHrmsUserfield45(hRMS_USERFIELD_45);
				if (hRMS_USERFIELD_41 != null && !hRMS_USERFIELD_41.equals("") && !hRMS_USERFIELD_41.equals("null"))
					emp.setHrmsUserfield41(hRMS_USERFIELD_41);
				if (fname != null && !fname.equals("") && !fname.equals("null"))
					emp.setFname(fname);
				if (enterDeptDate != null && !enterDeptDate.equals("") && !enterDeptDate.equals("null"))
					emp.setEnterdeptdate(ConstDateUtil.parseDate(enterDeptDate,"yyyy-MM-dd"));
				if (enterGroupDate != null && !enterGroupDate.equals("") && !enterGroupDate.equals("null"))
					emp.setEntergroupdate(ConstDateUtil.parseDate(enterGroupDate,"yyyy-MM-dd"));
				if (inpositionDate != null && !inpositionDate.equals("") && !inpositionDate.equals("null"))
					emp.setInpositiondate(ConstDateUtil.parseDate(inpositionDate,"yyyy-MM-dd"));
				if (emptypecls != null && !emptypecls.equals("") && !emptypecls.equals("null"))
					emp.setEmptypecls(emptypecls);
				if (enterDate != null && !enterDate.equals("") && !enterDate.equals("null"))
					emp.setEnterdate(ConstDateUtil.parseDate(enterDate,"yyyy-MM-dd"));
				if (contractDate != null && !contractDate.equals("") && !contractDate.equals("null"))
					emp.setContractdate(ConstDateUtil.parseDate(contractDate,"yyyy-MM-dd"));
				list.add(emp);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return list;
	}

}