erp10-webService

Posted 六叔的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了erp10-webService相关的知识,希望对你有一定的参考价值。

webService是跨语言的远程调用技术,传递的是xml文件
CXF框架用来解析xml文件

常用的远程调用技术:
1、Socket 套接字  TCP/IP   UDP
2、webservice    跨语言    因为传输的数据是XML·    可以和spring进行整合
3、http调用
4、RML(远程方法调用)   Hessian框架    只能用于java编写的项目



第一节、webService的demo

一、服务端

1、pom.xml:
需要添加spring的依赖(省略)
和CXF的依赖
  1. <dependency>
  2. <groupId>org.apache.cxf</groupId>
  3. <artifactId>cxf-rt-frontend-jaxws</artifactId>
  4. <version>3.0.1</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.apache.cxf</groupId>
  8. <artifactId>cxf-rt-transports-http</artifactId>
  9. <version>3.0.1</version>
  10. </dependency>

2、加入web.xml  
添加spring的listener contextloaderlister    --contextconfigerlocation    --classpath:applicationContext.xml

3、创建接口和类
  1. package com.itcast.weather;
  2. import javax.jws.WebService;
  3. @WebService
  4. public interface IWeatherService {
  5. public String getWeatherInFoByCityName( String cityName);
  6. }
需要在接口上加@webservice注解,CXF才能使用

  1. package com.itcast.weather;
  2. public class WeatherService implements IWeatherService {
  3. @Override
  4. public String getWeatherInFoByCityName(String cityName) {
  5. if ("北京".equals(cityName)) {
  6. return "轻度雾霾";
  7. }
  8. return "晴天";
  9. }
  10. }
4、在项目中加入配置文件
webservice配置:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
  7. <bean id="weatherService" class="com.itcast.weather.WeatherService" ></bean>
  8. <jaxws:server address="/weather" >
  9. <jaxws:serviceBean>
  10. <ref bean="weatherService" />
  11. </jaxws:serviceBean>
  12. </jaxws:server>
  13. </beans>

CXFServlet配置(web.xml)
  1. <servlet>
  2. <servlet-name>webservice</servlet-name>
  3. <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  4. </servlet>
  5. <servlet-mapping>
  6. <servlet-name>webservice</servlet-name>
  7. <url-pattern>/ws/*</url-pattern>
  8. </servlet-mapping>

此时的访问路径为:
http://localhost:8080/CXFServer/ws/weather?wsdl
 




二、客户端

1、和服务端添加同样的依赖
2、运用jdk里面的工具将xml转换成java代码
 
 方法:
进入到项目目录中,在想要生成java文件的地方按住shift右键,打开命令行
    ,回车
 结果:
 生成的文件夹目录如下:
 其中只有IweatherService这个接口是有用的。其他的都删掉也可以

3、配置客户端xml
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
  7. <!-- 把jaxws:client当做一个特殊的bean -->
  8. <jaxws:client id="weatherService" serviceClass="com.itcast.weather.IWeatherService"
  9. address="http://localhost:8080/CXFServer/ws/weather?wsdl">
  10. </jaxws:client>
  11. </beans>

4、测试类Test
  1. public class Test {
  2. public static void main(String[] args) {
  3. ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext_cxf.xml");
  4. IWeatherService weatherService = (IWeatherService) context.getBean("weatherService");
  5. String info = weatherService.getWeatherInFoByCityName("北京");
  6. System.out.println(info);
  7. }
  8. }


 

第二节:手机号码归属地查询

1、配置文件
<jaxws:client id="code" 
                    serviceClass="cn.com.webxml.MobileCodeWSSoap"
                    address="http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl"                 >
        
    </jaxws:client>  
2、wsimport导入接口文件
3、创建测试类:
  1. public static void main(String[] args) {
  2. ApplicationContext app = new ClassPathXmlApplicationContext("classpath:applicationContext_cxf.xml");
  3. MobileCodeWSSoap mobileCode = (MobileCodeWSSoap) app.getBean("code");
  4. String codeInfo = mobileCode.getMobileCodeInfo("1850137", null);
  5. System.out.println(codeInfo);
  6. }



第三节、红日物流BOS系统开发

一、数据库设计-----mysql

运单:
 state:
0-待发货      1-已发货     2-已结束

运单明细:
 




二、代码生成器生成基本代码
 
 



三、bos两个服务开发
1、pol.xml配置:参上
2、applicationContext_cxf.xml配置:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:jaxws="http://cxf.apache.org/jaxws"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">
  8. <bean id="waybillService" class="cn.itcast.bos.ws.WayBillService" ></bean>
  9. <jaxws:server address="waybill" >
  10. <jaxws:serviceBean>
  11. <ref bean="waybillService" />
  12. </jaxws:serviceBean>
  13. </jaxws:server>
  14. </beans>

3、web.xml配置:
  1. <filter>
  2. <filter-name>struts2</filter-name>
  3. <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  4. </filter>
  5. <filter-mapping>
  6. <filter-name>struts2</filter-name>
  7. <url-pattern>/admin/*</url-pattern>
  8. </filter-mapping>
  9. <servlet>
  10. <servlet-name>webservice</servlet-name>
  11. <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  12. </servlet>
  13. <servlet-mapping>
  14. <servlet-name>webservice</servlet-name>
  15. <url-pattern>/ws/*</url-pattern>
  16. </servlet-mapping>

4、struts.xml配置:(namespace)
  1. <struts>
  2. <package name="default" namespace="/admin" extends="struts-default">
  3. <!-- -->
  4. <action name="waybill_*" class="waybillAction" method="{1}"></action>
  5. <!-- -->
  6. <action name="waybilldetail_*" class="waybilldetailAction" method="{1}"></action>
  7. </package>
  8. </struts>
5、代码:
接口略,@WebService
  1. public class WayBillService implements IWayBillService {
  2. private IWaybilldetailBiz waybilldetailBiz ;
  3. private IWaybillBiz waybillBiz ;
  4. public void setWaybillBiz(IWaybillBiz waybillBiz) {
  5. this.waybillBiz = waybillBiz;
  6. }
  7. public void setWaybilldetailBiz(IWaybilldetailBiz waybilldetailBiz) {
  8. this.waybilldetailBiz = waybilldetailBiz;
  9. }
  10. /**
  11. * 根据运单号获取运单详情
  12. */
  13. public List<Waybilldetail> getWayBilldetails(Long sn) {
  14. Waybilldetail t1 = new Waybilldetail();
  15. t1.setSn(sn);
  16. List<Waybilldetail> list= waybilldetailBiz.getList(t1, null, null);
  17. return list;
  18. }
  19. /**
  20. * 在线下单预约功能
  21. * state:0待发 1在途 2结束
  22. */
  23. public Long online(Long userid, String toaddress, String addressee, String tele, String info) {
  24. Waybill waybill = new Waybill();
  25. waybill.setAddressee(addressee);
  26. waybill.setInfo(info);
  27. waybill.setState("0");
  28. waybill.setTele(tele);
  29. waybill.setToaddress(toaddress);
  30. waybill.setUserid(userid);
  31. waybillBiz.add(waybill);
  32. return waybill.getSn();
  33. }


  34. }




第四节:erp中调用BOS系统

在erp的biz层把bos系统的依赖加进来

一、配置文件

CXF配置:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:jaxws="http://cxf.apache.org/jaxws"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">
  8. <bean id="waybillService" class="cn.itcast.bos.ws.WayBillService" >
  9. <property name="waybillBiz" ref="waybillBiz" ></property>
  10. <property name="waybilldetailBiz" ref="waybilldetailBiz" ></property>
  11. </bean>
  12. <jaxws:server address="waybill" >
  13. <jaxws:serviceBean>
  14. <ref bean="waybillService" />
  15. </jaxws:serviceBean>
  16. </jaxws:server>
  17. </beans>

二、erp项目的biz层调用bos逻辑

action:
  1. public void waybilldetials(){
  2. List<Waybilldetail> list = ordersBiz.waybilldetials(sn);
  3. write(JSON.toJSONString(list));
  4. }
biz:
  1. public List<Waybilldetail> waybilldetials(Long sn) {
  2. List<Waybilldetail> list = wayBillService.getWayBilldetails(sn);
  3. return list;
  4. }
注入省略

三、前端

  1. $("#waybillBtn").bind("click",function(){
  2. if($("#sn").html()==null||$("#sn").html()==""){
  3. $.messager.alert("提示","没有物流信息");
  4. }
  5. $("#waybillWindow").window("open");
  6. $("#waybillGrid").datagrid({
  7. url:\'orders_waybilldetials.action?sn=\'+$("#sn").html(),
  8. columns:[[
  9. {field:\'exedate\',title:\'日期\',width:100},
  10. {field:\'exetime\',title:\'时间\',width:100},
  11. {field:\'info\',title:\'信息\',width:100}
  12. ]],
  13. singleSelect:true
  14. })
  15. })





第五节、erp中调用在线下单预约服务

出库的逻辑里面添加在线下单功能

biz:

  1. private IWayBillService wayBillService ;
  2. public void setWayBillService(IWayBillService wayBillService) {
  3. this.wayBillService = wayBillService;
  4. }
  5. private ISupplierDao supplierDao;
  6. public void setSupplierDao(ISupplierDao supplierDao) {
  7. this.supplierDao = supplierDao;
  8. }
  9. /**
  10. * 出库逻辑
  11. * @param id
  12. * @param empuuid
  13. * @param storeuuid
  14. */
  15. public void doOutstore(Long id,Long empuuid,Long storeuuid){
  16. // 1、修改订单项状态
  17. // private java.util.Date endtime;//结束日期
  18. // private Long ender;//库管员
  19. // private Long storeuuid;//仓库编号
  20. // private String state;//状态 采购订单0未入库 1已入库 销售订单 0未出库 1已出库
  21. Orderdetail orderdetail = get(id);
  22. orderdetail.setEnder(empuuid);
  23. orderdetail.setStoreuuid(storeuuid);
  24. orderdetail.setEndtime(new Date());
  25. orderdetail.setState("1");
  26. // 2、修改库存表
  27. // 2.1 先从数据库中查询是否有此商品的记录:传的条件:仓库ID 商品ID
  28. Storedetail t1= new Storedetail();
  29. t1.setGoodsuuid(orderdetail.getGoodsuuid());
  30. t1.setStoreuuid(orderdetail.getStoreuuid());
  31. List<Storedetail> list = storedetailDao.getList(t1, null, null);
  32. // 如果有记录
  33. if (list!=null&&list.size()>0) {
  34. t1=list

    以上是关于erp10-webService的主要内容,如果未能解决你的问题,请参考以下文章

    低代码平台在ERP软件开发中的作用

    低代码平台在ERP软件开发中的作用

    低代码平台在ERP软件开发中的作用

    低代码平台在ERP软件开发中的作用

    ERP已死,“中台”已凉,“低代码”称王!

    程序人生 - ERP已死,“中台”已凉,“低代码”称王!