基于web的機票管理系統
如果你還沒有閱讀基于web的機票管理系統設計與實作(一),請點擊查看,獲取詳細資料請關注公眾號:C you again
5 系統詳細設計及實作
5.1 添加航班資訊
系統管理員登錄后臺系統后,點擊側邊欄的航班資訊管理按鈕會出現下拉串列選單,繼續點擊添加航班資訊按鈕可以進行添加航班資訊操作,添加航班時輸入航班號、起點、終點、始發機場、到達機場等資訊,如下圖所示,

添加航班資訊的程序如下:后臺系統管理員進入添加航班資訊頁面后,填寫航班號、起點、終點、始發機場、到達機場等相關資訊后點擊保存按鈕,這是會隨機生成flightId并與資料庫中已經存在的flightId進行比較,保證航班Id唯一,之后繼續判斷輸入的機票價格,航班座位數等資料是否有效,核對資訊的有效性和完整性,最后存入資料庫,具體流程如下圖所示,

主要代碼:
@RequestMapping("addFlight")
public Result addFlight(@RequestBody Flight flight ) {
//設定日期格式
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
// new Date()為獲取當前系統時間
flight.setFlightId("F"+df.format(new Date()));
try {
flightManageService.addFlight(flight);
return new Result(true,"添加成功");
} catch (Exception e) {
e.printStackTrace();
return new Result(false,"添加失敗");
}
}
5.2 航班資訊串列
系統管理員登錄系統后有查看航班串列的權限,航班串列界面有添加航班,洗掉航班,搜索航班資訊,航班資訊詳情,航班資訊修改等功能,具體見下圖,各個功能詳細說明如表5.1所示,


主要代碼這里以航班查詢功能service層代碼為例:
public PageResult search(int pageNum, int pageSize, String searchEntity) {
PageHelper.startPage(pageNum,pageSize);
List<Flight> flightsList=flightManageMapper.select(searchEntity);
Page<Flight> page=(Page<Flight>) flightsList;
return new PageResult(page.getTotal(), page.getResult());
}
5.3 訂單資訊串列
訂單資訊串列是訂單資訊管理模塊的一個子功能,展示的是前臺所有用戶的機票訂單資訊,如下圖所示,系統管理員可以對訂單進行查詢,洗掉操作,各個功能詳細說明如表5.2所示,


主要代碼這里以訂單洗掉功能dao層的mapper代碼為例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cafuc.mapper.IOrderManageMapper">
<delete id="delete" parameterType="String">
delete from `order` where order_id in
<foreach collection="selectIds" item="ids" open="(" close=")" separator=",">
#{ids}
</foreach>
</delete>
</mapper>
5.4 用戶資訊串列
用戶資訊串列是用戶資訊管理模塊的子功能,它是指把前臺系統所有注冊用戶資訊以串列的形式展示給后臺系統管理員,方便系統管理員精確定位到每一個機票預訂系統的使用者,對其進行管理,用戶資訊串列的界面如下圖所示,系統管理員有查找系統使用用戶和洗掉違反平臺規定用戶的權利,各個功能詳細說明如表5.3所示,


主要代碼以用戶搜索功能dao層的mapper代碼為例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cafuc.mapper.IUserManageMapper">
<select id="select" resultType="com.cafuc.pojo.User">
select DISTINCT * from `user` as u where
u.user_name like concat('%',#{searchEntity},'%')
</select>
</mapper>
5.5 留言評論串列
留言評論是前臺系統使用者完成注冊后具有的功能,用戶可以通過留言評論功能對所購班次機票進行全方位的評價,也可以對其在使用程序中遇到的問題進行反饋,等待作業員處理,后臺系統管理員對用戶留言具有管理的權限,見下圖,各功能詳情見表5.4,


主要代碼以后臺系統留言評論模塊controller層DiscussManageController.java類例:
package com.cafuc.controller;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cafuc.pojo.PageResult;
import com.cafuc.pojo.Result;
import com.cafuc.service.IDiscussManageService;
import com.cafuc.service.IOrderManageService;
@RestController
@RequestMapping("discussManage")
public class DiscussManageController {
@Resource
private IDiscussManageService discussManageService;
@RequestMapping("search")
public PageResult search(int pageNum ,int pageSize,String searchEntity){
System.out.println(pageNum+" "+pageSize+" "+searchEntity);
PageResult pageResult=discussManageService.search(pageNum, pageSize, searchEntity);
return pageResult;
}
@RequestMapping("deleteBySelectIds")
public Result deleteBySelectIds(String []selectIds) {
try {
discussManageService.deleteBySelectIds(selectIds);
return new Result(true,"洗掉成功");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return new Result(false,"洗掉失敗");
}
}
}
5.6 添加廣告資訊
廣告作為網站的必要元素,在機票系統的前臺頁面也有廣告展示的功能,后臺增加了相應的管理模塊,界面如下圖所示,

后臺系統添加廣告的步驟:管理員登錄后臺系統后點擊廣告管理按鈕,在出現的下拉串列選項中選擇添加廣告資訊并點擊進入廣告添加頁面,在頁面輸入廣告圖片、廣告鏈接,廣告說明等資訊,點擊保存按鈕,進行資料校驗,檢查資料的有效性和完整性,保證資料無誤之后將資料資訊持久化到mysql資料庫,流程圖如下圖所示,

主要代碼以后臺系統controller層ContentManageController.java類例:
@RequestMapping("addContent")
public void addContent(@RequestParam("file") MultipartFile file,HttpServletRequest request,HttpServletResponse response)
throws IOException {
String describe="";
String url="";
String picture="";
if(request.getParameter("describe")!=null) {
describe=request.getParameter("describe");
}
if(request.getParameter("url")!=null) {
url=request.getParameter("url");
}
// 判斷檔案是否為空,空則回傳失敗頁面
if (!file.isEmpty()) {
try {
// 獲取檔案存盤路徑(絕對路徑)
String path = request.getServletContext().getRealPath("/WEB-INF/file");
// 獲取原檔案名
String fileName = file.getOriginalFilename();
// 創建檔案實體
File filePath = new File(path, fileName);
// 如果檔案目錄不存在,創建目錄
if (!filePath.getParentFile().exists()) {
filePath.getParentFile().mkdirs();
System.out.println("創建目錄" + filePath);
}
picture=filePath+"";
// 寫入檔案
file.transferTo(filePath);
Content content=new Content();
//設定日期格式
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
// new Date()為獲取當前系統時間
content.setContentId("C"+df.format(new Date()));
content.setDescribe(describe);
content.setPicture(picture);
content.setUrl(url);
contentManageServiceImpl.addContent(content);
response.sendRedirect(request.getContextPath()+"/admin/list_content.html");
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect(request.getContextPath()+"/admin/add_content.html");
}
}
else {
response.sendRedirect(request.getContextPath()+"/admin/add_content.html");
}
}
5.7 廣告資訊串列
后臺系統管理員完成添加廣告以后跳轉到廣告資訊串列頁面,本頁面展示的是添加到資料庫的所有廣告資訊,如下圖所示,系統管理員可以通過查詢,洗掉等操作來管理廣告資訊,詳情見表5.5,


5.8 查看個人資訊
后臺系統管理員可以查看個人的用戶名,密碼,郵箱,手機號等資訊,由于時間有限,這里以只實作了查看用戶名,密碼的功能,見下圖所示,其他功能后期添加,

由于系統管理員在登陸系統后把個人資訊存到redis資料庫中,在頁面初始化時從redis資料庫中查找處個人資訊從到cookie中,查看個人資訊就是從cookie中提取資料并設定到頁面中,具體代碼如下:
//初始化
$scope.adminEntity={};
$scope.init=function () {
console.log($.cookie('key'));
adminManageService.init($.cookie('key')).success(function (res) {
console.log(res)
$scope.adminEntity=res;
});
}
5.9 修改個人資訊
后臺系統管理員也對用戶名,密碼,郵箱,手機號等資訊進行修改,點擊個人資訊修改按鈕進入頁面修改個人資訊,修改后點擊保存等檢查填寫的資訊無誤后提示完成修改,為了確保用戶名欄位的唯一性,用戶名一項無法修改,主要代碼以controller層為例:
@RequestMapping("editAdmin")
public Result editAdmin(@RequestBody AdminUser adminUser){
try {
adminManageServiceImpl.editAdmin(adminUser);
redisTemplate.boundValueOps(adminUser.getUser()).set(adminUser);
return new Result(true, "修改成功");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return new Result(false, "修改失敗");
}
}
5.10 用戶登錄
用戶在進行機票預定,留言評論等功能時需要登錄前臺系統后才能進行,在瀏覽器地址欄輸入http://localhost:8081/flyTicket-portal-web/default/login.html回車進入如下圖所示界面,

用戶進行到登錄界面,輸入正確的用戶名和密碼就可以登錄到前臺系統,登錄順序圖如下圖所示,

主要代碼以controller層代碼為例:
app.controller('portalLoginManageController',function($scope,$controller,portalLoginManageService){
$controller('baseController',{$scope:$scope});
//初始化
$scope.userEntity={userName:null,userPwd:null};
$scope.login=function(){
if($scope.userEntity.userName==null || $scope.userEntity.userName.trim()==""){
alert("用戶名為空");
}
else{
if($scope.userEntity.userPwd==null || $scope.userEntity.userPwd.trim()==""){
alert("密碼為空");
}
else{ portalLoginManageService.login($scope.userEntity).success(function(res){
if(res.result==false){
alert(res.message)
}
else{
window.location.href=https://www.cnblogs.com/cafuc20160512056/p/"index.html#?key="+$scope.userEntity.userName;
}
});
}
};
}
});
5.11 航班資訊展示
在瀏覽器地址欄輸入http://localhost:8081/flyTicket-portal-web/default/index.html出現如下圖所示界面,首頁面展示所有航班資訊,每一條資訊包含出發城市、到達城市、出發機場、到達機場,出發時間、到達時間、機票價格等資訊,

5.12 航班資訊查詢
用戶可以通過航班查詢功能精確查找到所需資訊,節省時間簡化操作,通過輸入航班型別、出發時間、出發城市、到達城市等搜索條件實作航班查詢,比圖以成都為到達城市為例,搜索結果如下圖所示,

代碼以dao層PortalManageMapper.xml類例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cafuc.mapper.IPortalManageMapper">
<select id="select" resultType="com.cafuc.pojo.Flight">
select * from flight as f
<where>
<if test="flightStartTime1 !=null and flightStartTime1 !=''">
and f.flight_start_time like concat('%',#{flightStartTime1},'%')
</if>
<if test="flightStartPlace !=null and flightStartPlace !=''">
and f.flight_start_place like concat('%',#{flightStartPlace},'%')
</if>
<if test="flightEndPlace !=null and flightEndPlace !=''">
and f.flight_end_place like concat('%',#{flightEndPlace},'%')
</if>
</where>
</select>
</mapper>
5.13 航班資訊詳情
航班資訊詳情是對某一航班資訊的詳細情況進行展示,如下圖所示,用戶點擊選定航班,航班詳細資訊以下拉串列的形式展現給用戶,

主要代碼如下:
//保留n位小數
$scope.weishu=function(price,n){
return new Number(price).toFixed(n);
}
//下拉詳情
$scope.lists=function(flightNumber){
//收縮狀態
if($("#F_"+flightNumber).is(":visible")){
$scope.reloadList();
}
$("#F_"+flightNumber).animate({
height:'toggle'
});
}
//判斷最低價
$scope.minPrice=function(flightHighPrice,flightMiddlePrice,flightBasePrice){
return (flightHighPrice<=flightMiddlePrice?flightHighPrice:flightMiddlePrice)<=flightBasePrice?(flightHighPrice<=flightMiddlePrice?flightHighPrice:flightMiddlePrice):flightBasePrice
}
//判斷是否有票
$scope.isKickets=function(kicketsNumber,flightNumber,temp){
/*console.log(flightNumber)*/
if(kicketsNumber>0){
$("#"+temp+"_"+flightNumber).css({
color:"green"
});
return "有票";
}
else{
$("#"+temp+"_"+flightNumber).css({
color:"red"
});
return "無票";
}
}
5.14 登錄用戶資訊展示
游客訪問前臺系統時,在頁面頭部顯示“請登錄”字樣,如下圖所示資訊,而網站用戶登錄后則顯示“您好,XXX”字樣,如下圖所示,


5.15 留言板
點擊前臺系統右上角“留言板”按鈕進入都留言頁面如下圖所示,留言評論是前臺系統使用者完成注冊后具有的功能,用戶可以通過留言評論功能對所購班次機票進行全方位的評價,也可以對其在使用程序中遇到的問題進行反饋,

主要代碼以前臺系統controller層DiscussManageController.java類例:
package com.cafuc.controller;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.collections.FastArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cafuc.pojo.Discuss;
import com.cafuc.pojo.Flight;
import com.cafuc.pojo.PageResult;
import com.cafuc.pojo.Result;
import com.cafuc.service.IDiscussManageService;
import com.cafuc.service.IPortalManageService;
@RestController
@RequestMapping("discussManage")
public class DiscussManageController {
@Resource
private IDiscussManageService discussManageService;
@RequestMapping("addDiscuss")
public Result addDiscuss(@RequestBody Discuss discuss){
try {
System.out.println(discuss);
discussManageService.addDiscuss(discuss);
return new Result(true, "評論成功");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return new Result(false, "評論失敗");
}
}
@RequestMapping("init")
public List<Discuss> init(){
return discussManageService.init();
}
}
5.16 訂單填寫
訂單填寫是機票預定中不可缺少的步驟之一,用戶找到自己所需班次后點擊訂票按鈕進入訂單資訊填寫頁面,用戶所填寫的資訊包括乘機人資訊和聯系人資訊量大模塊,如下圖所示,填寫完資訊后點擊提交訂單按鈕,等待驗證資料的有效性,確定填寫無誤后完成提交,填寫訂單的前提是用戶已經登錄系統,

5.17 訂單詳情
填寫訂單資訊完成訂單提交后彈出訂單詳情頁面提示用戶檢查航班資訊和填寫的用戶資訊,如下圖所示,確保資訊無誤后點擊確認付款按鈕跳轉到訂單支付頁面,

訂單確認功能主要代碼如下:
@RequestMapping("/ack")
public void ack(Order order,HttpServletRequest request,HttpServletResponse response) throws IOException {
try {
if(order.getOrderDate() ==null) {
order.setOrderDate(new Date());
}
HttpSession httpSession=request.getSession();
httpSession.setAttribute("order", order);
System.out.println(request.getSession().getAttribute("order"));
response.sendRedirect(request.getContextPath()+"/pay/index.jsp");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
5.18 訂單支付
機票預訂系統的訂單支付功能使用的是支付寶沙箱環境支付,螞蟻沙箱環境 (Beta) 是協助開發者進行介面功能開發及主要功能聯調的輔助環境,登錄支付寶沙箱平臺依次完成生成買家和賣家賬號資訊、生成RSA秘鑰、設定公鑰資訊、設定應用網關等應用環境配置,完成配置后下載官方測驗代碼,本系統選擇的是電腦應用java版本,然后將下載的專案匯入到eclipse作業空間,最后設定核心組態檔資訊,打開flyTicket-portal-web專案下com.alipay.config包中的AlipayConfig.java檔案配置如下資訊:
//沙箱APPID
public static final String app_id = "這里需要自己申請";
//沙箱私鑰
public static final String merchant_private_key = "這里需要自己申請";
//支付寶公鑰
public static final String alipay_public_key = "這里需要自己申請";
//沙箱網關地址
public static final String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";
//服務器異步通知頁面路徑 需http://格式的完整路徑,不能加?id=123這類自定義引數,必須外網可以正常訪問
public static String notify_url = "http://localhost:8081/flyTicket-portal-web/pay/notify_url.jsp";
//頁面跳轉同步通知頁面路徑 需http://格式的完整路徑,不能加?id=123這類自定義引數,必須外網可以正常訪問
public static String return_url = "http://localhost:8081/flyTicket-portal-web/orderManage/complete";
完成以上配置后就可以實作訂單支付功能了,點擊確認付款后跳轉到如下圖所示界面,

點擊付款按鈕后如下圖所示,可以登錄賬戶付款,也可以使用手機端沙箱支付寶完成付款,

完成付款后如下圖所示

主要代碼如下:
//支付完成后
@RequestMapping("complete")
public void complete(HttpServletRequest request,HttpServletResponse response) throws IOException {
System.out.println(request.getSession().getAttribute("order"));
Order order=(Order)request.getSession().getAttribute("order");
try {
//將資料插入到訂單表中
orderManageService.insertOrder(order);
//更改庫存
Flight flight=orderManageService.findOneByFlightNumber(order.getFlightNumber());
if(order.getGrade().equals("f")) {
flight.setFlightHighNumber(flight.getFlightHighNumber()-1);
}
else if(order.getGrade().equals("b")) {
flight.setFlightMiddleNumber(flight.getFlightMiddleNumber()-1);
}
else {
flight.setFlightBaseNumber(flight.getFlightBaseNumber()-1);
}
orderManageService.updatesNum(flight);
} catch (Exception e) {
e.printStackTrace();
}
response.sendRedirect(request.getContextPath()+"/default/index.html");
}
獲取原始碼請關注公眾號:C you again,回復“基于web的機票管理系統”或者“機票管理系統”

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/6648.html
標籤:其他
