logistics-6-decidedZone management
2019獨角獸企業重金招聘Python工程師標準>>>
業務:
1.decidedZone management_添加decidedZone
2.decidedZone management_定區數據分頁多條件查詢
3.decidedZone關聯客戶功能實現
技術點:
遠程訪問技術:webservice、hessian
decidedZone:并非實際存在,只是業務上存在。一個派送人員可以管理多個分區,這多個分區就組成一個定區。
客戶會關聯定區,為業務受理、自動分單功能服務。
05:【Hessian遠程訪問技術入門】
該物流系統需要與CRM系統進行通訊,所以要用到遠程訪問技術常用的遠程訪問技術:
█RMI
? ?RMI是?Java?首選遠程調用協議,非常高效穩定,特別是在數據結構復雜,數據量大的情況下,與其他通訊協議的差距尤為明顯。但不能跨語言。
█HttpInvoker
? ?HttpInvoker使用?java?的序列化技術傳輸對象,與?RMI?在本質上是一致的。從效率上看,兩者也相差無幾,?HttpInvoker?與?RMI?的傳輸時間基本持平。
█Hessian
? ?Hessian在傳輸少量對象時,比RMI?還要快速高效,但傳輸數據結構復雜的對象或大量數據對象時,較?RMI?要慢?20%?左右。但這只是在數據量特別大,數據結構很復雜的情況下才能體現出來,中等或少量數據時,Hessian并不比RMI慢。?Hessian?的好處是精簡高效,可以跨語言使用,而且協議規范公開。?
█Burlap
? ?采用?xml?格式傳輸。僅在傳輸?1?條數據時速度尚可,通常情況下,它的耗時是?RMI?的?3?倍。
█?Web?Service
? ?效率低下是眾所周知的,平均來看,?Web?Service?的通訊耗時是?RMI?的?10?倍。?
webService參考博客:點擊打開鏈接
通訊效率測試結果:
?????RMI?>?Httpinvoker?>=?Hessian?>>?Burlap?>>?Web?service
這里使用Hessian實現。
理由:1.可以跨平臺
? ? ? ? ? ? 2.效率比WebService高很多
hessian官網:點擊打開鏈接
1.導入hessian.jar包
2.新建Dynamic web project工程
? 注意:一定要指定target runtime,如果不指定會沒有servlet API支持。
? 2.5-----javaEE5(Apache Tomcat v6.0) ?
? 3.0-----javaEE6(Apache Tomcat v7.0)
3.編寫hessian的服務端(接口和實現)
首先,提供服務接口
public class HelloServiceImpl implements HelloService {@Overridepublic String sayHello(String name) {return "hello," + name;} } 最后,將接口發布為Hessian?web?服務
<servlet><servlet-name>hello</servlet-name> <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class><init-param><!-- Hessian服務 實現類 --><param-name>home-class</param-name><param-value>cn.itcast.service.impl.HelloServiceImpl</param-value></init-param><init-param><!-- Hessian 服務業務接口 --><param-name>home-api</param-name><param-value>cn.itcast.service.HelloService</param-value></init-param></servlet><servlet-mapping><servlet-name>hello</servlet-name><url-pattern>/hello</url-pattern> </servlet-mapping>
通過瀏覽器即可訪問是否發布成功
4.編寫hessian客戶端
Hessian 客戶端如果是相同語言開發,最簡單方式,直接將服務器接口復制到客戶端 。
如果不是相同語言, 客戶端獲得一個Map對象?
06:【編寫CRM提供CustomerService業務接口】
( CRM寫的有點亂,也不完整,待完善) 說明:1.使用ssh框架開發的
2.使用自動建表。hibernate.cfg.xml文件配置如下:
4.封裝了sessionFactoryUtils工具類,直接運行其中的main方法就進行建表了。
public class HibernateUtils {private static Configuration configuration;private static SessionFactory sessionFactory;static {configuration = new Configuration().configure();sessionFactory = configuration.buildSessionFactory();}public static Session openSession() {return sessionFactory.openSession();}public static void main(String[] args) {openSession();} }
CRM系統的實現
這里假設遠程的CRM系統使用ssh實現。
CRM導入了一個javassist包:用來給hibernate做代理用(??????)
注意:schema和catalog的含義。
calatog表示的是數據庫,針對mysql(mysql的表在數據庫下),schema的是名稱空間,針對oracle(oracle的表在命名空間下)。
參考:oracle的表空間概念
如果在這里不指定schema,則會在默認空間建表,會報如下的錯誤提示。
所以應該指定schema。
假設CRM系統的功能已經都實現。
現在要做的僅僅是提供供外部訪問的接口。( 疑問:具體開發中到底是開發過程中就已經將接口提供好,還是最后再單獨考慮接口問題?)
具體的步驟:
1.提供接口 在CRM系統中,提供一個service接口。
public class CustomerServiceImpl implements CustomerService {public List<Customer> findNoAssociationCustomers() {Session session = HibernateUtils.openSession();Transaction transaction = session.beginTransaction();List<Customer> list = session.createQuery("from Customer where decidedZoneId is null").list();transaction.commit();session.close();return list;}public List<Customer> findHasAssociationCustomers(String decidedZoneId) {Session session = HibernateUtils.openSession();Transaction transaction = session.beginTransaction();List<Customer> list = session.createQuery("from Customer where decidedZoneId = ?").setParameter(0, decidedZoneId).list();transaction.commit();session.close();return list;}public void assignCustomersToDecidedZone(String[] customerIds, String decidedZoneId) {Session session = HibernateUtils.openSession();Transaction transaction = session.beginTransaction();if (customerIds != null) {for (String id : customerIds) {Customer customer = (Customer) session.get(Customer.class, id);customer.setDecidedZoneId(decidedZoneId);}}transaction.commit();session.close();} } 2.提供接口的實現類。
public class CustomerServiceImpl implements CustomerService {public List<Customer> findNoAssociationCustomers() {Session session = HibernateUtils.openSession();Transaction transaction = session.beginTransaction();List<Customer> list = session.createQuery("from Customer where decidedZoneId is null").list();transaction.commit();session.close();return list;}public List<Customer> findHasAssociationCustomers(String decidedZoneId) {Session session = HibernateUtils.openSession();Transaction transaction = session.beginTransaction();List<Customer> list = session.createQuery("from Customer where decidedZoneId = ?").setParameter(0, decidedZoneId).list();transaction.commit();session.close();return list;}public void assignCustomersToDecidedZone(String[] customerIds, String decidedZoneId) {Session session = HibernateUtils.openSession();Transaction transaction = session.beginTransaction();if (customerIds != null) {for (String id : customerIds) {Customer customer = (Customer) session.get(Customer.class, id);customer.setDecidedZoneId(decidedZoneId);}}transaction.commit();session.close();} } 3.發布為hessian? 服務。
在web.xml中配置servlet,發布服務。
<servlet><servlet-name>customerService</servlet-name><servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class><init-param><!-- Hessian服務 實現類 --><param-name>home-class</param-name><param-value>cn.itcast.crm.service.impl.CustomerServiceImpl</param-value></init-param><init-param><!-- Hessian 服務業務接口 --><param-name>home-api</param-name><param-value>cn.itcast.crm.service.CustomerService</param-value></init-param></servlet><servlet-mapping><servlet-name>customerService</servlet-name><url-pattern>/customerService</url-pattern></servlet-mapping>這樣,我們就已經發布好了。接下來就可以運行CRM系統了。
我們同樣使用maven的tomcat插件來啟動。
使用命令:tomcat:run
注意:CRM和物流系統都使用tomcat:run啟動,是否會端口沖突呢?
當然不會,因為我們配置的CRM啟動使用的是9090端口。而物流系統使用的是tomcat的80端口。
最后,測試一下服務是否發布成功。
07:【編寫BOS客戶端基于junit遠程接口調試】
對方寫一個接口,我們寫客戶端調用時,先不寫測試程序將系統調通,再進行開發,這樣避免直接使用時出現問題。注意:?接口基于Hessian?傳輸對象,必須實現Serializable?接口,以實現網絡傳輸。
測試之前先檢測一下是否遺忘了這一點。?
最簡單的做法就是直接將服務接口拷貝到客戶端。
除了拷貝CustomerService,還要拷貝它所依賴的Customer實體類。( 注意:這里并沒有拷貝服務實現類)
同時拷貝以上兩個,才能保持一致,不一致的話,會將對象解析為一個map( ?不太懂?)
然后,在客戶端可以使用 ?HessianProxyFactory? 對接口創建代理。(見官網:點擊打開鏈接)
當然我們通常會 使用spring整合hessian。
參考spring的specification(part IV:integration部分,chapter 17)
參考本地文檔:spring jar包的docs文件夾下的pdf
參考在線文檔:
見官網: 點擊打開鏈接
applicationContext.xml?配置hessian接口代理?客戶端
接下來,進行接口調試。
測試代碼
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:applicationContext.xml") public class CustomerServiceTest {@Autowiredprivate CustomerService customerService;@Testpublic void testFindNoAssociationCustomers() {List<Customer> customers = customerService.findNoAssociationCustomers();System.out.println(customers);}@Testpublic void testFindHasAssociationCustomers() {List<Customer> customers = customerService.findHasAssociationCustomers("DQ001");System.out.println(customers);}@Testpublic void testAssignCustomersToDecidedZone() {customerService.assignCustomersToDecidedZone(new String[] { "1" }, "DQ002");} }測試結果
1.測試 testFindNoAssociationCustomers()
在數據庫中手動插入幾條模擬數據
控制臺打印結果:
[Customer [id=2, name=李四, telephone=23456, address=北京朝陽, decidedZoneId=null]]
說明測試通過
2.測試testFindHasAssociationCustomers()
插入一條有定區的模擬數據(即定區已經關聯了客戶)
控制臺打印結果:
[Customer [id=3, name=王五, telephone=55555, address=上海浦東, decidedZoneId=DQ001]]
說明測試通過。
3.測試testAssignCustomersToDecidedZone()
測試的是:對未關聯定區的張三用戶進行關聯定區DQ002.
測試結果:關聯成功
說明測試通過。
以上三個方法都測試成功,說明接口已經調試通過。
接下來就可以實現物流系統的定區關聯客戶功能了。
08:【定區關聯客戶功能實現】
關聯客戶按鈕響應事件 選中第一行數據,點擊關聯客戶,則出現關聯客戶窗口
左側列表顯示未關聯客戶列表,右側列表顯示已關聯選中定區客戶列表?
從圖中可以看到定區DQ001已與客戶王五關聯,而位于李四關聯。
當然這些列表數據是在點擊最上面的關聯客戶列表后,進行查詢數據庫后顯示出來的。
點擊響應事件代碼:
function doAssociations(){// 獲得選中數據行 var row = $('#grid').datagrid('getSelected');if(row == null){// 沒有選中$.messager.alert('警告','關聯客戶前,必須選中一條定區數據 ','warning');return}$('#noassociationSelect').html('');$('#associationSelect').html('');// 加載 窗口中兩個select 列表數據// 查詢未關聯$.post("${pageContext.request.contextPath}/decidedzone_findnoassociationCustomers.do" , function(data){$(data).each(function(){var option = $("<option value='"+this.id+"'>"+this.name+"("+this.address+")</option>");$('#noassociationSelect').append(option);});});// 查詢已經關聯$.post("${pageContext.request.contextPath}/decidedzone_findhasassociationCustomers.do" , {id: row.id},function(data){$(data).each(function(){var option = $("<option value='"+this.id+"'>"+this.name+"("+this.address+")</option>");$('#associationSelect').append(option);});});$('#customerWindow').window('open'); }
列表左右移動功能實現
// 左右移動 $('#toRight').click(function(){$('#associationSelect').append($('#noassociationSelect option:selected')); }); $('#toLeft').click(function(){$('#noassociationSelect').append($('#associationSelect option:selected')); });
關聯客戶
現在我們想把李四也與定區DQ001進行關聯。
選中李四,然后將其添加到右側的已關聯列表中。點擊關聯客戶按鈕(下方)后,提交表單,通過在數據庫將李四與定區DQ001關聯。
數據庫中結果:
顯然,關聯成功了。定區與客戶關聯的功能也就實現了。
轉載于:https://my.oschina.net/javandroid/blog/878208
總結
以上是生活随笔為你收集整理的logistics-6-decidedZone management的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: css撑起父元素清除浮动的问题
- 下一篇: Qtopia-2.2.0 的配置和交叉编