汽車租賃項目業務流程總結
阿新 • • 發佈:2017-09-22
java
-一、需求分析
-二、
-一、需求分析與數據表設計
需求圖:
發現類:
01.moto類(汽車父類):
01.1:bus類(客車類)
01.2:car類(轎車類)
01.3:truck類(卡車類)
02.mototype類(汽車類型類)
03.用戶類:軟件系統的使用者,登錄該系統 管理的 人,比如:管理員、業務經理等。
04.客戶類:租車的人。
05.公司類:用於處理租車換車業務流程的人。
-二、設計概要設計
數據庫設計:
-三、詳細設計
實現各車的信息錄入
一個問題:卡車跟大巴和轎車錄入是不一樣的,所以在業務層需要判斷是什麽車型,但這樣代碼比較臃腫,不利於擴展,不是面向對象編程。
解決:采用面向對象的特點(繼承和多態),在moto類建立錄入車信息的方法,這樣轎車客車大巴繼承moto類就可以有自己的錄入車信息的方法。
代碼演示:
moto類:
public abstract class Moto { private String mno; //車牌號 private int seatCount; private MotoType mtype; //這裏省略get\set方法 public Moto(MotoType mtype,String mno,int seatCount){ this.mno = mno; this.seatCount = seatCount; this.mtype = mtype; } /** * 把當前對象存儲到數據庫中 * @throws Exception */ public void saveDB() throws Exception{ CompanyDao dao = new CompanyDao(); try { dao.addMoto(this); } catch (Exception e) { e.printStackTrace(); }finally{ dao.closeConnection(); } } }
car類:可以直接使用moto類中的方法
public class Car extends Moto{ public Car(MotoType mtype,String mno) { super(mtype,mno, 5); } }
truck類:重寫了moto類的saveDB()方法
public class Truck extends Moto{ private int dun; private double priceEachDun; //每噸每天的單價 public int getDun() { return dun; } public double getPriceEachDun() { return priceEachDun; } public void setPriceEachDun(double priceEachDun) { this.priceEachDun = priceEachDun; } public Truck(MotoType mtype, String mno, int seatCount,int dun) { super(mtype, mno, seatCount); this.dun = dun; } public double getDayMoney() { return priceEachDun*dun; } /** * 把當前對象存儲到數據庫中 ----------重寫 * @throws Exception */ @Override public void saveDB() throws Exception{ CompanyDao dao = new CompanyDao(); try { dao.beginTransaction(); dao.addMoto(this); TruckEntity truckEntity = new TruckEntity(); truckEntity.setMno(this.getMno()); truckEntity.setDun(dun); truckEntity.setPriceEachDun(priceEachDun); dao.addTruck(truckEntity); dao.commit(); } catch (Exception e) { e.printStackTrace(); dao.rollback(); throw e; }finally{ dao.closeConnection(); } } }
在業務邏輯層方法就很簡單了:
private List<Moto> motos; /** * 添加汽車 * @param moto * @throws Exception */ public void addMoto(Moto moto) throws Exception{ if(moto != null ){ moto.saveDB(); //OO多態 motos.add(moto); }else{ throw new Exception("入參moto錯誤"); } }
2.實現租車業務
圖解:
註意:由於整個租車過程包含多個表的修改,比如加入兩個訂單在差不多時間操作同一輛車,肯定會有一個訂單有問題,這是就需要保證事務的一致性和完整性。
在業務邏輯層的代碼就可以:
public class RentCompany { private String name; private List<Moto> motos; //待租賃的汽車 public String getName() { return name; } public List<Moto> getMotos() { return motos; } public RentCompany(String name){ this.name = name; motos = new ArrayList<Moto>(50); } /** * 汽車租賃 * @param motos * @param client * @param rentinfo * @return 租賃成功,返回訂單號 * @throws Exception */ public String rent(List<Moto> motos,TClient client,TRentInfo rentinfo) throws Exception{ String rentno = null; if(motos != null && client != null && rentinfo!= null){ CompanyDao dao = new CompanyDao(); try { dao.beginTransaction(); //開啟事務 //添加客戶數據 dao.addTClient(client); //添加汽車租賃信息 rentno = dao.addRentInfo(rentinfo); //添加租賃明細 for(Moto moto : motos){ TRentDetail rentDetail = getTRentDetail(rentno,moto); dao.addRentDetail(rentDetail); } dao.commit(); //提交事務 } catch (Exception e) { dao.rollback(); //回滾事務 rentno = null; throw e; }finally{ dao.closeConnection(); } }else{ throw new Exception("入參錯誤,請檢查"); } return rentno; } private TRentDetail getTRentDetail(String rentno,Moto moto){ TRentDetail detail = new TRentDetail(); detail.setMno(moto.getMno()); detail.setRentno(rentno); detail.setDaymoney(moto.getDayMoney()); return detail; } }
3.實現還車業務
本文出自 “秦斌的博客” 博客,請務必保留此出處http://qinbin.blog.51cto.com/11773640/1967828
汽車租賃項目業務流程總結