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