智能停——基於雲計算的停車服務平臺

目 錄
1.系統功能概述 3
2.系統設計 3
2.1系統總體架構 3
2.2收費規則設計 5
2.3核心功能模塊 1
3.系統功能操作說明 1
3.1用戶操作 1
3.1.1 登錄 1
3.1.2 註冊 3
3.1.3 忘記密碼 4
3.2停車場管理員 6
3.2.1 首頁 6
3.2.2 停車場管理 8
3.2.3 設備管理 19
3.2.4 車輛管理 21
3.2.5 報表管理 23
3.2.6 公告發布 29
3.3系統管理員 31
3.3.1 首頁 31
3.3.2 停車場管理 32
3.3.3 統計分析 33
3.3.4 用戶數據 43
4.源代碼 46
4.1服務端 46
Service實現層 213
POJO類 297
Fare收費規則模塊 396
Constant常量 430
Utils工具類 434
程序入口 488
Mapper層 491
Mapper Xml編寫 512
配置文件 614
config 框架配置 619
conf 項目配置 634
項目依賴 638
4.2客戶端 642
4.2.1 用戶界面UI 642
4.2.2 組件 651
4.2.3 頁面 668
4.2.4 路由配置 668
4.2.5項目總配置 674
4.2.6項目入口文件 677

1.系統概述
利用物聯網、移動互聯網通信技術和雲計算技術,建設一體化的停車服務平臺,實現的主要功能包括:通過掃車牌,實現車輛的自動入場、計(時)費,以及自動收費和出場功能,全程.實現停車場的無人值守,降低運營成本;藉助雲端服務,通過集中託管各停車場的位置、停車位數量等信息,並實時採集各停車場的可用停車位的數量等信息,爲移動終端用戶實時查詢並推薦可用的停車位,且基於位置服務,爲移動終端用戶導航到所預約或預定停車位所在的停車場,這在一定程度上緩解停車難的問題;基於大數據分析,統計併發布區域內各個停車場的使用狀況,含使用效率、繁忙時段等信息,移動終端用戶可根據查詢到的停車場使用狀況,有助於滿足其合理出行的需要,以及引導停車場的配套建設和規劃的有效性。

2.系統設計
2.1系統總體架構
系統架構如圖2-1所示,主要分爲三層,分別爲:客戶層、應用層、數據層。
圖2-1 系統結構圖
(1)客戶層
主要實現協議爲HTTP和Socket,HTTP是實現App與服務器的交互,Socket主要是實現傳輸芯片(硬件端)與服務器的實時交互。
(2)應用層
會話層:主要用Nginx來進行路由控制以及轉發服務:主要是置於TOMCAT中得java程序提供的RestApi和WebService。
業務邏輯:主要由Java編寫的邏輯代碼,包括數據查詢,報表管理,數據監聽,收費規則管理等其他的一些公共的邏輯。
(3)數據層
數據訪問:主要是利用Spring jdbc/Redis來進行數據訪問。
數據存儲:Redis緩存+Mysql存儲,Redis主要是存放停車場實時更新的數據信息。Mysql主要存儲,實時性不太強的信息。

應用層執行架構:
服務器操作系統爲Centos6.2,
Nginx:負載均衡,路由分發。
Tomcat:運行Java後臺服務程序
數據執行架構:
服務器操作系統爲Centos6.2,以及Redis緩存,Mysql數據庫。

2.2收費規則設計
利用停車場現有設備(攝像頭),獲取到車輛信息進行處理,對車輛進行自動識別,識別到車輛信息和停車動作後,調用雲端服務功能,驗證該車輛訂單,完成自動扣費,收費系統架構圖如圖2-2所示。
圖2-2 收費系統架構圖

扣費的方式:支付寶、微信、銀行卡均可。(根據默認扣費方式自動收費)
時長收費規則:按照停車時間長度收費。
前N小時收費:該規則包含免費收費段(免費段),和優惠收費段,停車場可自定義該兩端的收費段,可以通過調節收費段只需要“免費段”,“優惠段”
階梯收費段:停車場可在該段細粒度定義時間間隔及間隔的收費標準
超過階梯收費區域:用戶的停車時間超過階梯收費規則可按該段收費規則收費

時制收費規則:
對於每天可以劃分不同時間段進行收費,大致分爲“凌晨”,“早上”,“中午”,“下午”,“傍晚”,“深夜”,停車場可根據需要,在各個時段指定收費規則
收費規則折扣指定:各個階段的收費規則都可以定義,“折扣”,“額定優惠”,“單元收費”,“階段最大收費”,幾個指標來組合制定出“活動價”,“高峯期時段價”,等等
額定優惠:指一次性優惠一定的金額。
單元收費:指定計費單元,N元/U小時中U的大小。
階段最大收費:指定階梯收費階段中最多的費用。

停車場可以綜合上述收費標準,可以制定出滿足各自需求的收費標準,特別是在不同的時段(“高峯期”,“低潮區”,“正常區”),以及推出各種活動(“活動價”)等上打造更方便,靈活,快速,高效的收費系統。

2.3核心功能模塊
主要由停車場用戶模塊和網站管理模塊
停車場管理員:主要由停車場信息管理,收費管理,報表管理
系統管理員:主要管理停車場和用戶信息已經對停車場應用的授權管理

3.系統功能操作說明
3.1用戶操作
3.1.1 登錄
用戶進入系統登錄頁面,用戶輸入用戶名以及登錄密碼,選取自己的用戶類型(系統默認爲停車場管理員),用戶正確填寫信息後登錄進系統。
其它功能:
1、自動登錄:用戶勾選自動登錄則允許網頁記住密碼,下次登錄可填寫用戶名直接登錄。
2、立即註冊:用戶若無賬戶信息可選擇立即註冊功能,註冊新賬號。
3、忘記密碼:若忘記密碼可選擇忘記密碼功能,找回密碼。
登錄界面如圖2-1所示。

圖2-1 登錄系統
選取用戶類型如圖2-2所示。

圖2-2用戶類型選取

在登錄填寫信息時未正確輸入相關信息,會有相關提示。如圖2-3所示。

圖2-3 登錄界面
3.1.2 註冊
停車場管理員用戶進入系統註冊頁面,用戶輸入用戶名、手機號,登錄密碼、再次確認的密碼、短信驗證碼(用戶輸入手機號後點擊發送按鈕可獲取短信驗證碼),用戶正確填寫所有信息後在本系統註冊新帳號。
其它功能:
1、記住密碼:用戶勾選記住密碼則允許網頁記住密碼,下次登錄可填寫用戶名直接登錄。
2、直接登錄:用戶切換到登錄界面登錄帳號。
3、忘記密碼:若忘記密碼可選擇忘記密碼功能,找回密碼。
註冊界面如圖2-4所示。

圖2-4 註冊界面
在註冊填寫信息時未正確輸入相關信息,會有相關提示。如圖2-5所示。

圖2-5 註冊界面
3.1.3 忘記密碼
停車場管理員用戶進入密碼重置頁面,用戶輸入手機號,新密碼、再次確認的密碼、短信驗證碼(用戶輸入手機號後點擊發送按鈕可獲取短信驗證碼),用戶正確填寫所有信息後在本系統註冊新帳號。
其它功能:
1、立即註冊:用戶若無賬戶信息可選擇立即註冊功能,註冊新賬號。
2、自動登錄:用戶勾選自動登錄則允許網頁記住密碼,下次登錄可填寫用戶名直接登錄。
3、立即登錄:用戶切換到登錄界面登錄帳號。
密碼重置頁面如圖2-6所示。

圖2-6 密碼重置界面
在重置密碼填寫信息時未正確輸入相關信息,會有相關提示。如圖2-7所示。

圖2-7 密碼重置界面

3.2停車場管理員
3.2.1 首頁
停車場管理員進入系統首頁,首頁導航功能包括:
1、帳號信息顯示與操作
1)帳號名稱:查看賬戶信息
2)安全設置:設置帳號相關信息
3)退出帳號:退出當前登錄
2、停車場:切換到管理停車場界面
3、設備管理:管理停車場車位
4、車輛管理:管理停車場來往車輛
5、報表管理:查看停車場相關數據報表
6、公告發布:發佈相關停車場公告
7、導航條:顯示當前所在頁面
停車場管理員操作首頁如圖2-8所示。

圖2-8 停車場管理員操作首頁
帳號服務如圖2-9所示。

圖2-9 帳號服務
導航條如圖2-10所示。

圖2-10 導航條
3.2.2 停車場管理
3.2.2.1 新增停車場
停車場管理員選中新增停車場,即->“新增停車場”,可增加所管理的停車場。
需要輸入的信息有停車場名稱、所在區域、詳細地址、停車場營業執照、停車位、停車場類型、停車場負責人、經營人的身份證號以及關於停車場的簡單描述。如圖2-11所示。

圖2-11 新增停車場

用戶選擇停車場所在區域,如圖2-12所示。

圖2-12 選擇所在區域

用戶上傳營業執照,如圖2-13、圖2-14所示。

圖2-13 上傳營業執照

圖2-14 上傳營業執照

正確填寫相關信息後添加停車場成功。如圖2-15所示。

圖2-15 添加成功
3.2.2.2 查看停車場信息
停車場管理員選中停車場信息,即->“停車場信息”,可查看所管理的停車場的相關信息。
停車場管理員帳號下並未有停車場信息時,點擊添加停車場可切換至添加停車場信息頁面。停車場信息界面如圖2-16所示。

圖2-16 停車場信息

停車場管理員賬號下已存有停車場信息時,可查看到所管理的停車場編號、停車場名稱、所在地址、計價方式、停車位、停車場類型、停車場負責人、經營人身份證號和停車場簡述。
點擊編輯按鈕可編輯該停車場信息,點擊刪除按鈕可刪除該條停車場信息。
停車場界面信息如圖2-17所示。

圖2-17 停車場信息

用戶選擇編輯停車場信息功能,修改已存在停車場信息。
可修改的信息包括停車場名稱、停車場地址、詳細地址、停車位、停車場類型、停車場負責人、經營人的身份證號以及關於停車場的簡單描述。修改完成且信息無誤後點擊確認按鈕則保存新信息,點擊取消則放棄編輯停車場信息。
編輯停車場信息界面如圖2-18所示。

圖2-18 編輯停車場信息

用戶選擇刪除停車場信息功能,刪除已存在停車場信息。
選擇刪除停車場信息,系統會再次確認,若確定則繼續刪除,若放棄則關閉頁面。如圖2-19所示。

圖2-19 是否刪除停車場

選擇確認刪除停車場信息,刪除停車場成功,如圖2-20所示。

圖2-20 成功刪除停車場信息
3.2.2.3 停車場收費
停車場管理員選中收費標準,即->“收費標準”,可設置所管理的停車場的收費規則。
停車場管理員需要輸入:
1、停車場編號
2、用戶類型
3、收費類型(選擇用戶類型後出現對應的收費類型)
4、收費細則(選擇收費類型後出現對應的收費細則)
5、收費折扣(選擇收費類型後出現收費折扣輸入框)
收費初始界面如圖2-21所示。

圖2-21 收費

停車場管理員需要對不同用戶類型設置相應的收費規則,選擇用戶類型,可選擇的用戶類型有臨時用戶、期卡用戶、充值卡用戶。界面如圖2-22所示。

圖2-22 選擇卡用戶類型

1)臨時用戶
停車場管理員選擇爲臨時用戶設置規則,即->“臨時用戶”,可設置的規則有按階段收費、按時收費、按天收費。如圖2-23所示。

圖2-23 臨時卡收費類型

停車場管理員選擇設置按階段收費,即->“按階段收費”,停車場管理員填寫收費細則,填寫時間段、該時間段對應的收費。點擊“+”按鈕後添加下一階段,默認下一階段起始時間爲上一階段結束的時間。如圖2-24 圖2-25所示。

圖2-24 臨時卡按階段收費

圖2-25 臨時卡按階段收費

停車場管理員選擇設置按時收費,即->“按時收費”,停車場管理員填寫收費細則,輸入按時收費的收費價格。如圖2-26所示。

圖2-26 臨時卡按時收費

停車場管理員選擇設置按天收費,即->“按天收費”,停車場管理員填寫收費細則,輸入按天收費的收費價格。如圖2-27所示。

圖2-27 臨時卡按天收費
2)期卡用戶
停車場管理員選擇爲期卡用戶設置規則,即->“期卡用戶”,可設置的規則有按月收費、按季收費、按年收費。如圖2-28所示。

圖2-28 期卡收費類型

停車場管理員選擇設置按月收費,即->“按月收費”,停車場管理員填寫收費細則,輸入按月收費的收費價格。如圖2-29所示。

圖2-29 期卡按月收費

停車場管理員選擇設置按季收費,即->“按季收費”,停車場管理員填寫收費細則,輸入按季收費的收費價格。如圖2-30所示。

圖2-30 期卡按季收費

停車場管理員選擇設置按年收費,即->“按年收費”,停車場管理員填寫收費細則,輸入按年收費的收費價格。如圖2-31所示。

圖2-31 期卡按年收費
3)充值卡用戶
停車場管理員選擇爲充值卡用戶設置規則,即->“充值卡用戶”,填寫用戶收費細則。如圖2-32所示。

圖3-32 充值卡收費

3.2.3 設備管理
3.2.3.1 車位狀態管理
停車場管理員選中停車場信息,即->“車位狀態管理”,可查看所管理的停車場的相關設備信息。包括停車場的總車位數、剩餘車位數、預訂車位數、車位狀態以及停車場內每個車位的實時情況。
車位實時情況包括車位所屬片區、片區號、泊位號、泊位狀態、所在車輛的車牌號(若無車輛則不現實)、預訂的車牌號(若無預訂則不顯示)。
其它功能:
1、輸入內容可檢索停車場指定車位信息。
2、選擇表格操作欄編輯選項對該條車位信息進行編輯。
3、選擇表格操作欄移除選項對該條車位信息進行移除。
停車場信息界面如圖2-33所示。

圖2-33 停車場設備信息

停車場車位信息界面如圖2-34所示。

圖2-34 停車場車位信息界面

選擇藍色編輯按鈕,可批量管理車位信息。如圖2-35所示。

圖2-35 批量管理
3.2.3.2 泊車流水
停車場管理員選中泊車流水,即->“泊車流水”,可查看所管理的停車場的泊車流水信息。泊車流水信息包括該流水的所屬片區、片區號、泊位號、泊位狀態、變化時間、是否預訂、相關車牌號、進/出/預訂情況。
其它功能:
1、表格底操作區域可選擇每頁信息條數、前往指定頁面。
2、輸入內容可檢索停車場指定車位信息。
3、選擇表格操作欄編輯選項對該條泊車流水信息進行編輯。
4、選擇表格操作欄移除選項對該條泊車流水信息進行移除。
停車場泊車流水如圖2-36所示。

圖2-36 泊車流水

3.2.4 車輛管理
3.2.4.1 會員車輛
停車場管理員選中會員車輛,即->“會員車輛”,可查看所管理的停車場的會員車輛信息。會員車輛信息包括車輛的車牌號、車輛品牌、所屬帳號、所屬人姓名、所屬人身份證號、添加時間、停放次數。
其它功能:
1、表格底操作區域可選擇每頁信息條數、前往指定頁面。
2、輸入內容可檢索停車場指定車位信息。
3、選擇表格操作欄拉黑選項拉黑該車。
4、選擇表格操作欄編輯選項對該條信息進行編輯。
5、選擇表格操作欄移除選項對該條信息進行移除。
會員車輛信息界面如圖2-37所示。

圖2-37 停車場會員車輛
3.2.4.2 黑名單
停車場管理員選中黑名單,即->“黑名單”,可查看所管理的停車場的黑名單車輛信息。黑名單車輛信息包括車輛的車牌號、欠費金額、欠費時間、欠費次數。
其它功能:
1、表格底操作區域可選擇每頁信息條數、前往指定頁面。
2、輸入內容可檢索停車場指定車位信息。
3、選擇表格操作欄查看選項查看具體信息。
4、選擇表格操作欄編輯選項對該條信息進行編輯。
5、選擇表格操作欄移除選項對該條信息進行移除。
黑名單車輛信息界面如圖2-38所示。

圖2-38 停車場黑名單
3.2.5 報表管理
3.2.5.1 泊車報表
停車場管理員選中泊車報表,即->“泊車報表”,查看所管理的停車場指定時間內的泊車信息報表(默認時間爲一週),可查看的報表如下:
1、停車場的泊車次走勢圖。
2、停車場的泊車評價分析圖。
3、停車場的泊車訪客類型佔比圖。
4、停車場的累積泊車次。
5、停車場的累積評價次。
6、停車場泊車次最少的時間。
7、停車場泊車次最多的時間。
8、停車場的平均泊車次。
其它功能:選擇時間按鈕指定查看的時間段(一週、一月、一年)
泊車報表如圖2-39 圖2-40所示。

圖2-39 泊車報表界面

圖2-40 泊車報表界面

泊車次走勢圖,可查看指定時間段的泊車次數。
1、圖數據:
1)縱座標:泊車次。
2)橫座標:指定時間的構成單位。
3)紅線:泊車次。停車場指定時間段的所有泊車次數總和。
2、圖功能:
1)移動鼠標在指定時間查看詳細信息,包括對應車次與時間
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
如圖2-41所示。

圖2-41 泊車次走勢圖

泊車評價分析圖,可查看指定時間段的泊車評價報表。
1、圖數據:
1)紅色塊:不滿意
2)藍黑色塊:還行
3)綠色塊:一般
4)橙色塊:滿意
5)青色塊:非常滿意
2、圖功能:
1)移動鼠標在指定色塊查看詳細信息,包括對應人次與佔比
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
如圖2-42所示。

圖4-42 泊車評價分析

泊車訪客類型佔比圖,可查看指定時間段的泊車訪客類型佔比。
1、圖數據:
1)紅色塊:臨時用戶
2)藍黑色塊:期卡用戶
3)綠色塊:充值卡用戶
2、圖功能:
1)移動鼠標在指定色塊查看詳細信息,包括對應人次與佔比
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
如圖2-43所示。

圖4-43 訪客類型佔比圖
3.2.5.1 收入流水
停車場管理員選中收入流水,即->“收入流水”,查看所管理的停車場指定時間內的收入流水報表(默認時間爲一週),可查看的報表如下:
1、停車場的收入流水走勢圖。
2、停車場的收入構成單元圖。
3、停車場的收入來源佔比圖。
4、停車場的充值卡持有人數。
5、停車場的期卡持有人數。
6、停車場臨時卡停車次數。
其它功能:選擇時間按鈕指定查看的時間段(一週、一月、一年)
收入流水報表如圖4-44 圖4-45所示。

圖4-44 收入流水界面

圖4-45 收入流水界面

停車場收入流水走勢圖,可查看指定時間段的收入情況。
1、圖數據:
1)縱座標:泊車次。
2)橫座標:指定時間的構成單位。
3)紅線:停車場收入。停車場指定時間段的停車場收入總和。
2、圖功能:
1)移動鼠標在指定時間查看詳細信息,包括對應收入與時間
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
如圖2-46所示。

圖2-46 停車場收入

停車場收入構成單元圖,可查看指定時間段的收入構成單元。
1、圖數據:
1)縱座標:停車場收入,單位:元。
2)橫座標:收入總值、臨時卡佔值、期卡佔值、充值卡佔值。
2、圖功能:
1)移動鼠標在指定時間查看詳細信息,包括對應組成成分與收入
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
如圖2-47所示。

圖2-47 收入構成單元
停車場收入來源佔比圖,可查看指定時間段的收入來源佔比。
1、圖數據:
1)紅色塊:臨時卡
2)藍黑色塊:期卡
3)綠色塊:充值卡
2、圖功能:
1)移動鼠標在指定色塊查看詳細信息,包括對應收入與佔比
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
如圖2-48所示。

圖4-48 收入來源佔比圖
3.2.6 公告發布
3.2.6.1 發佈公告
停車場管理員選中發佈公告,即->“發佈公告”,可發佈停車場的公告。
需要輸入的信息有公告名稱、發佈人、所見區域、公告類型、公告內容,還可上傳相關附件。如圖2-49所示。

圖2-49 發佈公告

編輯公告內容,停車場管理員選擇添加內容,即->“添加內容”,添加公告內容。如圖2-50 圖2-51所示。

圖2-50 編輯初始頁面

圖2-51 編輯公告界面
3.2.6.2 已發公告
管理員選中已發公告,即->“已發公告”,可查看停車場已經發布的公告。
停車場已發公告界面如圖2-52所示。

圖2-52 已發公告界面
3.3系統管理員
3.3.1 首頁
系統管理員進入系統首頁,首頁導航功能包括:
1、帳號信息顯示與操作
1)帳號名稱:查看賬戶信息
2)安全設置:設置帳號相關信息
3)退出帳號:退出當前登錄
2、停車場管理:切換到管理停車場界面
3、統計分析:管理停車場車位
4、用戶數據:管理停車場來往車輛
5、系統設置:查看停車場相關數據報表
6、公告發布:發佈相關停車場公告
7、導航條:顯示當前所在頁面
系統管理員操作首頁如圖2-53所示。

圖2-53 系統管理員操作界面

3.3.2 停車場管理
系統管理員選中停車場數據,即->“停車場數據”,可查看系統所管理的停車場的相關信息。包括停車場序號、停車場地區號、停車場名稱、停車場所在區域、停車位、創建時間。
其它功能:
1、表格底操作區域可選擇每頁信息條數、前往指定頁面。
2、輸入內容可檢索指定停車場信息。
3、選擇表格操作欄編輯選項對該條停車場數據信息進行編輯。
4、選擇表格操作欄移除選項對該條停車場數據信息進行移除。
停車場數據信息如圖2-54所示。

圖2-54 停車場數據界面
3.3.3 統計分析
3.3.3.1 系統推廣
系統管理員選中系統推廣,即->“系統推廣”,查看本系統的推廣信息報表。可查看的報表如下:
1、地區推廣柱狀圖。
2、地區推廣各地圖。
3、系統註冊佔比圖。
3、系統註冊最多停車場的城市及註冊個數。
4、系統推廣率最高的停車場的城市及推廣比。
系統推廣報表如圖2-55 圖2-56所示。

圖2-55 系統推廣報表

圖2-56 系統推廣報表

地區推廣柱狀圖,可查看各地區已註冊的和未註冊的停車場。
1、圖數據:
1)縱座標:停車場個數。
2)橫座標:中國各大城市。
3)藍色柱塊:對應城市已註冊的停車場個數。
4)灰色柱塊:對應城市未註冊的停車場個數
2、圖功能:
1)移動鼠標在指定柱塊查看詳細信息,包括對應地區與(未)註冊個數
2)鼠標拖拽圖放縮柱狀圖
3)雙擊色塊隱藏該色塊
4)圖右上方圖標功能
數據視圖:點擊查看該圖的各項數據列表
還原:還原爲未拖拽前的默認圖像
保存圖片:將圖表保存爲圖片儲存在本地
地區推廣柱狀圖如圖2-57所示。

圖2-57 地區推廣柱狀圖

只顯示未註冊數據信息。如圖2-58所示。

圖2-58 未註冊地區推廣柱狀圖

查看柱狀圖數據視圖,如圖2-59所示。

圖2-59 數據視圖

地區推廣各地圖,可在地圖上查看各地區已註冊的和未註冊的停車場。移動鼠標在指定柱塊查看詳細信息,包括對應地區與(未)註冊個數。如圖2-60所示。

圖2-60地區推廣各地圖

系統註冊佔比圖,可查看系統註冊佔比。
1、圖數據:
1)紅色塊:不滿意
2)綠色塊:一般
2、圖功能:
1)移動鼠標在指定色塊查看詳細信息,包括對應註冊次與佔比
如圖2-61所示。

圖2-61 系統總體註冊率
3.3.3.2 資源數據分析
系統管理員選中資源數據分析,即->“資源數據分析”,查看本系統的資源數據。
1、圖數據:
1)縱座標:泊車次。
2)橫座標:指定時間的構成單位。
3)紅線:泊車次。所有停車場指定時間段的所有泊車次數總和。
2、圖功能:
1)移動鼠標在指定時間查看詳細信息,包括對應車次與時間
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
系統資源數據報表如圖2-62所示。

圖2-62 系統總泊車次
3.3.3.3 訪問數據分析
系統管理員選中訪問數據分析,即->“訪問數據分析”,查看本系統的訪問數據分析報表。可查看的報表如下:
1、訪問系統人次走勢圖。
2、新註冊用戶走勢圖。
3、用戶評價分析圖。
4、管理員評價分析圖。
5、停車場類型佔比圖。
系統資源數據報表如圖2-63圖2-64所示。

圖6-23

圖2-64

訪問系統人次走勢圖,可查看指定時間段的訪問系統人次。
1、圖數據:
1)縱座標:訪問系統人次。
2)橫座標:指定時間的構成單位。
3)折線:指定時間段的訪問系統人次。
2、圖功能:
1)移動鼠標在指定時間查看詳細信息,包括對應訪問人次與時間
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
如圖2-65所示。

圖2-65 訪問系統人次圖

新註冊用戶走勢圖,可查看指定時間段的新註冊用戶人次。
1、圖數據:
1)縱座標:新註冊用戶人次。
2)橫座標:指定時間的構成單位。
3)折線:指定時間段的新註冊用戶人次。
2、圖功能:
1)移動鼠標在指定時間查看詳細信息,包括對應新註冊用戶人次與時間
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
如圖2-66所示。

圖2-66 新用戶註冊人次圖

用戶評價分析圖,可查看指定時間段的用戶評價報表。
1、圖數據:
1)紅色塊:不滿意
2)藍黑色塊:還行
3)綠色塊:一般
4)橙色塊:滿意
5)青色塊:非常滿意
2、圖功能:
1)移動鼠標在指定色塊查看詳細信息,包括對應人次與佔比
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
如圖2-67所示。

圖2-67用戶評價分析圖

管理員評價分析圖,可查看指定時間段的管理員評價報表。
1、圖數據:
1)紅色塊:不滿意
2)藍黑色塊:還行
3)綠色塊:一般
4)橙色塊:滿意
5)青色塊:非常滿意
2、圖功能:
1)移動鼠標在指定色塊查看詳細信息,包括對應人次與佔比
2)選擇時間按鈕指定查看的時間段(一週、一月、一年)
如圖2-68所示。

圖2-68管理員評價分析圖

停車場類型佔比圖,可查看指定時間段的停車場類型佔比。
1、圖數據:
1)紅色塊:公共停車場
2)藍黑色塊:私有停車場
3)綠色塊:專用停車場
2、圖功能:
1)移動鼠標在指定色塊查看詳細信息,包括對應停車場個數與佔比
如圖2-69所示。

圖2-69停車場類型佔比圖
3.3.4 用戶數據
3.3.4.1 停車場管理員
系統管理員選中停車場管理員,即->“停車場管理員”,可查看所管理的停車場管理員信息。停車場管理員信息包括姓名、所屬停車場、密碼、聯繫電話、身份證號、性別、年齡。
其它功能:
1、表格底操作區域可選擇每頁信息條數、前往指定頁面。
2、輸入內容可檢索管理員指定管理員信息。
3、選擇表格操作欄查看選項查看該條管理員詳細信息。
4、選擇表格操作欄編輯選項對該條信息進行編輯。
5、選擇表格操作欄移除選項對該條信息進行移除。
停車場管理員信息界面如圖2-70所示。

圖2-70 停車場管理員信息
3.3.4.2 註冊用戶
系統管理員選中註冊用員,即->“註冊用員”,可查看所管理的註冊用員信息。註冊用員信息包括賬戶、電話、創建時間、費用、積分、身份證號、信譽度。
其它功能:
1、表格底操作區域可選擇每頁信息條數、前往指定頁面。
2、輸入內容可檢索管理員指定註冊用員信息。
3、選擇表格操作欄查看選項查看該條註冊用戶詳細信息。
4、選擇表格操作欄編輯選項對該條信息進行編輯。
5、選擇表格操作欄移除選項對該條信息進行移除。
停車場管理員信息界面如圖2-71所示

圖2-71 註冊系統用戶信息

4.源代碼
4.1服務端
Controller層
socket
Instructions
package com.cloud.station.controller.socket;

import com.alibaba.fastjson.JSONArray;
import com.cloud.station.pojo.DepotInfo;
import com.cloud.station.pojo.DepotStationState;
import com.cloud.station.pojo.dto.CarDTO;
import com.cloud.station.service.*;
import com.cloud.station.service.cache.SocketManager;
import com.cloud.station.service.redis.StationStateRedis;
import com.cloud.station.utils.BeanTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

import java.io.PrintStream;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

/**

  • 指令處理
    */
    public class Instructions{
    public Map<String,String> devicesMap = new HashMap<>();//鏈接設備狀態 appId-key
    //相關指令
    public final static String SYS_CHBT = “SYS+CHBT”;//獲取心跳時間(單位秒)
    public final static String DAT_LOCKED_0=“DAT+LOCKED=0”;//鎖住指定車位
    public final static String DAT_LOCKED_1=“DAT+LOCKED=1”;//解鎖車位
    public final static String DAT_UPSUM=“DAT+UPSNUM”;//更新數據(車位總數量)
    public final static String DATA_LEFT=“DAT+LEFT”;//剩餘數量
    public final static String SYS_REST=“SYS+REST”;//重置模塊設置信息

    public final static String DAT_TIME_INTERVAL = “DAT+TTL”;//每多少毫秒同步一次數據

    public final static String SYS_CLOSED=“SYS+CLOSED”;//斷開連接

    private static ApplicationContext applicationContext = null;
    @Autowired
    SocketManager socketManager;

    @Autowired
    StationOrderService stationOrderService;
    @Autowired
    DepotInfoService depotStationService;

    PrintStream out = null;
    Socket socket = null;

    public Instructions() {

    }
    public Instructions(Socket socket,PrintStream out) {
    this.out = out;
    this.socket = socket;
    }
    //保存連接
    private void saveConnection(Socket socket){
    //如果是新的socket
    Socket socket_ = this.socketManager.get(socket.getInetAddress().toString());
    if(socket_!=null) socketManager.add(socket);
    }

    public void parse(String cmd){
    //1.進行認證
    // out.println(“recived:”+cmd);

     StationStateRedis stationStateRedis = (StationStateRedis) BeanTools.getBean(StationStateRedis.class);
     stationOrderService = (StationOrderService)BeanTools.getBean(StationOrderService.class);
     PayService payService = (PayService) BeanTools.getBean(PayService.class);
     depotStationService = (DepotInfoService) BeanTools.getBean(DepotInfoService.class);
    
     if(cmd.contains("number")){//收到的是車牌信息
          CarDTO carDTO = JSONArray.parseObject(cmd,CarDTO.class);
           if(carDTO.getEndTime()!=null && carDTO.getEndTime()>0){//計算
                float cusumMoney = payService.pay(carDTO.getStationId(),carDTO.getNumber());
                out.println(cusumMoney);//總消費金額
           }else{//添加
                 //TODO 餘額不足未處理
              Integer rst = stationOrderService.addByCarNum(carDTO.getStationId(),carDTO.getNumber());
              if(rst==1)out.println("OK");
              else {
                  //TODO 查詢黑名單 如果存在過則不能進入
                  out.println("ERROR");
              }
           }
     }else if(cmd.contains("stationId")){
           DepotStationState depotStationState = JSONArray.parseObject(cmd,DepotStationState.class);
           stationStateRedis.save(depotStationState);
      }else if("ST+NUM".equals(getKeyFromCmd(cmd))){//獲取停車場的數量(ST+NUM)
         String stationId_ = getValueFromCmd("ST+NUM",cmd);
         try{
             DepotInfo depotInfo = (DepotInfo) depotStationService.findByPrimaryKey(Long.valueOf(stationId_));
             out.println(depotInfo.getStationNum());
         }catch (Exception e){
             out.println("ERROR");
         }
     }else if("ST+LEFT".equals(getKeyFromCmd(cmd))){//獲取當前停車場剩餘數
         String stationId_ = getValueFromCmd("ST+LEFT",cmd);
         try{
             DepotStationState depotStationState = stationStateRedis.getByKey(Long.valueOf(stationId_));
             if(depotStationState!=null){
                 out.println(depotStationState.getLeft());
             }else{
                 DepotInfo depotInfo = (DepotInfo) depotStationService.findByPrimaryKey(Long.valueOf(stationId_));
                 out.println(depotInfo.getStationNum());
             }
    
         }catch (Exception e){
             out.println("ERROR");
         }
     }
    

    }

    /**

    • 從指令中提取值

    • 格式 key:value

    • @param key 指令key

    • @param str 字符串

    • @return
      */
      public String getValueFromCmd(String key,String str){
      String cmd = null;//指令值
      String str_ = str.trim();//去除前後空格
      if(!str_.startsWith(key)) return null;

      if(!str_.contains("😊) return null;

      cmd = str_.substring(str.indexOf(":")+1);
      return cmd.trim();
      }

    /**

    • 從指令中得到KEY
    • @param cmd
    • @return
      */
      public String getKeyFromCmd(String cmd){
      String cmd_ = cmd.trim();
      if(cmd_.contains("😊){
      return cmd_.substring(0,cmd_.lastIndexOf("😊).trim();
      }else{
      return cmd.trim();
      }
      }

}

SocketOperate
package com.cloud.station.controller.socket;

import org.springframework.beans.factory.annotation.Autowired;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Date;

/**

  • 多線程處理socket接收的數據
    */
    public class SocketOperate extends Thread{
    private Socket socket;
    @Autowired

    public SocketOperate(Socket socket) {
    this.socket=socket;
    }
    @SuppressWarnings(“unused”)
    public void run()
    {
    PrintStream out = null;
    BufferedReader buf =null;
    Instructions instructions = null;
    boolean flag =true;
    try{
    while(flag){
    //獲取Socket的輸出流,用來向客戶端發送數據
    out = new PrintStream(socket.getOutputStream());
    //獲取Socket的輸入流,用來接收從客戶端發送過來的數據
    buf = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    instructions = new Instructions(socket,out);
    //接收從客戶端發送過來的數據
    String str = buf.readLine();

             if(str == null || "".equals(str)){
                 flag = false;
             }else{
                 instructions.parse(str);
             }
         }
         out.close();
         socket.close();
    

// socket.setSoTimeout(30000);//設置讀操作超時時間30 s
}catch(Exception ex){
out.println(“Connection closed;”);
flag = false;
ex.printStackTrace();
}
}
}

SocketServiceLoader
package com.cloud.station.controller.socket;

import com.cloud.station.service.cache.SocketManager;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**

  • 將socket service隨tomcat啓動
  • @author zhangzhongwen

*/
@WebListener
public class SocketServiceLoader implements ServletContextListener{
//socket server 線程
private SocketThread socketThread;

@Override
public void contextDestroyed(ServletContextEvent arg0) {
    System.out.println("liting: contextDestroyed");
    if(null!=socketThread && !socketThread.isInterrupted())
    {
        socketThread.closeSocketServer();
        socketThread.interrupt();
    }
}

@Override
public void contextInitialized(ServletContextEvent arg0) {
    System.out.println("liting: contextInitialized");

    if(null==socketThread)
    {
        //新建線程類
        socketThread=new SocketThread(null);
        //啓動線程
        socketThread.start();
    }
}

}

SocketThread
package com.cloud.station.controller.socket;

import com.cloud.station.conf.ConfigurationManager;
import com.cloud.station.constant.ConstantsKey;
import com.cloud.station.service.cache.SocketManager;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**

  • socket 線程類
  • @author zhangzhongwen

*/
public class SocketThread extends Thread{
private ServerSocket serverSocket = null;

public SocketThread(ServerSocket serverScoket){
    try {
        if(null == serverSocket){
            this.serverSocket = new ServerSocket(8899);//TODO 這裏要使用配置文件進行配置
            System.out.println("socket start");
        }
    } catch (Exception e) {
        System.out.println("SocketThread創建socket服務出錯");
        e.printStackTrace();
    }

}

public void run(){

    while(!this.isInterrupted()){
        try {
            Socket socket = null;
            socket = serverSocket.accept();
            if(null != socket){
                //處理接受的數據
                new SocketOperate(socket).start();
            }

// socket.setSoTimeout(300000);

        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}


public void closeSocketServer(){
    try {
        if(null!=serverSocket && !serverSocket.isClosed())
        {
            serverSocket.close();
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

websocket
StationSateWebSocket
package com.cloud.station.controller.websocket;

import com.alibaba.fastjson.JSONArray;
import com.cloud.station.pojo.dto.AddressDTO;
import com.cloud.station.pojo.dto.MapAddressDTO;
import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;

/**

  • 停車場狀態信息WebSocket
    */
    @ServerEndpoint("/station/websoket")
    @Component
    public class StationSateWebSocket {

    //靜態變量,用來記錄當前在線連接數。應該把它設計成線程安全的。
    private static int onlineCount = 0;

    //與某個客戶端的連接會話,需要通過它來給客戶端發送數據
    private Session session;

    //處理線程
    private StationStateThread stationStateThread;
    /**

    • 連接建立成功調用的方法
    • @param session 可選的參數。session爲與某個客戶端的連接會話,需要通過它來給客戶端發送數據
      */
      @OnOpen
      public void onOpen(Session session){
      this.session = session;
      addOnlineCount(); //在線數加1

    }

    /**

    • 連接關閉調用的方法
      */
      @OnClose
      public void onClose(){
      subOnlineCount(); //在線數減1
      try {
      session.close();
      } catch (IOException e) {
      e.printStackTrace();
      }
      stationStateThread.shut();
      }

    /**

    • 收到客戶端消息後調用的方法
    • @param address 客戶端發送過來的消息
    • @param session 可選的參數
      */
      @OnMessage
      public void onMessage(String address, Session session,@PathParam(“client-id”) String clientId) {
      AddressDTO addressDTO = JSONArray.parseObject(address,AddressDTO.class);
      try{
      if(stationStateThread==null)stationStateThread = new StationStateThread(session,addressDTO);
      if(session.isOpen() && stationStateThread!=null)stationStateThread.start();
      }catch (Exception e){
      try {
      session.close();
      } catch (IOException e1) {
      e1.printStackTrace();
      }
      }

    }

    /**

    • 發生錯誤時調用
    • @param session
    • @param error
      */
      @OnError
      public void onError(Session session, Throwable error){
      try {
      session.close();
      } catch (IOException e) {
      e.printStackTrace();
      }
      stationStateThread.shut();
      error.printStackTrace();
      }

    public static synchronized int getOnlineCount() {
    return onlineCount;
    }

    public static synchronized void addOnlineCount() {
    StationSateWebSocket.onlineCount++;
    }

    public static synchronized void subOnlineCount() {
    StationSateWebSocket.onlineCount–;
    }
    }

StationStateThread
package com.cloud.station.controller.websocket;

import com.alibaba.fastjson.JSONObject;
import com.cloud.station.algorithm.Distance;
import com.cloud.station.pojo.DepotInfo;
import com.cloud.station.pojo.DepotStationState;
import com.cloud.station.pojo.dto.AddressDTO;
import com.cloud.station.pojo.dto.Position;
import com.cloud.station.pojo.dto.StationStateDTO;
import com.cloud.station.service.DepotInfoService;
import com.cloud.station.service.redis.StationStateRedis;
import com.cloud.station.utils.BeanTools;

import javax.websocket.Session;
import java.io.IOException;
import java.util.*;

/**

  • 停車場狀態信息線程
    */
    public class StationStateThread extends Thread{
    private Session session;
    private boolean isRunning;

    private DepotInfoService depotInfoService;
    StationStateRedis stationStateRedis;

    private AddressDTO addressDTO;//封裝的地址類
    public StationStateThread(Session session,AddressDTO addressDTO) {
    this.session = session;
    this.addressDTO = addressDTO;

     //從spring容器中獲取bean
     depotInfoService = (DepotInfoService) BeanTools.getBean(DepotInfoService.class);
    
     if(session.isOpen() && addressDTO!=null)
         this.isRunning = true;
     else
         this.isRunning = false;
    

    }

    @Override
    public void run() {
    stationStateRedis = (StationStateRedis) BeanTools.getBean(StationStateRedis.class);
    List list = init();//獲取數據
    List stateList = new ArrayList<>();//狀態信息
    while (isRunning){
    if(!session.isOpen()){
    isRunning = false;
    }else{

             try {
                 Thread.sleep(1000);
    
                 //監控當前車位狀態
                 stateList.clear();
                 for(DepotInfo di:list){
                     StationStateDTO ss = new StationStateDTO();
    
                     DepotStationState ds = stationStateRedis.getByKey(di.getId());//獲取狀態信息
    
                     if(ds!=null){
                         ss.setLeft(ds.getLeft());
                     }else{
                         ss.setLeft(di.getStationNum());
                     }
                     ss.setStationId(di.getId());
                     ss.setLastTime(new Date().getTime());
                     stateList.add(ss);
                 }
    
    
                 StationStateDTO css = new StationStateDTO();
                 DepotStationState currrentDs = stationStateRedis.getByKey(addressDTO.getSid());
                 if(currrentDs!=null){
                     css.setLeft(currrentDs.getLeft());
                 }else{
                     DepotInfo depotInfo = (DepotInfo) depotInfoService.findByPrimaryKey(addressDTO.getSid());
                     css.setLeft(depotInfo.getStationNum());
                 }
                 css.setStationId(addressDTO.getSid());
                 css.setLastTime(new Date().getTime());
    
    
    
                 Map map = new HashMap();
                 map.put("state_info",stateList);
                 map.put("count",1);
                 map.put("current",css);
                 this.session.getBasicRemote().sendText(JSONObject.toJSONString(map));
    
             } catch (Exception e) {
                 e.printStackTrace();
             }
         }
    
     }
    

    }

    public void shut(){
    this.isRunning = false;
    }

    public List getDataFromDB(Double lat,Double lng,Double distance){
    //計算範圍
    Position position = Distance.calcPosition(lat,lng,distance);
    List list =depotInfoService.getByLatAndLon(position,addressDTO.getPage(),addressDTO.getLimit());

     if(list.isEmpty() || list.size()<addressDTO.getLimit()){
        List list_ =  stationStateRedis.getByLatAndLon(position,addressDTO.getLimit()-list.size());//從緩存獲取
        list.addAll(list_);
     }
     return list;
    

    }

    /**

    • 首次進入獲得數據
      */
      public List init(){
      //重數據庫查詢
      List list = getDataFromDB(addressDTO.getLat(),addressDTO.getLng(),
      addressDTO.getDistance());

      Double distance = addressDTO.getDistance();//當前搜索範圍
      Double max_distance = 2*addressDTO.getDistance();//TODO 最大搜索範圍 暫定2倍距離
      while(list==null){//如果沒有找到則擴大範圍查找
      distance+=addressDTO.getStep();//擴大範圍
      list = getDataFromDB(addressDTO.getLat(),addressDTO.getLng(),distance);

       if(distance>=max_distance)break;//達到最大搜索範圍後還沒有就跳出循環
      

      }
      try {
      Map map = new HashMap();
      map.put(“station_info”,list);
      map.put(“count”,0);
      map.put(“current”,depotInfoService.findByPrimaryKey(addressDTO.getSid()));
      this.session.getBasicRemote().sendText(JSONObject.toJSONString(map));
      } catch (IOException e) {
      e.printStackTrace();
      }

      return list;
      }
      }

WebSocketConfig
package com.cloud.station.controller.websocket;

import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Configuration
public class WebSocketConfig {
//TODO 使用springboot內置的容器時要打開註釋,發佈到tomcat時要註釋掉
// @Bean
// public ServerEndpointExporter serverEndpointExporter() {
// return new ServerEndpointExporter();
// }
}

AdminController
package com.cloud.station.controller;

import com.cloud.station.constant.Code;
import com.cloud.station.constant.ConstantsKey;
import com.cloud.station.constant.HttpCode;
import com.cloud.station.pojo.AdminInfo;
import com.cloud.station.pojo.DepotAdminInfo;
import com.cloud.station.pojo.UserInfo;
import com.cloud.station.service.AdminInfoService;
import com.cloud.station.service.UserInfoService;
import com.cloud.station.utils.BeanUtils;
import com.cloud.station.utils.CommonUtils;
import com.cloud.station.utils.ParamValidUtils;
import com.cloud.station.utils.PasswordUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/admin")
public class AdminController {
@Autowired
private AdminInfoService adminInfoService;

/**
* 管理員登陸
* @param request
* account 賬號
* password 密碼
* @return
*/
@RequestMapping(value = “/login”, method = RequestMethod.POST)
public JSONType login(HttpServletRequest request) {
try {
String account = request.getParameter(“account”);// 賬號
String password = request.getParameter(“pwd”);// 密碼
if(ParamValidUtils.isEmpty(account) || ParamValidUtils.isEmpty(password))
return JSONReturn.error(HttpCode.PARAMETER_MISSING,“username and password are required”);

     // 2.根據賬戶查詢存儲的密碼
     String realPassword = adminInfoService.getPasswordByAccount(account);
     AdminInfo adminInfo= adminInfoService.getDepotAdminInfoByAccount(account);
     if(realPassword==null || !PasswordUtils.check(realPassword,password))
        return JSONReturn.error(Code.ERROR,"login failed");

     request.getSession().setAttribute(ConstantsKey.LOGIN_SESSION_TOKEN,account);
     return JSONReturn.success(adminInfo.getId());
  } catch (Exception e) {
     return JSONReturn.error(HttpCode.LOGIN_FAILE, "login failed");
  }

}

/**
* 管理員添加
* @param request
* userInfo User 實體屬性
* @return
*/
@RequestMapping(value = “/add”, method = RequestMethod.POST)
@ResponseBody
public JSONType register(HttpServletRequest request) {

     return JSONReturn.success();

}

/**
* 獲取管理員基本信息
*
* @param request
* @return
*/
@RequestMapping(value = “/info”, method = RequestMethod.GET)
@ResponseBody
public JSONType getUserInfo(HttpServletRequest request) {
try{
Integer uid = Integer.valueOf(request.getParameter(“uid”));
AdminInfo adminInfo = (AdminInfo) adminInfoService.findByPrimaryKey(uid);
return JSONReturn.success(adminInfo);
}catch (Exception e){
return JSONReturn.error(HttpCode.UNEXPETED_ERROR,“unexpeted error”);
}
}
}

AppController
package com.cloud.station.controller;

import com.cloud.station.conf.ConfigurationManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**

  • @className: AppController

  • @data: 2018-03-06

  • @lastModify: 2018-03-06

  • @description: APP Controller

  • @version v1
    */
    @Controller
    @RequestMapping("/v1/app")
    public class AppController {

    public static String APK_UPLOAD_DIR = “apk.upload.dir” ;

    /**

    • 獲取APP的版本
    • @return 版本信息
      */
      @RequestMapping(value = “/v”, method = RequestMethod.GET)
      @ResponseBody
      public Object getVersion(HttpServletRequest request){
      //TODO /v1/app/v
      return “success”;
      }

    /**

    • 更具平臺和版本下載APK文件
    • @method POST
    • @url /v1/app/app
    • @param request
    •          platform[String]  平臺
      
    •          v[String]          版本
      
    • @return 下載
      */
      @RequestMapping(value = “/app”, method = RequestMethod.POST)
      @ResponseBody
      public Object dowonloadApp(HttpServletRequest request){
      //TODO /v1/app/app
      return null;
      }

    /**

    • 上傳APK安裝包

    • @method POST

    • @url /v1/app/upload

    • @param request

    •          platform[String]  平臺
      
    •          v[String]          版本
      
    • @return 下載
      */
      @RequestMapping(value = “/upload”, method = RequestMethod.POST)
      @ResponseBody
      public Object uploadApp(HttpServletRequest request){
      String dir = ConfigurationManager.getProperty(APK_UPLOAD_DIR);

      //TODO /v1/app/upload
      return null;
      }
      }

CarInfoController
package com.cloud.station.controller;

import com.alibaba.fastjson.JSON;
import com.cloud.station.conf.ConfigurationManager;
import com.cloud.station.constant.Code;
import com.cloud.station.constant.HttpCode;
import com.cloud.station.pojo.CarInfo;
import com.cloud.station.service.CarInfoService;
import com.cloud.station.service.StationOrderService;
import com.cloud.station.utils.BeanUtils;
import com.cloud.station.utils.ParamValidUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**

  • @className: CarInfoController

  • @data: 2018-03-06

  • @lastModify: 2018-03-06

  • @description: APP Controller

  • @version v1
    */
    @Controller
    @RequestMapping("/v1/carinfo")
    public class CarInfoController {

    @Autowired
    CarInfoService carInfoService;

    @Autowired
    StationOrderService stationOrderService;

    /**

    • 查詢

    • @param request

    • @return
      */
      @RequestMapping(value = “/get”, method = RequestMethod.GET)
      @ResponseBody
      public JSONType getByNum(HttpServletRequest request){
      try{
      CarInfo carInfo = new CarInfo();
      String carNumber =request.getParameter(“carNumber”);
      String carNumberType =request.getParameter(“carNumberType”);
      String carType =request.getParameter(“carType”);
      String carXH =request.getParameter(“carXH”);
      String carYear =request.getParameter(“carYear”);
      String carColor =request.getParameter(“carColor”);
      String code =request.getParameter(“code”);

       if(!ParamValidUtils.isEmpty(carNumber))carInfo.setCarNumber(carNumber);
       if(!ParamValidUtils.isEmpty(carNumberType))carInfo.setCarNumberType(carNumberType);
       if(!ParamValidUtils.isEmpty(carType))carInfo.setCarType(carType);
       if(!ParamValidUtils.isEmpty(carXH))carInfo.setCarXH(carXH);
       if(!ParamValidUtils.isEmpty(carYear))carInfo.setCarYear(Integer.valueOf(carYear));
       if(!ParamValidUtils.isEmpty(carColor))carInfo.setCarColor(carColor);
       if(!ParamValidUtils.isEmpty(code))carInfo.setCode(code);
      
       if(carInfo==null)
           return JSONReturn.error(HttpCode.PARAMETER_MISSING,"parameter missing");
       String page_ = request.getParameter("page");
       String limit_ = request.getParameter("limit");
      
       if(ParamValidUtils.isEmpty(page_))page_="1";
       if(ParamValidUtils.isEmpty(limit_))limit_="20";
      
       Integer page = Integer.valueOf(page_);
       Integer limit = Integer.valueOf(limit_);
      
       if(ParamValidUtils.isEmpty(page_))page=1;
       if(ParamValidUtils.isEmpty(limit_))limit=20;
      
       List list = carInfoService.get(carInfo,page,limit);
       Long total = carInfoService.count(carInfo);
       Map result = new HashMap();
       result.put("data",list);
       result.put("total",total);
       result.put("pageIndex",page);
       result.put("pageSize",list.size());
      
       return !list.isEmpty() ? JSONReturn.success(result):
               JSONReturn.error(HttpCode.NOT_EXSITS,"empty");
      

      }catch (Exception e){
      return JSONReturn.error(HttpCode.UNEXPETED_ERROR,“unexpeted error”);
      }
      }

    /**

    • 綁定車牌

    • @param request

    • @return
      */
      @RequestMapping(value = “/bind”, method = RequestMethod.POST)
      @ResponseBody
      public JSONType bindCarNumber(HttpServletRequest request){
      try{
      CarInfo carInfo = BeanUtils.toObject(request,CarInfo.class);
      System.out.println(carInfo);
      if(carInfo==null)
      return JSONReturn.error(HttpCode.PARAMETER_MISSING,“parameter missing”);

       if(ParamValidUtils.isEmpty(request.getParameter("carNumber"))||
               ParamValidUtils.isEmpty(request.getParameter("userId")))
           return JSONReturn.error(HttpCode.PARAMETER_MISSING,"parameter missing");
      
       carInfo.setId(null);
       carInfo.setCurrentUsed(0L);
      
       CarInfo carInfo_ = new CarInfo();
       carInfo_.setCarNumber(carInfo.getCarNumber());
       List list = carInfoService.get(carInfo_,1,1);
       if(!list.isEmpty()){
           return JSONReturn.error(Code.ERROR,"resource is exsist");
       }
      
       Integer rst = carInfoService.add(carInfo);
       return rst>0 ? JSONReturn.success(rst):
               JSONReturn.error(Code.ERROR,"failed");
      

      }catch (Exception e){
      return JSONReturn.error(HttpCode.UNEXPETED_ERROR,“unexpeted error”);
      }
      }

    @RequestMapping(value = “/addcn”, method = RequestMethod.POST)
    @ResponseBody
    public JSONType addCarNumber(HttpServletRequest request){
    try{
    CarInfo carInfo = BeanUtils.toObject(request,CarInfo.class);
    int stat = carInfoService.add(carInfo);
    return JSONReturn.success(stat);
    }catch (Exception e){
    return JSONReturn.error(HttpCode.UNEXPETED_ERROR,“error”);
    }
    }

    @RequestMapping(value = “/unbind”, method = RequestMethod.POST)
    @ResponseBody
    public JSONType unBind(HttpServletRequest request){
    //TODO 綁定車牌
    return JSONReturn.success(“未實現”);
    }

    @RequestMapping(value = “/history”, method = RequestMethod.GET)
    @ResponseBody
    public JSONType history(HttpServletRequest request){
    try{
    String carNum = request.getParameter(“carNum”);
    List list = stationOrderService.getHistory(carNum);
    return JSONReturn.success(list);
    }catch (Exception e){
    return JSONReturn.error(HttpCode.UNEXPETED_ERROR,“error”);
    }
    }
    }

CarNumberBlackListController
package com.cloud.station.controller;

import com.alibaba.fastjson.JSON;
import com.cloud.station.constant.HttpCode;
import com.cloud.station.pojo.CarNumberBlacklist;
import com.cloud.station.service.CarNumberBlackListService;
import com.cloud.station.utils.BeanUtils;
import com.cloud.station.utils.ParamValidUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/v1/carblacklist")
public class CarNumberBlackListController {

@Autowired
CarNumberBlackListService carNumberBlackListService;

@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
public JSONType add(HttpServletRequest request){
    try{
        CarNumberBlacklist carNumberBlacklist = BeanUtils.toObject(request,CarNumberBlacklist.class);
        if(carNumberBlacklist==null)
            return JSONReturn.error(HttpCode.INVALIED_AUTHORITY,"invalied");
        if(carNumberBlacklist.getCarNum()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"car number required");
        int rst = 0;

         carNumberBlacklist.setOweTime(new Date().getTime());
         carNumberBlacklist.setId(null);
         carNumberBlacklist.setOweAmount(0);
         carNumberBlacklist.setDisposeTime(new Date().getTime());
         carNumberBlacklist.setOweMoneyTime(1L);
         rst = carNumberBlackListService.save(carNumberBlacklist);
        return rst>0 ? JSONReturn.success(rst) :
                JSONReturn.error(HttpCode.INVALIED_AUTHORITY,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }

}

@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public JSONType update(HttpServletRequest request){
    try{
        CarNumberBlacklist carNumberBlacklist = BeanUtils.toObject(request,CarNumberBlacklist.class);
        if(carNumberBlacklist==null)
            return JSONReturn.error(HttpCode.INVALIED_AUTHORITY,"invalied");
        if(carNumberBlacklist.getId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"id required");

        carNumberBlacklist.setDisposeTime(new Date().getTime());
        int rst = carNumberBlackListService.update(carNumberBlacklist);

        return rst>0 ? JSONReturn.success(rst) :
                JSONReturn.error(HttpCode.INVALIED_AUTHORITY,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}
@RequestMapping(value = "/del/id", method = RequestMethod.POST)
@ResponseBody
public JSONType deleteById(HttpServletRequest request){
    try{
        String id_ = request.getParameter("id");
        if(ParamValidUtils.isEmpty(id_))
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"id required");

        int rst = carNumberBlackListService.deleteByPrimaryKey(Long.valueOf(id_));
        return rst>0 ? JSONReturn.success(rst) :
                JSONReturn.error(HttpCode.INVALIED_AUTHORITY,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

@RequestMapping(value = "/get/id", method = RequestMethod.GET)
@ResponseBody
public JSONType getById(HttpServletRequest request){
    try{
        String id_ = request.getParameter("id");
        if(ParamValidUtils.isEmpty(id_))
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"id required");

        CarNumberBlacklist carNumberBlacklist = (CarNumberBlacklist) carNumberBlackListService.findByPrimaryKey(Long.valueOf(id_));
        return carNumberBlacklist!=null ? JSONReturn.success(carNumberBlacklist) :
                JSONReturn.error(HttpCode.INVALIED_AUTHORITY,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

/**
 * 根據車牌查詢
 * @param request
 * @return
 */
@RequestMapping(value = "/get/number", method = RequestMethod.GET)
@ResponseBody
public JSONType getByCarNumber(HttpServletRequest request){
    try{
        String page_ = request.getParameter("page");
        String limit_ = request.getParameter("limit");
        String carNum = request.getParameter("carNum");

        if(ParamValidUtils.isEmpty(page_))page_="1";
        if(ParamValidUtils.isEmpty(limit_))limit_="20";

        if(ParamValidUtils.isEmpty(carNum))
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"car number required");

        Integer page = Integer.valueOf(page_);
        Integer limit = Integer.valueOf(limit_);

        List<CarNumberBlacklist> list = carNumberBlackListService.getByCarNumber(carNum,page,limit);

        Long total = carNumberBlackListService.countFilterByCarNum(carNum);
        Map map = new HashMap();
        map.put("data",list);
        map.put("total",total);
        return (list!=null && !list.isEmpty()) ? JSONReturn.success(map) :
                JSONReturn.error(HttpCode.RESULT_EMPTY,"empty");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

}

DepotAdminController
package com.cloud.station.controller;

import com.cloud.station.constant.Code;
import com.cloud.station.constant.ConstantsKey;
import com.cloud.station.constant.HttpCode;
import com.cloud.station.pojo.AdminInfo;
import com.cloud.station.pojo.DepotAdminInfo;
import com.cloud.station.pojo.UserInfo;
import com.cloud.station.service.DepotAdminInfoService;
import com.cloud.station.service.UserInfoService;
import com.cloud.station.utils.BeanUtils;
import com.cloud.station.utils.CommonUtils;
import com.cloud.station.utils.ParamValidUtils;
import com.cloud.station.utils.PasswordUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/depot/admin")
public class DepotAdminController {
@Autowired
private DepotAdminInfoService depotAdminInfoService;

/**
* 管理員登陸
* @param request
* account 賬號
* password 密碼
* @return
*/
@RequestMapping(value = “/login”, method = RequestMethod.POST)
public JSONType login(HttpServletRequest request) {
try {
String account = request.getParameter(“account”);// 賬號
String password = request.getParameter(“pwd”);// 密碼
if(ParamValidUtils.isEmpty(account) || ParamValidUtils.isEmpty(password))
return JSONReturn.error(HttpCode.PARAMETER_MISSING,“username and password are required”);

     // 2.根據賬戶查詢存儲的密碼
     String realPassword = depotAdminInfoService.getPasswordByAccount(account);
     DepotAdminInfo depotAdminInfo= depotAdminInfoService.getDepotAdminInfoByAccount(account);
     if(realPassword==null || !PasswordUtils.check(realPassword,password))
        return JSONReturn.error(Code.ERROR,"login failed");

     request.getSession().setAttribute(ConstantsKey.LOGIN_SESSION_TOKEN,account);
     return JSONReturn.success(depotAdminInfo.getId());
  } catch (Exception e) {
     return JSONReturn.error(HttpCode.LOGIN_FAILE, "login failed");
  }

}

/**
* 管理員註冊
* @param request
* userInfo User 實體屬性
* @return
*/
@RequestMapping(value = “/reg”, method = RequestMethod.POST)
@ResponseBody
public JSONType register(HttpServletRequest request) {
try {
DepotAdminInfo depotAdminInfo = BeanUtils.toObject(request,DepotAdminInfo.class);

     /**
      * 必要參數驗證
      * a.賬號不能爲空
      * b.密碼不能爲空
      */
     if(ParamValidUtils.isEmpty(depotAdminInfo.getAccount()) || ParamValidUtils.isEmpty(depotAdminInfo.getPwd()))
        return JSONReturn.error(HttpCode.PARAMETER_MISSING,"parameter missing");

     String newPwd = PasswordUtils.encrpty(depotAdminInfo.getPwd());// 密碼加密處理

     depotAdminInfo.setPwd(newPwd);
     // id爲自動增長
     depotAdminInfo.setId(null);
     depotAdminInfo.setCreateTime(new Date().getTime());


     // 3.持久化數據
     List list=  depotAdminInfoService.findByName(depotAdminInfo.getAccount());
     if(list!=null && list.size()>0){//用戶存在
        return JSONReturn.error(HttpCode.RESOURCE_EXSISTS,"already exsists");
     }
     Integer result = depotAdminInfoService.save(depotAdminInfo);

     return result > 0 ? JSONReturn.success() : JSONReturn.error(
           Code.ERROR, "register failed");

  } catch (Exception e) {
     e.printStackTrace();
     return JSONReturn.error(HttpCode.UNEXPETED_ERROR, "unexpeted error");
  }

}

/**
* 獲取管理員基本信息
*
* @param request
* @return
*/
@RequestMapping(value = “/info”, method = RequestMethod.GET)
@ResponseBody
public JSONType getUserInfo(HttpServletRequest request) {
try{
Integer uid = Integer.valueOf(request.getParameter(“uid”));
DepotAdminInfo depotAdminInfo = (DepotAdminInfo) depotAdminInfoService.findByPrimaryKey(uid);
return JSONReturn.success(depotAdminInfo);
}catch (Exception e){
return JSONReturn.error(HttpCode.UNEXPETED_ERROR,“unexpeted error”);
}
}
}

DepotInfoController
package com.cloud.station.controller;

import com.alibaba.fastjson.JSON;
import com.cloud.station.algorithm.Distance;
import com.cloud.station.constant.Code;
import com.cloud.station.constant.HttpCode;
import com.cloud.station.pojo.Address;
import com.cloud.station.pojo.DepotInfo;
import com.cloud.station.pojo.dto.Position;
import com.cloud.station.service.AddressService;
import com.cloud.station.service.DepotInfoService;
import com.cloud.station.service.redis.StationStateRedis;
import com.cloud.station.utils.BeanUtils;
import com.cloud.station.utils.ParamValidUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/v1/station")
public class DepotInfoController {

@Autowired
private DepotInfoService depotInfoService;
@Autowired
AddressService addressService;
@Autowired
StationStateRedis stationStateRedis;

/**
* 添加停車場信息
*
* @param request
* @return
*/
@RequestMapping(value = “/add”, method = RequestMethod.POST)
@ResponseBody
public JSONType save(HttpServletRequest request) {
try{
DepotInfo depotInfo = BeanUtils.toObject(request,DepotInfo.class);
Address address = BeanUtils.toObject(request,Address.class);
Integer stationNum = depotInfo.getStationNum();// 車位總數

     //車位<0時
     if (stationNum==null || stationNum<0){
        depotInfo.setStationNum(0);
     }

     //如果名稱爲空或者用戶ID爲空
     if(ParamValidUtils.isEmpty(depotInfo.getName()) ||
           depotInfo.getUserId()==null)
        return JSONReturn.error(HttpCode.PARAMETER_MISSING,"parameter missing");


     depotInfo.setId(null);
     depotInfo.setCreateTime(new Date().getTime());
     address.setCreateTime(new Date().getTime());



     // 3.持久化數據
     //保存地址
     List<Address> addressList = addressService.find(address);
     if(addressList==null || addressList.isEmpty()){
        addressService.save(address);
        addressList = addressService.find(address);
     }

     Long id = Long.valueOf(addressList.get(0).getId());
     if(id!=null)
        depotInfo.setAddressId(id);

// List list = depotInfoService.find(depotInfo);
// if(list!=null && list.size()>0){//數據存在
// return JSONReturn.error(HttpCode.RESOURCE_EXSISTS,“failed”);
// }

     Integer result = depotInfoService.save(depotInfo);

     return result > 0 ? JSONReturn.success() : JSONReturn.error(Code.ERROR,
           "add failed");
  }catch (Exception e){
     return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
  }

}

/**
* 根據主鍵id修改停車場基本信息
*
* @param request
* @return
*/
@RequestMapping(value = “/edit”, method = RequestMethod.POST)
@ResponseBody
public JSONType update(HttpServletRequest request) {
try{
DepotInfo depotInfo = BeanUtils.toObject(request,DepotInfo.class);
if(depotInfo.getId()==null ||
depotInfo.getUserId()==null ||
depotInfo.getAddressId()==null ||
depotInfo.getStationNum()<0)
return JSONReturn.error(HttpCode.PARAMETER_INVALIED,“paramter invalied”);

     Address address = (Address) addressService.findByPrimaryKey(depotInfo.getAddressId());
     if(address==null)
        return JSONReturn.error(HttpCode.NOT_EXSITS,"address is not exsist");

     // 3.修改停車場信息
     DepotInfo depotInfo_ = (DepotInfo) depotInfoService.findByPrimaryKey(depotInfo.getId());
     if (depotInfo==null) return JSONReturn.error(HttpCode.RESULT_EMPTY,"empty");

     Integer result = depotInfoService.update(depotInfo);
     return result > 0 ? JSONReturn.success() : JSONReturn.error(Code.ERROR,
           "Update failed");
  }catch (Exception e){
     return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
  }

}

/**
* 根據主鍵獲取停車場信息
*
* @param request
* @return
*/
@RequestMapping(value = “/get”, method = RequestMethod.GET)
@ResponseBody
public JSONType select(HttpServletRequest request) {
try {
// 1.獲取請求參數
Integer depotInfoId = Integer.parseInt(request.getParameter(“id”));// 停車場主鍵id

     // 2.根據主鍵獲取停車場信息
     DepotInfo depotInfo = (DepotInfo) depotInfoService
           .findByPrimaryKey(depotInfoId);
     
     return depotInfo != null ? JSONReturn.success(depotInfo) : JSONReturn.error(
           Code.ERROR, "empty");

  } catch (Exception e) {
     return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
  }

}

/**
* 分頁查詢停車場信息
* @param request
* @return
*/
@RequestMapping(value = “/list/address”, method = RequestMethod.GET)
@ResponseBody
public JSONType getByPage(HttpServletRequest request) {
try{
Integer page = Integer.valueOf(request.getParameter(“page”));//當前頁
Integer limit = Integer.valueOf(request.getParameter(“limit”));//每頁條數

     page = page == null ? 1 : page;//默認1
     limit = limit == null ? 20 : limit;//默認爲20
     List list = depotInfoService.findByPage(page,limit);
     Long total = depotInfoService.count();//總條數
     Map result = new HashMap();
     result.put("data",list);
     result.put("total",total);
     result.put("pageIndex",page);
     result.put("pageSize",limit);

     return list!=null ? JSONReturn.success(result) :
           JSONReturn.empty("empty");

  }catch (Exception e){
     return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpected error");
  }

}

/**
* 根據經緯度查詢指定範圍的停車場信息
* @param request
* @return
*/
@RequestMapping(value = “/get/position”, method = RequestMethod.GET)
@ResponseBody
public JSONType getByPosition(HttpServletRequest request) {
try{
Double lat = Double.valueOf(request.getParameter(“lat”));//精度
Double lng = Double.valueOf(request.getParameter(“lng”));//緯度
Double len = Double.valueOf(request.getParameter(“len”));//範圍
Integer page = Integer.valueOf(request.getParameter(“page”));
Integer limit = Integer.valueOf(request.getParameter(“limit”));
Integer step = Integer.valueOf(request.getParameter(“step”));//TODO 暫未使用步進發

     if(lat<=0 || lng<=0 || len<=0) return JSONReturn.error(HttpCode.PARAMETER_MISSING,"parameter missing");

     Position position = Distance.calcPosition(lat,lng,len);
     List list = depotInfoService.getByLatAndLon(position,page,limit);
     if(list.isEmpty() || list.size()<limit){
        List list_ = stationStateRedis.getByLatAndLon(position,limit-list.size());
        list.addAll(list_);
     }

     return JSONReturn.success(list);
  }catch (Exception e){
     e.printStackTrace();
     return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
  }

}

/**
* TODO 停車場預約
* @param request
* @return
*/
@RequestMapping(value = “/order”, method = RequestMethod.POST)
@ResponseBody
public JSONType orderStation(HttpServletRequest request) {
try{
Long userId = Long.valueOf(request.getParameter(“uid”));//用戶ID
Long stationId = Long.valueOf(request.getParameter(“sid”));//停車場ID
//1.查詢停車場信息 如果存在
//2.查詢用戶 如果存在
//3.用戶的餘額不能少於停車場的費用
//4.餘額 不足調用支付寶接口充值
return JSONReturn.success();
}catch (Exception e){
return JSONReturn.error(HttpCode.UNEXPETED_ERROR,“unexpeted error”);
}

}

/**
* 根據停車場管理員的id獲取所有的停車場
* @param request
* @return
*/
@RequestMapping(value = “/list”, method = RequestMethod.GET)
@ResponseBody
public JSONType getAll(HttpServletRequest request) {
try{
String uid = request.getParameter(“uid”);
if(ParamValidUtils.isEmpty(uid))
return JSONReturn.error(HttpCode.PARAMETER_MISSING,“uid is required”);

     DepotInfo depotInfo = new DepotInfo();
     depotInfo.setUserId(Long.valueOf(uid));
     List list = depotInfoService.find(depotInfo);
     return JSONReturn.success(list);
  }catch (Exception e){
     return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
  }

}

@RequestMapping(value = “/del”, method = RequestMethod.POST)
@ResponseBody
public JSONType delete(HttpServletRequest request) {
try{
String id = request.getParameter(“id”);
if(ParamValidUtils.isEmpty(id))
return JSONReturn.error(HttpCode.PARAMETER_MISSING,“id is required”);

     Integer rst = depotInfoService.deleteByPrimaryKey(Long.valueOf(id));
     return rst>0 ? JSONReturn.success() :
           JSONReturn.error("failed");
  }catch (Exception e){
     return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
  }

}
}

DepotStationController
package com.cloud.station.controller;

import com.cloud.station.constant.Code;
import com.cloud.station.pojo.DepotStation;
import com.cloud.station.service.DepotStationService;
import com.cloud.station.utils.BeanUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**

  • @className: StationController

  • @data: 2018-03-06

  • @lastModify: 2018-03-06

  • @description: 停車場車位Controller

  • @version v1
    */
    @Controller
    @RequestMapping("/v1/station/parking")
    public class DepotStationController {

    @Autowired
    private DepotStationService depotStationService;

    /**

    • 添加停車場車位基本信息

    • @param request

    •        depotStation 實體屬性
      
    • @return
      */
      @RequestMapping(value = “/add”, method = RequestMethod.POST)
      @ResponseBody
      public JSONType addDepotStation(HttpServletRequest request) {
      try {
      DepotStation depotStation = BeanUtils.toObject(request,DepotStation.class);
      // 1.持久化數據
      depotStation.setId(null);// 主鍵
      depotStation.setCreateTime(new Date().getTime());
      //TODO 要判斷有沒有重複的code
      Integer result = depotStationService.save(depotStation);
      return result > 0 ? JSONReturn.success() : JSONReturn.error(
      Code.ERROR, “Add failed”);

      } catch (Exception e) {
      return JSONReturn.error(Code.ERROR, “failed”);
      }
      }

    /**

    • 刪除停車場車位信息

    • @param request

    • @return
      */
      @RequestMapping(value = “/del”, method = RequestMethod.POST)
      @ResponseBody
      public JSONType delById(HttpServletRequest request) {
      try {
      // 1.獲取請求參數
      Integer depotStationId = Integer.parseInt(request
      .getParameter(“id”));// 停車場車位id

      // 2.更據主鍵刪除停車場信息
      Integer result = depotStationService
      .deleteByPrimaryKey(depotStationId);
      return result > 0 ? JSONReturn.success() : JSONReturn.error(
      Code.ERROR, “Deleted failed”);

      } catch (Exception e) {
      return JSONReturn.error(Code.ERROR, “failed”);
      }
      }

    /**

    • 根據主鍵修改停車場車位基本信息

    • @param request

    • @return
      */
      @RequestMapping(value = “/edit”, method = RequestMethod.POST)
      @ResponseBody
      public JSONType update(HttpServletRequest request, DepotStation depotStation) {
      try {
      // 1.獲取請求參數
      Long depotStationId = Long.parseLong(request.getParameter(“id”));// 主鍵id

      // 2.修改停車場車位信息
      depotStation.setCreateTime(new Date().getTime());

      Integer result = depotStationService.update(depotStation);
      return result > 0 ? JSONReturn.success() : JSONReturn.error(
      Code.ERROR, “failed”);

      } catch (Exception e) {
      return JSONReturn.error(Code.ERROR, “failed”);
      }
      }

    /**

    • 根據主鍵獲取停車場車位信息

    • @param request

    • @return
      */
      @RequestMapping(value = “/get”, method = RequestMethod.GET)
      @ResponseBody
      public JSONType select(HttpServletRequest request) {
      try {
      // 1.獲取請求參數
      Integer depotStationId = Integer.parseInt(request
      .getParameter(“id”));// 停車場主鍵id

      // 2.根據主鍵獲取停車場車位信息
      DepotStation depotStation = (DepotStation) depotStationService
      .findByPrimaryKey(depotStationId);
      return depotStation != null ? JSONReturn.success(depotStation) : JSONReturn
      .error(Code.ERROR, “not exist.”);

      } catch (Exception e) {
      return JSONReturn.error(Code.ERROR, “failed”);
      }
      }
      }

FareController
package com.cloud.station.controller;

import com.cloud.station.constant.Code;
import com.cloud.station.constant.HttpCode;
import com.cloud.station.pojo.FareRule;
import com.cloud.station.service.FareService;
import com.cloud.station.utils.BeanUtils;
import com.cloud.station.utils.ParamValidUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/v1/fare")
public class FareController {

@Autowired
FareService fareService;

@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
public JSONType add(HttpServletRequest request){
    try{
        FareRule fareRule = BeanUtils.toObject(request,FareRule.class);

        if(fareRule==null){
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"paramter missing");
        }
        if(fareRule.getStationId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"station id required");
        if(fareRule.getUserId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"user id required");

        fareRule.setId(null);
        fareRule.setCreateTime(new Date().getTime());

        //查詢當前停車場是否有正在使用的規則
        FareRule fareRule_ = fareService.getUsedByStationId(fareRule.getStationId());

        if(fareRule_!=null){
            fareRule.setUsed(0);//強制設置成未使用
        }

        Integer rst = fareService.save(fareRule);

        if(fareRule_==null)//如果不存在
            return rst==1 ? JSONReturn.success(Code.SUCCESS,"success") :
                    JSONReturn.error(Code.ERROR,"failed");
        else
            return rst==1 ? JSONReturn.success(HttpCode.RESOURCE_RESET,"used is seted UNUSED") :
                    JSONReturn.error(Code.ERROR,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }

}

@RequestMapping(value = "/del", method = RequestMethod.POST)
@ResponseBody
public JSONType deleteById(HttpServletRequest request){
    try{
        String id_ = request.getParameter("id");
        if(ParamValidUtils.isEmpty(id_))
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"id required");

        int rst = fareService.deleteByPrimaryKey(Long.valueOf(id_));

        return rst>0 ? JSONReturn.success(rst) :
                JSONReturn.error(Code.ERROR,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

@RequestMapping(value = "/get", method = RequestMethod.GET)
@ResponseBody
public JSONType getById(HttpServletRequest request){
    try{
        String id_ = request.getParameter("id");
        if(ParamValidUtils.isEmpty(id_))
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"id required");

        FareRule fareRule = (FareRule) fareService.findByPrimaryKey(Long.valueOf(id_));

        return fareRule!=null ? JSONReturn.success(fareRule) :
                JSONReturn.error(Code.ERROR,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public JSONType update(HttpServletRequest request){
    try{
        FareRule fareRule = BeanUtils.toObject(request,FareRule.class);
        if(fareRule==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"error");
        if(fareRule.getId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"id requied");
        if(fareRule.getUserId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"user id requied");
        if(fareRule.getStationId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"station id requied");

        FareRule fareRule_ = fareService.getUsedByStationId(fareRule.getStationId());

        if(fareRule_!=null){
            fareRule.setUsed(0);
        }

        int rst = fareService.update(fareRule);

        if(fareRule_==null)
            return rst>0 ? JSONReturn.success() :
                    JSONReturn.error(Code.ERROR,"failed");
        else
            return rst>0 ? JSONReturn.success("used will be seted 0") :
                    JSONReturn.error(Code.ERROR,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

/**
 * 查詢所有
 * @param request
 * @return
 */
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public JSONType getAll(HttpServletRequest request){
    try{
        String stationId_ = request.getParameter("uid");
        if(ParamValidUtils.isEmpty(stationId_))
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"sid required");

        List<FareRule> list = fareService.getAll(Long.valueOf(stationId_));


        return !list.isEmpty() ? JSONReturn.success(list) :
                JSONReturn.error(HttpCode.RESULT_EMPTY,"empty");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

/**
 * 設置規則爲當前使用的規則
 * @param request
 * @return
 */
@RequestMapping(value = "/update/used", method = RequestMethod.POST)
@ResponseBody
public JSONType updateUsed(HttpServletRequest request){
    try{
        String id_ = request.getParameter("id");
        String used_ = request.getParameter("used");

        Integer used = Integer.valueOf(used_);

        if(ParamValidUtils.isEmpty(id_))
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"id required");

        //used必須是0或者1
        if(used!=0 && used!=1)
            return JSONReturn.error(HttpCode.INVALIED_AUTHORITY,"used valied");

        FareRule fareRule = (FareRule) fareService.findByPrimaryKey(Long.valueOf(id_));
        FareRule usedFareRule = fareService.getUsedByStationId(fareRule.getStationId());

        if(usedFareRule!=null){//存在規則正在被使用
            if(used==1){//修改
                usedFareRule.setUsed(0);
                fareRule.setUsed(1);
            }else{
                fareRule.setUsed(0);
            }
            fareService.update(usedFareRule);
        }else{
            fareRule.setUsed(used);
        }


        int rst = fareService.update(fareRule);

        return rst>0 ? JSONReturn.success("success") :
                JSONReturn.error(Code.ERROR,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

}

FriendController
package com.cloud.station.controller;

import com.cloud.station.constant.Code;
import com.cloud.station.constant.HttpCode;
import com.cloud.station.pojo.Friend;
import com.cloud.station.service.FriendService;
import com.cloud.station.utils.BeanUtils;
import com.cloud.station.utils.ParamValidUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/v1/friend")
public class FriendController {

@Autowired
FriendService friendService;

@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
public JSONType addFriend(HttpServletRequest request){
    try{
        Friend friend = BeanUtils.toObject(request,Friend.class);
        if(friend.getFrendId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"friend id required");
        if(friend.getMyId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"my id required");
        if(friend.getRelative()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"relative required");

        if(friend.getMyId()==friend.getFrendId())
            return JSONReturn.error(HttpCode.INVALIED_AUTHORITY,"parameter invalied");

        friend.setId(null);
        friend.setCreateTime(new Date().getTime());

        List<Friend> friendList = friendService.find(friend);

        int rst = 0;
        if(friendList==null || friendList.isEmpty()){
            rst = friendService.save(friend);
        }else{
            Friend friend_ = friendList.get(0);
            friend_.setCreateTime(new Date().getTime());
            friend_.setRelative(friend.getRelative());

            rst = friendService.update(friend_);
        }

        return rst>0 ? JSONReturn.success(rst) :
                JSONReturn.error(Code.ERROR,"failed");

    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

@RequestMapping(value = "/del", method = RequestMethod.POST)
@ResponseBody
public JSONType delFriend(HttpServletRequest request){
    try{
        Friend friend = BeanUtils.toObject(request,Friend.class);

        if(friend==null)
            return JSONReturn.error(HttpCode.INVALIED_AUTHORITY,"invalied");
        if(friend.getMyId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"user id required");
        if(friend.getFrendId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"friend id required");

        List<Friend> friendList = friendService.find(friend);

        if(friendList==null || friendList.isEmpty()){
            return JSONReturn.error(HttpCode.RESULT_EMPTY,"not exsist");
        }

        int rst = friendService.deleteByPrimaryKey(friendList.get(0).getId());

        return rst>0 ? JSONReturn.success(rst) :
                JSONReturn.error(Code.ERROR,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public JSONType update(HttpServletRequest request){
    try{
        Friend friend = BeanUtils.toObject(request,Friend.class);
        if(friend.getFrendId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"friend id required");
        if(friend.getMyId()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"my id required");
        if(friend.getRelative()==null)
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"relative required");

        if(friend.getMyId()==friend.getFrendId())
            return JSONReturn.error(HttpCode.INVALIED_AUTHORITY,"parameter invalied");

        List<Friend> friendList = friendService.find(friend);

        if(friendList==null || friendList.isEmpty()){
            return JSONReturn.error(HttpCode.NOT_EXSITS,"empty");
        }

        friend.setId(friendList.get(0).getId());

        int rst = friendService.update(friend);

        return rst>0 ? JSONReturn.success(rst) :
                JSONReturn.error(Code.ERROR,"failed");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public JSONType getFriendList(HttpServletRequest request){
    try{
        String page_ = request.getParameter("page");
        String limit_ = request.getParameter("limit");
        String myId_ = request.getParameter("myId");
        String relative_ = request.getParameter("relative");
        String unrelative_ = request.getParameter("unrelative");
        if(ParamValidUtils.isEmpty(page_))page_="1";
        if(ParamValidUtils.isEmpty(limit_))limit_ = "20";

        if(ParamValidUtils.isEmpty(myId_))
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"user id requied");


        Integer page = Integer.valueOf(page_);
        Integer limit = Integer.valueOf(limit_);
        Long myId = Long.valueOf(myId_);
        Integer relative = null;
        Integer unrelative = null;

        if(ParamValidUtils.isNotEmpty(relative_))relative = Integer.valueOf(relative_);
        if(ParamValidUtils.isNotEmpty(unrelative_))unrelative = Integer.valueOf(unrelative_);


        List list = friendService.getFriendList(myId,relative,unrelative,page,limit);
        Long total = friendService.countByFilter(myId,relative,unrelative);
        Map map = new HashMap();
        map.put("data",list);
        map.put("total",total);
        return (list!=null && list.size()>0) ? JSONReturn.success(map) :
                JSONReturn.error(HttpCode.RESULT_EMPTY,"empty");
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"unexpeted error");
    }
}

}

PayController
package com.cloud.station.controller;

import com.cloud.station.constant.HttpCode;
import com.cloud.station.service.PayService;
import com.cloud.station.utils.ParamValidUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@RestController
@RequestMapping("/v1/pay")
public class PayController {

@Autowired
PayService payService;
/**
 * 收費
 * @param request
 * @return
 */
@RequestMapping(value = "/p", method = RequestMethod.POST)
@ResponseBody
public JSONType updateUsed(HttpServletRequest request){
    try{
        String uid = request.getParameter("uid");//用戶ID
        String carNum = request.getParameter("carNum");//車牌
        if(ParamValidUtils.isEmpty(carNum))
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"paramter missing");

        float leftMoney = payService.pay(carNum,new Date().getTime());
        return JSONReturn.success(leftMoney);
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"error");
    }

}

}

StationOrderController
package com.cloud.station.controller;

import com.cloud.station.constant.HttpCode;
import com.cloud.station.mapper.StationOrderMapper;
import com.cloud.station.pojo.StationOrder;
import com.cloud.station.utils.ParamValidUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/v1/stationorder")
public class StationOrderController {

@Autowired
StationOrderMapper stationOrderMapper;

/**
 * 根據停車場ID獲取使用停車場的用戶信息
 * @param request
 * @return
 */
@RequestMapping(value = "/users", method = RequestMethod.GET)
@ResponseBody
public JSONType getAllUsers(HttpServletRequest request){
    try{
        String stationId = request.getParameter("stationId");
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");

        if(ParamValidUtils.isEmpty(stationId))
            return JSONReturn.error(HttpCode.PARAMETER_MISSING,"paramter missing");

        if(ParamValidUtils.isEmpty(page))page="1";
        if(ParamValidUtils.isEmpty(limit))limit="20";

        StationOrder stationOrder = new StationOrder();
        stationOrder.setStationId(Long.valueOf(stationId));

        List list = stationOrderMapper.findUserByEntity(stationOrder,Integer.valueOf(page),Integer.valueOf(limit));

        Map map = new HashMap();
        map.put("total",stationOrderMapper.count());
        map.put("data",list);
        return JSONReturn.success(map);
    }catch (Exception e){
        return JSONReturn.error(HttpCode.UNEXPETED_ERROR,"error");
    }

}

}

UserController
package com.cloud.station.controller;

import com.alibaba.fastjson.JSON;
import com.cloud.station.constant.Code;
import com.cloud.station.constant.ConstantsKey;
import com.cloud.station.constant.HttpCode;
import com.cloud.station.pojo.UserInfo;
import com.cloud.station.service.UserInfoService;
import com.cloud.station.utils.BeanUtils;
import com.cloud.station.utils.CommonUtils;
import com.cloud.station.utils.ParamValidUtils;
import com.cloud.station.utils.PasswordUtils;
import com.cloud.station.utils.result.JSONReturn;
import com.cloud.station.utils.result.JSONType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/v1/user")
public class UserController {
@Autowired
private UserInfoService userInfoService;

/**
* 用戶登陸
* @param request
* account 賬號
* password 密碼
* @return
*/
@RequestMapping(value = “/login”, method = RequestMethod.POST)
public JSONType login(HttpServletRequest request) {
try {
String username = (String) request.getSession().getAttribute(ConstantsKey.LOGIN_SESSION_TOKEN);
if(username!=null)
return JSONReturn.success();

     String account = request.getParameter("account");// 賬號
     String password = request.getParameter("pwd");// 密碼
     if(ParamValidUtils.isEmpty(account) || ParamValidUtils.isEmpty(password))
        return JSONReturn.error(HttpCode.PARAMETER_MISSING,"username and password are required");

     // 2.根據賬戶查詢存儲的密碼
     String realPassword = userInfoService.getPasswordByAccount(account);
     UserInfo userInfo = userInfoService.getUserInfoByAccount(account);
     if(realPassword==null || !PasswordUtils.check(realPassword,password))
        return JSONReturn.error(Code.ERROR,"login failed");

     request.getSession().setAttribute(ConstantsKey.LOGIN_SESSION_TOKEN,account);
     return JSONReturn.success(userInfo.getId());
  } catch (Exception e) {
     return JSONReturn.error(HttpCode.LOGIN_FAILE, "login failed");
  }

}

/**
* 用戶註冊
* @param request
* userInfo User 實體屬性
* @return
*/
@RequestMapping(value = “/reg”, method = RequestMethod.POST)
@ResponseBody
public JSONType register(HttpServletRequest request) {
try {
UserInfo userInfo = BeanUtils.toObject(request,UserInfo.class);

     /**
      * 必要參數驗證
      * a.賬號不能爲空
      * b.密碼不能爲空
      */
     if(ParamValidUtils.isEmpty(userInfo.getAccount()) || ParamValidUtils.isEmpty(userInfo.getPwd()))
        return JSONReturn.error(HttpCode.PARAMETER_MISSING,"parameter missing");

     // 1.驗證手機號格式
     if (!CommonUtils.isTel(userInfo.getAccount()))
        return JSONReturn.error(Code.ERROR, "register failed");

     String oldPwd = userInfo.getPwd();

     // 2.密碼長度驗證
     if (!PasswordUtils.checkLength(oldPwd))// 密碼長度不符合要求
        return JSONReturn.error(HttpCode.PARAMETER_INVALIED,
              "password invalied");
     String newPwd = PasswordUtils.encrpty(oldPwd);// 密碼加密處理

     userInfo.setPwd(newPwd);
     // id爲自動增長
     userInfo.setId(null);
     userInfo.setCreateTime(new Date().getTime());
     // 金額精確到小數點後兩位
     userInfo.setMoney(CommonUtils.keepDecimalDigits(userInfo.getMoney()));

     // 3.持久化數據
     List list=  userInfoService.findByName(userInfo.getAccount());
     if(list!=null && list.size()>0){//用戶存在
        return JSONReturn.error(HttpCode.RESOURCE_EXSISTS,"already exsists");
     }
     Integer result = userInfoService.save(userInfo);

     return result > 0 ? JSONReturn.success() : JSONReturn.error(
           Code.ERROR, "register failed");

  } catch (Exception e) {
     e.printStackTrace();
     return JSONReturn.error(HttpCode.UNEXPETED_ERROR, "unexpeted error");
  }

}

/**
* 獲取用戶基本信息
*
* @param request
* @return
*/
@RequestMapping(value = “/info”, method = RequestMethod.GET)
@ResponseBody
public JSONType getUserInfo(HttpServletRequest request) {
// 1.獲取請求參數
// = (String) request.getSession().getAttribute(ConstantsKey.LOGIN_SESSION_TOKEN);
String uid = request.getParameter(“uid”);
if(ParamValidUtils.isEmpty(uid)){
return JSONReturn.error(HttpCode.PARAMETER_MISSING,“id is required”);
}

  // 2.更據用戶名查詢用戶基本信息
  UserInfo userInfo = (UserInfo) userInfoService.findByPrimaryKey(Long.valueOf(uid));

  return userInfo != null ? JSONReturn.success(userInfo) : JSONReturn
        .error(HttpCode.NOT_EXSITS, "empty");

}

@RequestMapping(value = “/list”, method = RequestMethod.GET)
@ResponseBody
public JSONType getUserList(HttpServletRequest request) {
try{
String page_ = request.getParameter(“page”);
String limit_ = request.getParameter(“limit”);
String type_ = request.getParameter(“type”);

     Integer page = Integer.valueOf(page_);
     Integer limit = Integer.valueOf(limit_);
     Integer type = Integer.valueOf(type_);//管理員類型

     if(ParamValidUtils.isEmpty(page_))page=1;
     if(ParamValidUtils.isEmpty(limit_))limit=20;

     List list = null;
     Long total = 0L;
     list = userInfoService.findByPage(page, limit);
     total = userInfoService.count();

     Map result = new HashMap();
     result.put("data",list);
     result.put("total",total);
     result.put("pageIndex",page);
     result.put("pageSize",limit);

     return !list.isEmpty() ? JSONReturn.success(result):
           JSONReturn.error("empty");
  }catch (Exception e){
     return JSONReturn.error(HttpCode.UNEXPETED_ERROR, "unexpeted error");
  }

}

/**
* 根據賬號查詢
* @param request
* @return
*/
@RequestMapping(value = “/get/account”, method = RequestMethod.GET)
@ResponseBody
public JSONType getByAccount(HttpServletRequest request) {
String account = request.getParameter(“account”);
if(ParamValidUtils.isEmpty(account))
return JSONReturn.error(HttpCode.PARAMETER_MISSING, “account required”);

  UserInfo userInfo = userInfoService.getUserInfoByAccount(account);

  return userInfo!=null ? JSONReturn.success(userInfo) :
        JSONReturn.error(HttpCode.NOT_EXSITS,"empty");

}
}

Service層
Redis
StationStateRedis
package com.cloud.station.service.redis;

import com.cloud.station.constant.ConstantsKey;
import com.cloud.station.pojo.CarNumberUsed;
import com.cloud.station.pojo.DepotInfo;
import com.cloud.station.pojo.DepotStationState;
import com.cloud.station.pojo.dto.CarDTO;
import com.cloud.station.pojo.dto.Position;
import com.cloud.station.service.DepotInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.query.SortQuery;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.concurrent.TimeUnit;

/**

  • 停車場動態信息
    */
    @Service
    public class StationStateRedis {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    DepotInfoService depotInfoService;

    public void save(DepotStationState depotStationState){
    if(depotStationState==null)return;
    //TODO 要定時更新數據到數據庫
    String key = ConstantsKey.STATION_STATE_PREFIX+depotStationState.getStationId()+"";

     //停車場信息
     DepotInfo depotInfo=null;
    
    
     boolean exists=redisTemplate.hasKey(key);
     if(exists){//如果緩存中存在
         DepotStationState temp = (DepotStationState) redisTemplate.opsForValue().get(key);
         if(temp.getDepotInfo()==null){//如果沒有停車場的信息則從數據庫中查詢出來
             //查詢
             depotInfo = (DepotInfo) depotInfoService.findByPrimaryKey(temp.getStationId());
         }else{
             depotInfo = temp.getDepotInfo();
         }
     }else{
         depotInfo = (DepotInfo) depotInfoService.findByPrimaryKey(depotStationState.getStationId());
     }
     depotStationState.setDepotInfo(depotInfo);
    
     redisTemplate.opsForValue().getAndSet(key,depotStationState);
    

    }

    /**

    • 存儲車牌信息
    • @param carDTO
      */
      public void saveCarNumber(CarDTO carDTO){
      redisTemplate.opsForValue().getAndSet(carDTO.getNumber(),carDTO);
      }

    /**

    • 根據主鍵查詢
    • @param key_
    • @return
      */
      public DepotStationState getByKey(Object key_){
      String key = ConstantsKey.STATION_STATE_PREFIX+key_;
      boolean exists=redisTemplate.hasKey(key);
      if(exists)
      return (DepotStationState) redisTemplate.opsForValue().get(key);
      else
      return null;
      }

    /**

    • 根據經緯度從緩存查詢

    • @param position 位置信息

    • @param n 個數

    • @return
      */
      public List getByLatAndLon(Position position,Integer n){

      List list = new ArrayList<>();//容器

      List temp = new ArrayList<>();//臨時容器

      Set s = redisTemplate.keys(ConstantsKey.STATION_STATE_PREFIX+"*");

      Iterator iterator = s.iterator();

      while (iterator.hasNext()){//獲取所有內容到臨時容器中
      String key = (String) iterator.next();
      DepotStationState depotStationState = (DepotStationState) redisTemplate.opsForValue().get(key);
      temp.add(depotStationState);
      }

      //TODO redis數據排序
      Collections.sort(temp, new Comparator() {
      @Override
      public int compare(DepotStationState o1, DepotStationState o2) {
      return o2.getLeft()-o1.getLeft();
      }
      });

      Integer i = 0;
      for(DepotStationState ds:temp){
      DepotInfo depotInfo = ds.getDepotInfo();
      if(depotInfo!=null){
      Double lat = depotInfo.getLatitude();
      Double lng = depotInfo.getLongitude();
      if(lat>=position.getLeftBottomLat() && lat<=position.getLeftTopLat() &&
      lng>position.getLeftTopLng() && lng<=position.getRightTopLng()){
      list.add(depotInfo);
      i++;
      if(i>=n)break;
      }
      }
      }

      return list;
      }

}

cache
impl
SocketManagerImple
package com.cloud.station.service.cache.impl;

import com.cloud.station.service.cache.SocketManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.net.Socket;
import java.util.*;

@Service(“socketManager”)
public class SocketManagerImple implements SocketManager{
private final Map<String, Socket> enties = new HashMap<>();
private final String NAMESPACE = “socketManager”;
@Autowired
private CacheManager cacheManager;

@Override
@CachePut(cacheNames = NAMESPACE)
public void add(Socket socket) {
    enties.put(socket.getInetAddress().toString(), socket);
}

@Override
@CacheEvict(cacheNames = NAMESPACE)
public void delete(String key) {
     enties.remove(key);
}

@Override
public void clear() {
    //TODO 清空所有的Socket連接未實現
}

@Override
@Cacheable(cacheNames = NAMESPACE)
public Socket get(String key) {
    return enties.get(key);
}

@Override
@CachePut(cacheNames = NAMESPACE)
public void update(Socket socket) {
    enties.put(socket.getInetAddress().toString(),socket);
}

@Override
public Integer count() {
    return enties.size();
}

@Override
@Cacheable(cacheNames = NAMESPACE)
public List getOtherSocket(Socket socket) {
    List list = new ArrayList();
    String key = socket.getInetAddress().toString();

    Iterator iterator=enties.values().iterator();
    while (iterator.hasNext()){
        list.add(iterator.next());
    }
    return list;
}

}

SocketManager
package com.cloud.station.service.cache;

import java.net.Socket;
import java.util.List;
import java.util.Map;

/**

  • socket連接管理類
    */
    public interface SocketManager {

    public void add(Socket socket);//z增加一個socket

    public void delete(String key);//刪除一個socket

    public void clear();//清空所有的Socket連接

    public Socket get(String key);//根據key查詢指定的Socket

    public void update(Socket socket);//更新

    public Integer count();//統計總數

    public List getOtherSocket(Socket socket);//獲得其他的Socket連接
    }

AddressService
package com.cloud.station.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.cloud.station.base.BaseService;
import com.cloud.station.pojo.Address;
import com.cloud.station.pojo.UserInfo;

/**

  • @className: AddressService
  • @data: 2018-03-07
  • @lastModify: 2018-03-07
  • @description: 地址信息 service接口
    */
    public interface AddressService extends BaseService {

}

AdminInfoService
package com.cloud.station.service;

import java.util.List;

import com.cloud.station.pojo.DepotAdminInfo;
import org.springframework.stereotype.Service;

import com.cloud.station.base.BaseService;
import com.cloud.station.pojo.Address;
import com.cloud.station.pojo.AdminInfo;
import com.cloud.station.pojo.UserInfo;

/**

  • @className: AdminInfoService

  • @data: 2018-03-07

  • @lastModify: 2018-03-07

  • @description: 系統管理員service接口
    /
    public interface AdminInfoService extends BaseService {
    /
    *

    • 根據用戶名查詢密碼
    • @param account
    • @return
      */
      public String getPasswordByAccount(String account);

    /**

    • 根據用戶名查詢用戶的基本信息
    • @param account
    • @return
      */
      public AdminInfo getDepotAdminInfoByAccount(String account);
      }

AppService
package com.cloud.station.service;

import com.cloud.station.base.BaseService;

/**

  • @className: AppService

  • @data: 2018-03-06

  • @lastModify: 2018-03-06

  • @description: 手機APP公共Service接口
    */
    public interface AppService extends BaseService {

    /**

    • 獲取對應平臺最新的APP版本
    • @param platform 平臺
    • @return
      */
      public String getLastVersion(String platform);

    /**

    • 更新手機APP版本
    • @param platform 平臺
    • @param version 版本
    • @return
      */
      public String updateApp(String platform, String version);

    /**

    • 下載APP
    • @param platform 平臺
    • @param version 版本
    • @return
      */
      public String dowloadApp(String platform, String version);
      }

CarInfoService
package com.cloud.station.service;

import com.cloud.station.pojo.CarInfo;

import java.util.List;

public interface CarInfoService {

/**
 * 根據實體查詢
 * @return
 */
public List get(CarInfo carInfo,Integer page,Integer limit);

/**
 * 統計總記錄數
 * @param carInfo
 * @return
 */
public Long count(CarInfo carInfo);

/**
 * 添加
 * @param carInfo
 * @return
 */
public Integer add(CarInfo carInfo);

}

CarNumberBlackListService
package com.cloud.station.service;

import com.cloud.station.base.BaseService;
import com.cloud.station.pojo.CarNumberBlacklist;

import java.util.List;

public interface CarNumberBlackListService extends BaseService{

/**
 * 根據車牌查詢
 * @param carNumber
 * @return
 */
public List<CarNumberBlacklist> getByCarNumber(String carNumber,Integer page,Integer limit);


public Long countFilterByCarNum(String carNum);

}

DepotAdminInfoService
package com.cloud.station.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.cloud.station.base.BaseService;
import com.cloud.station.pojo.Address;
import com.cloud.station.pojo.AdminInfo;
import com.cloud.station.pojo.DepotAdminInfo;
import com.cloud.station.pojo.UserInfo;

/**

  • @className: DepotAdminInfoService

  • @data: 2018-03-07

  • @lastModify: 2018-03-07

  • @description: 停車場管理員service接口
    */
    public interface DepotAdminInfoService extends BaseService {

    /**

    • 根據用戶名查詢密碼
    • @param account
    • @return
      */
      public String getPasswordByAccount(String account);

    /**

    • 根據用戶名查詢用戶的基本信息
    • @param account
    • @return
      */
      public DepotAdminInfo getDepotAdminInfoByAccount(String account);
      }

DepotFareStandardService
package com.cloud.station.service;

import com.cloud.station.pojo.CarInfo;

/**

  • 收費標準Service
    */
    public interface DepotFareStandardService {

    /**

    • 根據車信息計費
    • @param carInfo
    • @return
      */
      public Float calculateFare(CarInfo carInfo);
      }

DepotInfoService
package com.cloud.station.service;

import java.util.List;

import com.cloud.station.pojo.dto.Position;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.station.base.BaseService;
import com.cloud.station.mapper.DepotInfoMapper;
import com.cloud.station.pojo.Address;
import com.cloud.station.pojo.AdminInfo;
import com.cloud.station.pojo.DepotAdminInfo;
import com.cloud.station.pojo.DepotInfo;
import com.cloud.station.pojo.UserInfo;

/**

  • @className: DepotInfoService
  • @data: 2018-03-07
  • @lastModify: 2018-03-07
  • @description: 停車場基本信息service接口
    */

public interface DepotInfoService extends BaseService {

/**
 * 根據經緯度查詢
 * @param position 經緯度範圍
 * @param skip   跳過記錄條數
 * @param limit  每頁條數
 * @return
 */
public List getByLatAndLon(Position position, int skip, int limit);

/**
 * 根據經緯度查詢
 * @param lat 中心經緯
 * @Param lng  中心緯度
 * @Param dis  中心覆蓋距離
 * @param skip   跳過記錄條數
 * @param limit  每頁條數
 * @return
 */
public List getByLatAndLon(double lat,double lng,double dis, int skip, int limit);

/**
 * 根據車牌查找實體
 * @param carNum
 * @return
 */
public DepotInfo getByCarNumber(String carNum);

}

DepotStationService
package com.cloud.station.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.cloud.station.base.BaseService;
import com.cloud.station.pojo.DepotStation;
import com.cloud.station.pojo.DepotState;

/**

  • @className: DepotStateService
  • @data: 2018-03-07
  • @lastModify: 2018-03-07
  • @description: 停車場車位信息service接口
    */

public interface DepotStationService extends BaseService {

}

DepotStationStateService
package com.cloud.station.service;

import com.cloud.station.base.BaseService;
import com.cloud.station.pojo.dto.MapAddressDTO;
import java.util.List;

public interface DepotStationStateService extends BaseService{

/**
 * 根據地址查找停車場的狀態信息包括停車場的基本信息
 * @param mapAddressDTO
 * @return
 */
public List findByMapAddress(MapAddressDTO mapAddressDTO);

}

FareService
package com.cloud.station.service;

import com.cloud.station.base.BaseService;
import com.cloud.station.fare.entity.Rule;
import com.cloud.station.pojo.FareRule;

import java.util.List;

public interface FareService extends BaseService{

/**
 * 查詢停車場當前正在使用的規則
 * @param stationId
 * @return
 */
public FareRule getUsedByStationId(Long stationId);

/**
 * 根據停車場ID查詢所有
 * @param stationId
 * @return
 */
public List<FareRule> getAll(Long stationId);

/**
 * 停車場計費
 * @param rule
 * @return
 */
public float calc(Rule rule);

}

FriendService
package com.cloud.station.service;

import com.cloud.station.base.BaseService;
import com.cloud.station.pojo.ex.FriendEx;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface FriendService extends BaseService{

/**
 * 獲取好友列表
 * @param myId
 * @param relative
 * @param unrelative
 * @param page
 * @param limit
 * @return
 */
public List<FriendEx> getFriendList(Long myId,Integer relative,
                                    Integer unrelative,Integer page,
                                    Integer limit);

/**
 * 條件查詢總數
 * @param myId
 * @param relative
 * @param unrelative
 * @return
 */
public Long  countByFilter(Long myId,Integer relative,
                                    Integer unrelative);

}

PayService
package com.cloud.station.service;

/**

  • @className: PayService

  • @data: 2018-03-10

  • @lastModify: 2018-03-10

  • @description: 賬號充值Service
    */
    public interface PayService {

    /**

    • 根據車牌扣費
    • @param carNumber 車牌
    • @param endTime 結束時間
    • @return
      */
      public float pay(String carNumber,Long endTime);

    /**

    • 根據停車和停車場ID付款
    • @param stationId
    • @param carNum
    • @return 返回總消費金額
      */
      public float pay(Long stationId,String carNum);
      }

StationOrderService
package com.cloud.station.service;

import com.cloud.station.pojo.StationOrder;

import java.util.List;

public interface StationOrderService {

/**
 * 添加訂單
 * @param stationId
 * @param carNumber
 * @return
 */
public Integer addByCarNum(Long stationId,String carNumber);

/**
 * 更新實體
 * @param stationOrder
 * @return
 */
public Integer update(StationOrder stationOrder);

/**
 * 根據車牌查詢
 * @param carNum
 * @return
 */
public StationOrder getByCarNumber(String carNum);

/**
 * 根據停車場ID和車牌查詢
 * @param stationId
 * @param carNum
 * @return
 */
public StationOrder getByStationIdAndCarNuber(Long stationId,String carNum);

/**
 * 查看歷史信息
 * @param carNum
 * @return
 */
public List<StationOrder> getHistory(String carNum);

}

UserInfoService
package com.cloud.station.service;

import java.util.List;

import com.cloud.station.base.BaseService;
import com.cloud.station.pojo.UserInfo;

/**

  • @className: UserInfoService

  • @data: 2018-03-07

  • @lastModify: 2018-03-07

  • @description: 用戶基本信息 service接口
    /
    public interface UserInfoService extends BaseService {
    /
    *

    • 根據用戶名查詢密碼
    • @param account
    • @return
      */
      public String getPasswordByAccount(String account);

    /**

    • 根據用戶名查詢用戶的基本信息
    • @param account
    • @return
      */
      public UserInfo getUserInfoByAccount(String account);

    /**

    • 增加一條記錄
    • @param userInfo 實體
    • @return 影響記錄條數
      */
      public Integer save(UserInfo userInfo);

}

Service實現層
AddressServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.mapper.AddressMapper;
import com.cloud.station.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(“addressService”)
public class AddressServiceImpl extends BaseServiceImpl implements AddressService {

@Autowired
AddressMapper addressMapper;
/**
 * 查詢
 *
 * @param entity 實體
 * @return List    集合
 * @
 */
@Override
public List find(Object entity) {
    try {
        return addressMapper.find(entity);
    } catch (Exception e) {
        return null;
    }
}

/**
 * 增加一條記錄
 *
 * @param entity 實體
 * @return 影響記錄條數
 * @
 */
@Override
public Integer save(Object entity) {
    try {
        return addressMapper.insert(entity);
    } catch (Exception e) {
        return 0;
    }
}

/**
 * 更具主鍵查詢一條記錄
 *
 * @param obj 主鍵
 * @return 對象實體
 * @
 */
@Override
public Object findByPrimaryKey(Object obj) {
    try {
        return addressMapper.findByPrimaryKey(obj);
    } catch (Exception e) {
        return null;
    }
}

}

AdminInfoServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.mapper.AdminInfoMapper;
import com.cloud.station.pojo.AdminInfo;
import com.cloud.station.service.AdminInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(“adminInfoService”)
public class AdminInfoServiceImpl extends BaseServiceImpl implements AdminInfoService{

@Autowired
AdminInfoMapper adminInfoMapper;
/**
 * 根據用戶名查詢密碼
 *
 * @param account
 * @return
 */
@Override
public String getPasswordByAccount(String account) {
    try {
        return adminInfoMapper.findPasswordByAccount(account);
    } catch (Exception e) {
        return null;
    }
}

/**
 * 根據用戶名查詢用戶的基本信息
 *
 * @param account
 * @return
 */
@Override
public AdminInfo getDepotAdminInfoByAccount(String account) {
    try{
        return (AdminInfo) (adminInfoMapper.findByName(account)).get(0);
    }catch(Exception e){
        return null;
    }
}

/**
 * 更具主鍵查詢一條記錄
 *
 * @param obj 主鍵
 * @return 對象實體
 * @
 */
@Override
public Object findByPrimaryKey(Object obj) {
    try {
        return adminInfoMapper.findByPrimaryKey(obj);
    } catch (Exception e) {
        return null;
    }
}

}

AppServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.service.AppService;

import java.util.List;

/**

  • @className: AppServiceImpl

  • @data: 2018-03-06

  • @lastModify: 2018-03-06

  • @description: 手機APP公共Service實現類
    */
    public class AppServiceImpl extends BaseServiceImpl implements AppService{

    /**

    • 獲取對應平臺最新的APP版本
    • @param platform 平臺
    • @return
      */
      @Override
      public String getLastVersion(String platform) {
      //從數據庫查詢
      return null;
      }

    /**

    • 更新手機APP版本
    • @param platform 平臺
    • @param version 版本
    • @return
      */
      @Override
      public String updateApp(String platform,String version){
      //TODO 實現APK下載更新
      //暫時不用實現
      return null;
      }

    /**

    • 下載APP
    • @param platform 平臺
    • @param version 版本
    • @return
      */
      @Override
      public String dowloadApp(String platform, String version) {
      //TODO 下載APK
      //暫時不用實現
      return null;
      }

    //Override

    /**

    • 增加一條記錄
    • @param entity 實體
    • @return 影響記錄條數
    • @
      */
      @Override
      public Integer save(Object entity) {
      return super.save(entity);
      }

    /**

    • 刪除一條記錄
    • @param pk 主鍵或對象
    • @return 影響記錄條數
    • @
      */
      @Override
      public Integer delete(Object pk) {
      return super.delete(pk);
      }

    /**

    • 更新一條記錄
    • @param entity 實體
    • @return 影響記錄條數
    • @
      */
      @Override
      public Integer update(Object entity) {
      return super.update(entity);
      }

    /**

    • 查詢
    • @param entity 實體
    • @return List 集合
    • @
      */
      @Override
      public List find(Object entity) {
      return super.find(entity);
      }

    /**

    • 增加或更新一條記錄
    • @param entity 實體
    • @return 影響記錄條數
    • @
      */
      @Override
      public Integer saveOrUpdate(Object entity) {
      return super.saveOrUpdate(entity);
      }

    /**

    • 根據主鍵刪除一條記錄
    • @param pk 主鍵
    • @return 影響記錄條數
    • @
      */
      @Override
      public Integer deleteByPrimaryKey(Object pk) {
      return super.deleteByPrimaryKey(pk);
      }

    /**

    • 根據名稱刪除
    • @param name
    • @return
    • @
      */
      @Override
      public Integer deleteByName(String name) {
      return super.deleteByName(name);
      }

    /**

    • 更具主鍵查詢一條記錄
    • @param obj 主鍵
    • @return 對象實體
    • @
      */
      @Override
      public Object findByPrimaryKey(Object obj) {
      return super.findByPrimaryKey(obj);
      }
      }

CarInfoServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.mapper.CarInfoMapper;
import com.cloud.station.pojo.CarInfo;
import com.cloud.station.service.AppService;
import com.cloud.station.service.CarInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**

  • @className: AppServiceImpl

  • @data: 2018-03-06

  • @lastModify: 2018-03-06

  • @description: 手機APP公共Service實現類
    */
    @Service(“carInfoService”)
    public class CarInfoServiceImpl implements CarInfoService{

    @Autowired
    CarInfoMapper carInfoMapper;

    /**

    • 根據實體查詢
    • @param carInfo
    • @return
      */
      @Override
      public List get(CarInfo carInfo,Integer page,Integer limit) {
      try {
      return carInfoMapper.find(carInfo,(page-1)*limit,limit);
      } catch (Exception e) {
      return null;
      }
      }

    /**

    • 統計總記錄數
    • @param carInfo
    • @return
      */
      @Override
      public Long count(CarInfo carInfo) {
      try {
      return carInfoMapper.count(carInfo);
      } catch (Exception e) {
      return 0L;
      }
      }

    /**

    • 添加
    • @param carInfo
    • @return
      */
      @Override
      public Integer add(CarInfo carInfo) {
      try {
      return carInfoMapper.insert(carInfo);
      } catch (Exception e) {
      return 0;
      }
      }
      }

CarNumberBlackListServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.mapper.CarNumberBlacklistMapper;
import com.cloud.station.pojo.CarNumberBlacklist;
import com.cloud.station.service.CarNumberBlackListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(“carNumberBlackListService”)
public class CarNumberBlackListServiceImpl extends BaseServiceImpl
implements CarNumberBlackListService{

@Autowired
CarNumberBlacklistMapper carNumberBlacklistMapper;

/**
 * 根據車牌查詢
 *
 * @param carNumber
 * @return
 */
@Override
public List<CarNumberBlacklist> getByCarNumber(String carNumber,Integer page,Integer limit) {
    try {
        return carNumberBlacklistMapper.getByCarNumber(carNumber,(page-1)*limit,limit);
    } catch (Exception e) {
        return null;
    }
}

@Override
public Long countFilterByCarNum(String carNum) {
    try {
        return carNumberBlacklistMapper.countByFilterCarNum(carNum);
    } catch (Exception e) {
        return 0L;
    }
}

/**
 * 更新一條記錄
 *
 * @param entity 實體
 * @return 影響記錄條數
 * @
 */
@Override
public Integer update(Object entity) {
    try {
        return carNumberBlacklistMapper.update(entity);
    } catch (Exception e) {
        return 0;
    }
}

/**
 * 增加一條記錄
 *
 * @param entity 實體
 * @return 影響記錄條數
 * @
 */
@Override
public Integer save(Object entity) {
    try {
        return carNumberBlacklistMapper.insert(entity);
    } catch (Exception e) {
        return 0;
    }
}

/**
 * 根據主鍵刪除一條記錄
 *
 * @param pk 主鍵
 * @return 影響記錄條數
 * @
 */
@Override
public Integer deleteByPrimaryKey(Object pk) {
    try {
        return carNumberBlacklistMapper.deleteByPrimaryKey(pk);
    } catch (Exception e) {
        return 0;
    }
}

/**
 * 更具主鍵查詢一條記錄
 *
 * @param obj 主鍵
 * @return 對象實體
 * @
 */
@Override
public Object findByPrimaryKey(Object obj) {
    try {
        return carNumberBlacklistMapper.findByPrimaryKey(obj);
    } catch (Exception e) {
        return null;
    }
}

}

DepotAdminInfoServiceImpl
package com.cloud.station.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.mapper.DepotAdminInfoMapper;
import com.cloud.station.pojo.AdminInfo;
import com.cloud.station.pojo.DepotAdminInfo;
import com.cloud.station.service.DepotAdminInfoService;

@Service(“depotAdminInfoService”)
public class DepotAdminInfoServiceImpl extends BaseServiceImpl implements DepotAdminInfoService{

@Autowired
private DepotAdminInfoMapper depotAdminInfoMapper;

/**
* 增加一條記錄
*
* @param entity 實體
* @return 影響記錄條數
* @
*/
@Override
public Integer save(Object entity) {
try {
Integer result = depotAdminInfoMapper.insert(entity);
return result;
} catch (Exception e) {
return 0;//插入異常,返回0
}
}

/**
* 根據主鍵刪除一條記錄
* @param id
* @return 影響記錄條數
*/
public Integer delete(Integer id) {
try {
Integer result = depotAdminInfoMapper.deleteByPrimaryKey(id);
return result;
} catch (Exception e) {
return 0;//刪除異常,返回0
}
}

/**
* 根據主鍵更新一條記錄
* @param depotAdminInfo
* @return
*/
public Integer update(DepotAdminInfo depotAdminInfo) {
try {
Integer result = depotAdminInfoMapper.update(depotAdminInfo);
return result;
} catch (Exception e) {
return 0;//更新異常,返回0
}
}

/**
* 更具主鍵查詢一條記錄
*
* @param obj 主鍵
* @return 對象實體
* @
*/
@Override
public Object findByPrimaryKey(Object obj) {
try {
return depotAdminInfoMapper.findByPrimaryKey(obj);
} catch (Exception e) {
return null;//查詢異常,返回0
}
}

/**************************************
   * depotAdminInfoService
  *************************************/
/**
 * 根據賬號查詢密碼
 * @param account
 * @return
 */
  public String getPasswordByAccount(String account) {
     try {
        String password = depotAdminInfoMapper.findPasswordByAccount(account);
        return password;
     } catch (Exception e) {
        return null;
     }
  }

/**
* 根據用戶名查詢用戶的基本信息
*
* @param account
* @return
*/
@Override
public DepotAdminInfo getDepotAdminInfoByAccount(String account) {
try{
return (DepotAdminInfo) (depotAdminInfoMapper.findByName(account)).get(0);
}catch(Exception e){
return null;
}
}
}

DepotFareStandardServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.pojo.CarInfo;
import com.cloud.station.pojo.DepotFareStandard;
import com.cloud.station.service.DepotFareStandardService;

public class DepotFareStandardServiceImpl implements DepotFareStandardService{
/**
* 根據車信息計費
*
* @param carInfo
* @return
*/
@Override
public Float calculateFare(CarInfo carInfo) {
return null;
}

}

DepotInfoServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.algorithm.Distance;
import com.cloud.station.pojo.dto.Position;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.mapper.DepotInfoMapper;
import com.cloud.station.pojo.DepotInfo;
import com.cloud.station.service.DepotInfoService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service(“depotInfoService”)
public class DepotInfoServiceImpl extends BaseServiceImpl
implements DepotInfoService{

@Autowired
private DepotInfoMapper depotInfoMapper;

/**
* 增加一條記錄
* @param entity 實體
* @return 影響記錄條數
* @
*/
@Override
public Integer save(Object entity){
try{
Integer result = depotInfoMapper.insert(entity);
return result;
}catch(Exception e){
return 0;
}

}

/**
* 更新一條記錄
* @param entity 實體
* @return 影響記錄條數
*/
@Override
public Integer update(Object entity){
try{
Integer result = depotInfoMapper.update(entity);
return result;
}catch(Exception e){
return 0;
}
}

/**
* 根據主鍵刪除一條記錄
* @param id 主鍵
* @return 影響記錄條數
* @
*/
public Integer deleteByPrimaryKey(Integer id){
try{
Integer result = depotInfoMapper.deleteByPrimaryKey(id);
return result;
}catch(Exception e){
return 0;
}
}

/**
* 更具主鍵查詢一條記錄
*
* @param obj 主鍵
* @return 對象實體
* @
*/
@Override
public Object findByPrimaryKey(Object obj) {
try{
return depotInfoMapper.findByPrimaryKey(obj);
}catch(Exception e){
return null;
}
}

/**
* 根據名稱精確查找
*
* @param name 名稱
* @return
* @
*/
@Override
public List findByName(String name) {
try {
return depotInfoMapper.findByName(name);
} catch (Exception e) {
return null;
}
}

/**
* 分頁查詢
*
* @param skip 跳過記錄數
* @param limit 每頁記錄查詢條數
* @return 集合
* @
*/
@Override
public List findByPage(Integer skip, Integer limit) {
try {
return depotInfoMapper.findByPage((skip-1)*limit,limit);
} catch (Exception e) {
return null;
}
}

/**
* 根據經緯度查詢
*
* @param position 經緯度範圍
* @param skip 跳過記錄條數
* @param limit 每頁條數
* @return
*/
public List getByLatAndLon(Position position, int skip, int limit) {
try {
return depotInfoMapper.findByLatAndLon(position,(skip-1)*limit,limit);
} catch (Exception e) {
return null;
}
}

/**
* 根據經緯度查詢
*
* @param lat 中心經緯
* @param lng
* @param dis
* @param skip 跳過記錄條數
* @param limit 每頁條數 @Param lng 中心緯度
* @return
* @Param dis 中心覆蓋距離
*/
@Override
public List getByLatAndLon(double lat, double lng, double dis, int skip, int limit) {
Position position = Distance.calcPosition(lat,lng,dis);
try {
return depotInfoMapper.findByLatAndLon(position,(skip-1)*limit,limit);
} catch (Exception e) {
return null;
}
}

/**
* 根據車牌查找實體
*
* @param carNum
* @return
*/
@Override
public DepotInfo getByCarNumber(String carNum) {
DepotInfo depotInfo = new DepotInfo();
depotInfo.setName(carNum);
return (DepotInfo) find(depotInfo);
}

/**
* 查詢
*
* @param entity 實體
* @return List 集合
* @
*/
@Override
public List find(Object entity) {
try {
return depotInfoMapper.find(entity);
} catch (Exception e) {
return null;
}
}

/**
* 根據主鍵刪除一條記錄
*
* @param pk 主鍵
* @return 影響記錄條數
* @
*/
@Override
public Integer deleteByPrimaryKey(Object pk) {
try {
return depotInfoMapper.deleteByPrimaryKey(pk);
} catch (Exception e) {
return 0;
}
}

/**
* 統計總記錄條數
*
* @return 總記錄數
* @
*/
@Override
public Long count() {
try {
return depotInfoMapper.count();
} catch (Exception e) {
return 0L;
}
}
}

DepotStationServiceImpl
package com.cloud.station.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.mapper.DepotStationMapper;
import com.cloud.station.pojo.DepotStation;
import com.cloud.station.service.DepotStationService;
import com.cloud.station.service.DepotStationService;

@Service(“depotStationService”)
public class DepotStationServiceImpl extends BaseServiceImpl implements
DepotStationService {

@Autowired
private DepotStationMapper depotStationMapper;

/**
* 增加一條記錄
*
* @param entity 實體
* @return 影響記錄條數
* @
*/
@Override
public Integer save(Object entity) {
try {
return depotStationMapper.insert(entity);
} catch (Exception e) {
return 0;
}
}

/**
* 更新一條記錄
*
* @param entity 實體
* @return 影響記錄條數
* @
*/
@Override
public Integer update(Object entity) {
try {
Integer result = depotStationMapper.update(entity);
return result;
} catch (Exception e) {
return 0;
}
}

/**
* 根據主鍵刪除一條記錄
*
* @param pk 主鍵
* @return 影響記錄條數
* @
*/
@Override
public Integer deleteByPrimaryKey(Object pk) {
try {
Integer result = depotStationMapper.deleteByPrimaryKey(pk);
return result;
} catch (Exception e) {
return 0;
}
}

/**
* 更具主鍵查詢一條記錄
*
* @param obj 主鍵
* @return 對象實體
* @
*/
@Override
public Object findByPrimaryKey(Object obj) {
try {

     return depotStationMapper.findByPrimaryKey(obj);
  } catch (Exception e) {
     return null;
  }

}
}

DepotStationStateServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.mapper.DepotStationStateMapper;
import com.cloud.station.pojo.DepotStationState;
import com.cloud.station.pojo.dto.MapAddressDTO;
import com.cloud.station.service.DepotStationStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.ListIterator;

@Service(“depotStationStateService”)
public class DepotStationStateServiceImpl extends BaseServiceImpl implements DepotStationStateService {

@Autowired
DepotStationStateMapper depotStationStateMapper;
/**
 * 增加一條記錄
 *
 * @param entity 實體
 * @return 影響記錄條數
 * @
 */
@Override
public Integer save(Object entity) {
    try {
       return depotStationStateMapper.insert(entity);
    } catch (Exception e) {
        return 0;
    }
}

/**
 * 增加或更新一條記錄
 *
 * @param entity 實體
 * @return 影響記錄條數
 * @
 */
@Override
public Integer saveOrUpdate(Object entity) {
    Integer rst = 0;
    try {
        DepotStationState depotStationState = (DepotStationState) depotStationStateMapper.find(entity);

        if(depotStationState!=null)
            rst =depotStationStateMapper.update(entity);
        else
            rst = depotStationStateMapper.insert(entity);
    } catch (Exception e) {
        rst = 0;
    }
    return rst;
}

/**
 * 根據地址查找停車場的狀態信息包括停車場的基本信息
 *
 * @param mapAddressDTO
 * @return
 */
@Override
public List findByMapAddress(MapAddressDTO mapAddressDTO) {

    return null;
}

}

FareServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.fare.api.ChargeApi;
import com.cloud.station.fare.entity.Rule;
import com.cloud.station.mapper.FareRuleMapper;
import com.cloud.station.pojo.FareRule;
import com.cloud.station.service.FareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(“fareService”)
public class FareServiceImpl extends BaseServiceImpl implements FareService{

@Autowired
FareRuleMapper fareRuleMapper;

/**
 * 增加一條記錄
 *
 * @param entity 實體
 * @return 影響記錄條數
 * @
 */
@Override
public Integer save(Object entity) {
    try {
        return fareRuleMapper.insert(entity);
    } catch (Exception e) {
        return 0;
    }
}

/**
 * 查詢停車場當前正在使用的規則
 *
 * @param stationId
 * @return
 */
@Override
public FareRule getUsedByStationId(Long stationId) {
    try {
        return fareRuleMapper.getUsedByStationId(stationId);
    } catch (Exception e) {
        return null;
    }
}

/**
 * 根據停車場ID查詢所有
 *
 * @param stationId
 * @return
 */
@Override
public List<FareRule> getAll(Long stationId) {
    try {
        return fareRuleMapper.getAll(stationId);
    } catch (Exception e) {
        return null;
    }
}

/**
 * 停車場計費
 *
 * @param rule
 * @return
 */
@Override
public float calc(Rule rule) {
    return (new ChargeApi(rule)).calc();
}

/**
 * 根據主鍵刪除一條記錄
 *
 * @param pk 主鍵
 * @return 影響記錄條數
 * @
 */
@Override
public Integer deleteByPrimaryKey(Object pk) {
    try {
        return fareRuleMapper.deleteByPrimaryKey(pk);
    } catch (Exception e) {
        return 0;
    }
}

/**
 * 更具主鍵查詢一條記錄
 *
 * @param obj 主鍵
 * @return 對象實體
 * @
 */
@Override
public Object findByPrimaryKey(Object obj) {
    try {
        return fareRuleMapper.findByPrimaryKey(obj);
    } catch (Exception e) {
        return null;
    }
}

/**
 * 更新一條記錄
 *
 * @param entity 實體
 * @return 影響記錄條數
 * @
 */
@Override
public Integer update(Object entity) {
    try {
        return fareRuleMapper.update(entity);
    } catch (Exception e) {
        return 0;
    }
}

}

FriendServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.base.impl.BaseServiceImpl;
import com.cloud.station.mapper.FriendMapper;
import com.cloud.station.pojo.ex.FriendEx;
import com.cloud.station.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(“friendService”)
public class FriendServiceImpl extends BaseServiceImpl implements FriendService {

@Autowired
FriendMapper friendMapper;

/**
 * 增加一條記錄
 *
 * @param entity 實體
 * @return 影響記錄條數
 * @
 */
@Override
public Integer save(Object entity) {
    try {
        return friendMapper.insert(entity);
    } catch (Exception e) {
        return 0;
    }
}

/**
 * 更新一條記錄
 *
 * @param entity 實體
 * @return 影響記錄條數
 * @
 */
@Override
public Integer update(Object entity) {
    try {
        return friendMapper.update(entity);
    } catch (Exception e) {
        return 0;
    }
}

/**
 * 查詢
 *
 * @param entity 實體
 * @return List    集合
 * @
 */
@Override
public List find(Object entity) {
    try {
        return friendMapper.find(entity);
    } catch (Exception e) {
        return null;
    }
}

/**
 * 根據主鍵刪除一條記錄
 *
 * @param pk 主鍵
 * @return 影響記錄條數
 * @
 */
@Override
public Integer deleteByPrimaryKey(Object pk) {
    try {
        return friendMapper.deleteByPrimaryKey(pk);
    } catch (Exception e) {
        return 0;
    }
}


/**
 * 獲取好友列表
 *
 * @param myId
 * @param relative
 * @param unrelative
 * @param page
 * @param limit
 * @return
 */
@Override
public List<FriendEx> getFriendList(Long myId, Integer relative, Integer unrelative, Integer page, Integer limit)  {
    try {
        return friendMapper.getFriendList(myId,relative,unrelative,(page-1)*limit,limit);
    } catch (Exception e) {
        return null;
    }
}

/**
 * 條件查詢總數
 *
 * @param myId
 * @param relative
 * @param unrelative
 * @return
 */
@Override
public Long countByFilter(Long myId, Integer relative, Integer unrelative) {
    try {
        return friendMapper.countByFilter(myId,relative,unrelative);
    } catch (Exception e) {
        return 0L;
    }
}

}

PayServiceImpl
package com.cloud.station.service.impl;

import com.cloud.station.fare.api.ChargeApi;
import com.cloud.station.fare.entity.Rule;
import com.cloud.station.mapper.CarInfoMapper;
import com.cloud.station.mapper.CarNumberUsingMapper;
import com.cloud.station.mapper.UserInfoMapper;
import com.cloud.station.pojo.*;
import com.cloud.station.service.FareService;
import com.cloud.station.service.PayService;
import com.cloud.station.service.StationOrderService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service(“payService”)
public class PayServiceImpl implements PayService{

@Autowired
CarInfoMapper carInfoMapper;

@Autowired
UserInfoMapper userInfoMapper;

@Autowired
CarNumberUsingMapper carNumberUsingMapper;

@Autowired
StationOrderService stationOrderService;

@Autowired
FareService fareService;
/**
 * 根據車牌扣費
 *
 * @param carNumber
 * @return
 */
@Override
public float pay(String carNumber,Long endTime) {
    try {
        //1.根據車牌查詢車牌的信息
        CarInfo carInfo = carInfoMapper.getByCarNumber(carNumber);
        //2.查出使用車牌的用戶信息
        UserInfo userInfo = (UserInfo) userInfoMapper.findByPrimaryKey(carInfo.getCurrentUsed());
        //3.查詢出當前車牌的使用情況
        CarNumberUsing  carNumberUsing = (CarNumberUsing) carNumberUsingMapper.getByCarNumberId(carInfo.getId(),1);

        Long usedTimeMs = carNumberUsing.getEndTime()-endTime;//使用時間(毫秒)

        //計算費用
        float money = calculate(usedTimeMs);

        //計算餘額
        float leftMoney = userInfo.getMoney()-money;
        leftMoney = Float.valueOf(String.format("%.2f",leftMoney));//保留兩位小數
        if(leftMoney>=0){
            //更新用戶數據
            userInfo.setMoney(leftMoney);
            //增加信譽
            userInfo.setReputationPoints(userInfo.getReputationPoints()+5);//TODO 增加信譽度
            userInfoMapper.update(userInfo);

            //更新車牌使用數據
            carNumberUsing.setEndTime(endTime);//更新數據
            carNumberUsing.setState(2);
            carNumberUsingMapper.update(carNumberUsing);

            //更新當前使用車牌數據
            carInfo.setCurrentUsed(0L);
            carInfoMapper.update(carInfo);

            return leftMoney;
        }

        //餘額不足
        //更新使用車牌數據
        carNumberUsing.setState(3);
        carNumberUsing.setEndTime(endTime);
        carNumberUsingMapper.update(carNumberUsing);


        //更新車牌數據
        carInfo.setCurrentUsed(0L);
        carInfoMapper.update(carInfo);

        //更新用戶數據
        userInfo.setMoney(leftMoney);//餘額複數
        userInfo.setReputationPoints(userInfo.getReputationPoints()-5);////TODO 扣除信譽度 增加一個不良記錄
        userInfoMapper.update(userInfo);
        return leftMoney;
    } catch (Exception e) {
       return -1;
    }
}

/**
 * 根據停車和停車場ID付款
 *
 * @param stationId
 * @param carNum
 * @return
 */
@Override
public float pay(Long stationId, String carNum) {
    //1.獲取車牌信息
    StationOrder stationOrder = stationOrderService.getByStationIdAndCarNuber(stationId,carNum);

    if(stationOrder==null)return -1;
    //如果訂單已被處理
    if(stationOrder.getEndTime()>0 ||
            stationOrder.getState()==StationOrder.NORMAL ||
            stationOrder.getUserId()!=null)
        return -1;

    //2.根據車牌找到當前使用者的用戶信息
    try {
        //找到當前使用者相關的車主綁定的車牌信息
        CarInfo carInfo = carInfoMapper.getByCarNumber(carNum);
        //當前使用者的用戶信息
        UserInfo userInfo = (UserInfo) userInfoMapper.findByPrimaryKey(carInfo.getCurrentUsed());

        int usedTimeMs = Integer.valueOf((int) ((new Date().getTime()-stationOrder.getCreateTime())/1000/60/60));//使用時間(毫秒)
        /**
         * 計算費用
         */
        //1.獲得計費規則
        FareRule fareRule = fareService.getUsedByStationId(stationId);
        Rule rule = new Rule();
        rule.setRule(fareRule.getRule());
        rule.setMode(fareRule.getMode());
        rule.setTotalTime(usedTimeMs);
        rule.setStartTime(stationOrder.getCreateTime()/1000/60/60);//小時數
        rule.setEndTime((new Date().getTime())/1000/60/60);

// rule.setEndTime(1523671463702L+86060*1000);8小時
float fareTotal = (new ChargeApi(rule)).calc();//總費用

        if(usedTimeMs>=0){//時間有效
            float leftMoney = userInfo.getMoney()-fareTotal;//扣除後用戶餘額

            //扣費
            //1.用戶餘額不足
            if(leftMoney<=0){
                userInfo.setReputationPoints(reputationPoint(userInfo,0));//計算信譽度

                stationOrder.setState(StationOrder.UNDO_MONEY);//欠費
            }else{//用戶餘額夠
                userInfo.setRankPoints(rankPoint(userInfo));//計算積分
                userInfo.setReputationPoints(reputationPoint(userInfo,1));//計算信譽度

                stationOrder.setState(StationOrder.NORMAL);
            }
            //用戶餘額
            userInfo.setMoney(leftMoney);

            //更新用戶信息
            userInfoMapper.update(userInfo);

            //更新車牌信息
            carInfo.setCurrentUsed(0L);//釋放當前使用者
            carInfoMapper.update(carInfo);

            //更新訂單信息
            stationOrder.setEndTime(new Date().getTime());
            stationOrder.setUserId(userInfo.getId());
            stationOrderService.update(stationOrder);

            return fareTotal;//返回消費
        }
        return -1;
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}

/**
 * 計算費用
 * @param starTime
 * @return
 */
private float calculate(float starTime){
    //TODO 計算總費用
    return 10;
}


/**
 * 支付寶扣費
 * @return
 */
private boolean alipay(){

    return true;
}

//

/**
 * TODO 計算信譽度
 * @param userInfo 用戶信息
 * @param mode 模式0:餘額不足   1:餘額足
 * @return
 */
private float reputationPoint(UserInfo userInfo,Integer mode){
    return userInfo.getReputationPoints()-5;
}

//TODO 計算積分
private float rankPoint(UserInfo userInfo){
    return userInfo.getRankPoints()+5;
}

}

下一章

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章