1. pom 文件加包
<dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxws</artifactId><version>3.2.4</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http</artifactId><version>3.2.4</version></dependency><dependency><groupId>jaxen</groupId><artifactId>jaxen</artifactId><version>1.1-beta-11</version><exclusions><exclusion><groupId>xerces</groupId><artifactId>xercesImpl</artifactId></exclusion></exclusions></dependency>
2.增加配置文件
@Configuration
public class CxfConfig {@Autowiredprivate PersonnelsyncService personnelsyncService;@Beanpublic ServletRegistrationBean servicesServlet() {ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/services/*");bean.addInitParameter("hide-service-list-page", "true");return bean;}@Bean(name = Bus.DEFAULT_BUS_ID)public SpringBus springBus() {SpringBus springBus = new SpringBus();springBus.getProperties().put("org.apache.cxf.stax.maxTextLength", Integer.MAX_VALUE);return springBus;}@Beanpublic Endpoint organizationInfoService() {EndpointImpl endpoint = new EndpointImpl(springBus(), personnelsyncService);endpoint.publish("/OutHrmService");return endpoint;}
}
表示发布
3.
@WebService(name ="OutHrmService",targetNamespace="http://cornWeb.hbportal.wiseda.com")
@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)
public interface PersonnelsyncService {@WebMethod(operationName = "updateHrmResourceInfo")ReturnMes updateHrmResourceInfo(@WebParam(name="interfaceCode")String interfaceCode, @WebParam(name="recordXml")String recordXml) throws Exception;
}
4.实现类
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//package com.wiseda.protal.webservice.impl;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.wiseda.protal.dao.*;
import com.wiseda.protal.entity.*;
import com.wiseda.protal.eum.PersonSyncTypeEnum;
import com.wiseda.protal.vo.PersonSyncVo;
import com.wiseda.protal.webservice.PersonnelsyncService;
import com.wiseda.protal.webservice.ReturnMes;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import cn.hutool.core.bean.BeanUtil;
import org.springframework.transaction.annotation.Transactional;import javax.jws.WebService;
import java.util.*;@WebService(serviceName ="OutHrmService",targetNamespace="http://cornWeb.hbportal.wiseda.com")
@Service
@Transactional
public class PersonnelsyncServiceImpl implements PersonnelsyncService {@AutowiredPersonnelSyncMapper personnelSyncMapper;@AutowiredSysEmployeeOrgMMapper sysEmployeeOrgMapper;@AutowiredSysPositionMapper sysPositionMapper;@AutowiredSysOrgUnitMMapper sysOrgUnitMapper;@AutowiredSysPersonnelSyncLogMapper sysPersonnelSyncLogMapper;@Overridepublic ReturnMes updateHrmResourceInfo(String interfaceCode,String recordXml) throws Exception {String comp="";String BasicCode = "";ReturnMes rm = new ReturnMes();List<Map<String, String>> list = new ArrayList<>();SysPersonnelSyncLog sysPersonnelSyncLog = new SysPersonnelSyncLog();sysPersonnelSyncLog.setCrtTime(new Date());sysPersonnelSyncLog.setBasiCode(BasicCode);sysPersonnelSyncLog.setSendPara(recordXml);try {Document document = DocumentHelper.parseText(recordXml);Element root = document.getRootElement();comp=root.element("Head").element("Comp").getText();BasicCode = root.element("Head").element("BasicCode").getText();List nodes= document.selectNodes("//Msg/Data/*");for (Iterator iter = nodes.iterator(); iter.hasNext(); ) {Map<String, String> param = new HashMap<>();Element element = (Element) iter.next();Element header = element.element("Header");List dataItems = header.elements("DataItem");for (Object it : dataItems) {Element element1 = (Element) it;param.put(element1.attributeValue("FieldName"), element1.attributeValue("FieldValue"));}list.add(param);}if(PersonSyncTypeEnum.PERSONNEL.getMessge().equals(BasicCode)){insertPersonnel(list);}if(PersonSyncTypeEnum.POST.getMessge().equals(BasicCode)){insertPost(list);}if(PersonSyncTypeEnum.DEPARTMENT.getMessge().equals(BasicCode)){insertDepartment(list);}rm.setErrorDescribe("成功");rm.setRecordCode(comp);rm.setSateCode("0");rm.setSysIdKeyList("0");sysPersonnelSyncLog.setReturnPara(rm.toString());}catch (Exception e){e.printStackTrace();rm.setErrorDescribe("服务错误解析失败:"+e);rm.setRecordCode(comp);rm.setSateCode("103");rm.setSysIdKeyList("0");sysPersonnelSyncLog.setReturnPara(e.toString());}sysPersonnelSyncLogMapper.insert(sysPersonnelSyncLog);return rm;}public void insertPersonnel(List<Map<String, String>> list){list.stream().forEach(x->{PersonSyncVo personSyncVo = BeanUtil.mapToBean(x, PersonSyncVo.class, true);String user_cd = personSyncVo.getSys_user_cd().substring(personSyncVo.getSys_user_cd().length() - 8);int size = personnelSyncMapper.selectList(new LambdaQueryWrapper<SysEmployee>().eq(SysEmployee::getId, user_cd)).size();if(size >0){personnelSyncMapper.deleteById(user_cd);sysEmployeeOrgMapper.delete(new LambdaQueryWrapper<SysEmployeeOrg>().eq(SysEmployeeOrg::getEmpId,user_cd));}SysEmployee sysEmployee = new SysEmployee();sysEmployee.setId(user_cd);sysEmployee.setCode(user_cd);sysEmployee.setName(personSyncVo.getSys_cd_nm());if ("36501".equals(personSyncVo.getSex_id())) {sysEmployee.setGender("1");} else {sysEmployee.setGender("2");}sysEmployee.setEmail(personSyncVo.getEmail_addr());sysEmployee.setMobile(personSyncVo.getMobile());sysEmployee.setIsDeleted(0);sysEmployee.setIsUse(1);sysEmployee.setPositionId(personSyncVo.getPost_id());sysEmployee.setCreateTime(new Date());sysEmployee.setSortNum(Integer.parseInt(personSyncVo.getSys_ord_cd()));personnelSyncMapper.insert(sysEmployee);//人员表SysEmployeeOrg sysEmployeeOrg = new SysEmployeeOrg();sysEmployeeOrg.setId(UUID.randomUUID().toString());//根据部门对照表,将数字门户部门Id替换 人资部门IdString orgid = personnelSyncMapper.selectPortalDeptId(personSyncVo.getDept_id());sysEmployeeOrg.setOrgId(orgid);sysEmployeeOrg.setEmpId(user_cd);sysEmployeeOrg.setIsMaster(1);sysEmployeeOrgMapper.insert(sysEmployeeOrg);//人员部门关联表});}public void insertPost(List<Map<String, String>> list){list.stream().forEach(x->{PersonSyncVo personSyncVo = BeanUtil.mapToBean(x, PersonSyncVo.class, true);int size = sysPositionMapper.selectList(new LambdaQueryWrapper<SysPosition>().eq(SysPosition::getId, personSyncVo.getSys_id_key())).size();if(size>0){sysPositionMapper.deleteById(personSyncVo.getSys_id_key());}SysPosition sysPosition = new SysPosition();sysPosition.setId(personSyncVo.getSys_id_key());sysPosition.setName(personSyncVo.getSys_cd_nm());sysPositionMapper.insert(sysPosition);});}public void insertDepartment(List<Map<String, String>> list){list.stream().forEach(x->{PersonSyncVo personSyncVo = BeanUtil.mapToBean(x, PersonSyncVo.class, true);//查询公司主键String companyId = sysOrgUnitMapper.selectPortalComp(personSyncVo.getYy_gsml());//上级部门idString parentId = personnelSyncMapper.selectPortalDeptId(personSyncVo.getParent_id());// 查询数字化门户对应的部门String departId = personnelSyncMapper.selectPortalDeptId(personSyncVo.getSys_id_key());int size = sysOrgUnitMapper.selectList(new LambdaQueryWrapper<SysOrgUnit>().eq(SysOrgUnit::getId, departId)).size();if(size>0){sysOrgUnitMapper.deleteById(departId);}SysOrgUnit sysOrgUnit = new SysOrgUnit();sysOrgUnit.setId(departId);sysOrgUnit.setCode(departId);sysOrgUnit.setName(personSyncVo.getSys_cd_nm());sysOrgUnit.setAliasCode(departId);sysOrgUnit.setAliasName(personSyncVo.getSys_cd_nm());sysOrgUnit.setNodeType("DEPT");if(StringUtils.isNotBlank(parentId)){sysOrgUnit.setParentId(parentId);}else{sysOrgUnit.setParentId(companyId);}sysOrgUnit.setIsInvented(0);sysOrgUnit.setIsUse(1);sysOrgUnit.setPathId(departId);sysOrgUnit.setIsDeleted(0);sysOrgUnit.setCreateTime(new Date());sysOrgUnit.setSortNum(Integer.parseInt(personSyncVo.getSys_ord_cd()));sysOrgUnitMapper.insert(sysOrgUnit);});}
}
5.postman调用
参数 要用 <![CDATA[]]> 包装 xml的话,要顶格写 列如:<![CDATA[<?xml version="1.0" encoding="gb2312"?><?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://cornWeb.hbportal.wiseda.com"><soapenv:Body><test:updateHrmResourceInfo><interfaceCode><![CDATA[10106]]></interfaceCode> <recordXml><![CDATA[<?xml version="1.0" encoding="gb2312"?><Msg><Head><Source></Source><BasicCode>10106</BasicCode><Cryp></Cryp><Comp>35893863</Comp><Date>2024/04/11 03:00:24</Date><DataDefine><HeaderDefine QueryName="人员代码(全部)"><FieldItem FieldName="sys_id_key" Caption="系统内码" FieldType="NUMBER(18,0)" FieldLength="" Remark="" isPrimaryKey="True"/><FieldItem FieldName="sys_user_cd" Caption="国家局代码" FieldType="VARCHAR22(30)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="sys_cd_nm" Caption="职工姓名" FieldType="VARCHAR22(100)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="sex_id" Caption="性别" FieldType="NUMBER(18,0)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="dept_id" Caption="所属部门" FieldType="NUMBER(18,0)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="mobile" Caption="移动电话" FieldType="VARCHAR22(60)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="sys_ord_cd" Caption="排序码" FieldType="NUMBER(6,0)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="sys_use_mark" Caption="启用标记" FieldType="NUMBER(1,0)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="rem" Caption="所属公司" FieldType="VARCHAR22(100)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="tele_no" Caption="办公电话" FieldType="VARCHAR22(30)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="post_id" Caption="岗位" FieldType="NUMBER(18,0)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="email_addr" Caption="E-mail" FieldType="VARCHAR22(60)" FieldLength="" Remark="" isPrimaryKey="False"/><FieldItem FieldName="staff_tp_id" Caption="人员类别" FieldType="NUMBER(18,0)" FieldLength="" Remark="" isPrimaryKey="False"/></HeaderDefine></DataDefine></Head><Data><Row Index="1"><Header Action="update"><DataItem FieldName="sys_id_key" FieldValue="38211"/><DataItem FieldName="sys_user_cd" FieldValue="2013000100008712"/><DataItem FieldName="sys_cd_nm" FieldValue="王运华"/><DataItem FieldName="sex_id" FieldValue="36501"/><DataItem FieldName="dept_id" FieldValue="12823"/><DataItem FieldName="mobile" FieldValue="15933977958"/><DataItem FieldName="sys_ord_cd" FieldValue="99999"/><DataItem FieldName="sys_use_mark" FieldValue="1"/><DataItem FieldName="rem" FieldValue="1004"/><DataItem FieldName="tele_no" FieldValue=""/><DataItem FieldName="post_id" FieldValue=""/><DataItem FieldName="email_addr" FieldValue=""/><DataItem FieldName="staff_tp_id" FieldValue="30709112"/></Header></Row><Row Index="2"><Header Action="update"><DataItem FieldName="sys_id_key" FieldValue="38211"/><DataItem FieldName="sys_user_cd" FieldValue="2013000100008712111"/><DataItem FieldName="sys_cd_nm" FieldValue="王运华111"/><DataItem FieldName="sex_id" FieldValue="36501"/><DataItem FieldName="dept_id" FieldValue="12823"/><DataItem FieldName="mobile" FieldValue="15933977958"/><DataItem FieldName="sys_ord_cd" FieldValue="99999"/><DataItem FieldName="sys_use_mark" FieldValue="1"/><DataItem FieldName="rem" FieldValue="1004"/><DataItem FieldName="tele_no" FieldValue=""/><DataItem FieldName="post_id" FieldValue=""/><DataItem FieldName="email_addr" FieldValue=""/><DataItem FieldName="staff_tp_id" FieldValue="30709112"/></Header></Row><Row Index="3"><Header Action="update"><DataItem FieldName="sys_id_key" FieldValue="38211"/><DataItem FieldName="sys_user_cd" FieldValue="2013000100008712222"/><DataItem FieldName="sys_cd_nm" FieldValue="王运华2222"/><DataItem FieldName="sex_id" FieldValue="36501"/><DataItem FieldName="dept_id" FieldValue="12823"/><DataItem FieldName="mobile" FieldValue="15933977958"/><DataItem FieldName="sys_ord_cd" FieldValue="99999"/><DataItem FieldName="sys_use_mark" FieldValue="1"/><DataItem FieldName="rem" FieldValue="1004"/><DataItem FieldName="tele_no" FieldValue=""/><DataItem FieldName="post_id" FieldValue=""/><DataItem FieldName="email_addr" FieldValue=""/><DataItem FieldName="staff_tp_id" FieldValue="30709112"/></Header></Row></Data>
</Msg>]]></recordXml>
</test:updateHrmResourceInfo></soapenv:Body>
</soapenv:Envelope>