软件实现与测试

  一、项目在GitHub的代码:

         https://github.com/Chinenana/sharedParking/

         注意:仅仅是一部分,代码过大因此只上传一部分。

二、如何使用共享车位app?

       第一步:打开手机客户端 共享车位app

       第二步:点击登录或注册(输入正确手机号,进行短信验证)

       第三步:验证成功进入app主页

       第四步:点击图上显示的车位标识(红色标识表示有车位存在)进行查看或者预约车位

       第五步:查看车位信息,可点击查看该车位评价以及预约该车位

       第六步:查看评价则跳转到评价页面,预约则跳转到预约界面

       第七步:点击预约跳转到支付页面

       第八步:支付完成后点击导航

       第九步:导航到达目的地后开始停车,此时点击停车桩的开锁键进行开锁

       第十步:停车到达预约时间后开出车位,进行关锁,停车桩上升,停车流程结束。

三、代码实现

       利用myeclipse+H5编辑。

       部分核心代码如下:

package data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class dbCarInfo {
String ss="";
Connection conn=JDBCUtil.getConn();
//修改用户头像图片地址 修改成功返回1,失败返回0
public String updateUserImage(String user_id,String user_image){

try {
String sql="update user_info set user_image=? where user_id=?";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, user_image);
pst.setString(2, user_id);
int i=pst.executeUpdate();
if(i==1){
ss="1";
}else{
ss="0";
}
pst.close();
} catch (SQLException e){
e.printStackTrace();
}
return ss;
}

package data;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import json.*;
public class DbOrderInfo {
Connection conn = data.JDBCUtil.getConn();
//查找用户的全部订单
public JSONArray getAllOrder(String userId){
String sql = " select b.order_id,b.order_time,s.space_address,order_state "
+ " from book_order_info b,space_info s where b.space_id=s.space_id AND b.user_id='" +userId+ "'";
JSONArray jsar = new JSONArray();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
JSONObject jsonObjs = new JSONObject();
jsonObjs.put("order_id", rs.getString(1));
jsonObjs.put("order_time", rs.getString(2));
jsonObjs.put("space_id", rs.getString(3));
jsar.put(jsonObjs);
}
rs.close();
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
return jsar;
}

//查询某一订单的详细信息,返回jsonarray
public JSONArray getOrderDetail(String order_id){



return null;
}

}

package data;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import json.JSONArray;
import json.JSONObject;

import control.GetTimeForNow;
import data.JDBCUtil;

public class dbUserInfo {
String ss="";
Connection conn=JDBCUtil.getConn();

public String selectUserPw(String userId){ //用户登录

try {
StringBuffer sql_pw=new StringBuffer()
.append(" select user_pw from")
.append(" user_info where user_tel = ? ");
// System.out.println(conn);
PreparedStatement pst = conn.prepareStatement(sql_pw.toString());
pst.setString(1, userId);
ResultSet rs = pst.executeQuery();
if (rs.next()) {
ss = rs.getString("user_pw"); //获取密码
}
rs.close();
pst.close();
conn.close();
}catch (SQLException e) {
e.printStackTrace();
}
return ss;
}

public int savaUserInfo(String userid,String passwd){//用户注册
Connection conn=JDBCUtil.getConn();
int ss= 0;
try {
String time=GetTimeForNow.getTimeForNow(); //获取时间
StringBuffer sql=new StringBuffer()
.append(" insert into user_info ")
.append(" (user_tel,user_pw,user_register_time) values(?,?,?) ");

PreparedStatement pst = conn.prepareStatement(sql.toString());
pst.setString(1, userid);
pst.setString(2, passwd);
pst.setString(3, time);
ss = pst.executeUpdate(); // ss=1 表示成功 否则失败

pst.close();
conn.close();
}catch (SQLException e) {
e.printStackTrace();
}
return ss;
}


//设置登录状态 state 为1 表示登录 为0表示注销
public String setUserState(String userid,String state){
Connection conn = JDBCUtil.getConn();
String ss="";
try{
if(!state.equals("1") && !state.equals("0"))
return "0";

String sql_state="update user_info set user_login_state= ? where user_tel= ? ";
PreparedStatement pst = conn.prepareStatement(sql_state);
pst.setString(1, state);
pst.setString(2, userid);
if(pst.executeUpdate() == 1) //成功返回1 ,否则0
{
ss = "1";
}
else {
ss="0";
}
}
catch (SQLException e) {
e.printStackTrace();
}
return ss;
}
//个人信息页面
// 查看用户信息资料
// public List<Map<String, Object>> selectUserInfo(String user_id) {
// List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
// //用户名,性别,真实姓名,手机号码,信誉积分,密码,邮箱。
// try {
// String sql = "select user_name,user_sex,user_tel from user_info where user_id=?";
// PreparedStatement pst=conn.prepareStatement(sql);
// pst.setString(1, user_id);
// ResultSet rs = pst.executeQuery();
// while (rs.next()) {
// Map<String, Object> map = new HashMap<String, Object>();
// String user_name = rs.getString("user_name");
// String user_sex = rs.getString("user_sex");
// if (user_sex == null) {
// user_sex = "--";
// } else if (user_sex.equals("0")) {
// user_sex = "男";
// } else {
// user_sex = "女";
// }
// String user_tel = rs.getString("user_tel");
// if (user_name == null) {
// user_name = "未填写";
// }
// map.put("user_name", user_name);
// map.put("user_sex", user_sex);
// map.put("user_tel", user_tel);
// list.add(map);
// }
// rs.close();
// pst.close();
// } catch (SQLException e) {
// e.printStackTrace();
// }
// return list;
// }
public JSONArray selectUserInfo(String user_id){
String sql = "select user_tel,user_pw,user_name,user_sex,user_real_name,user_email from user_info where user_id=?";
JSONArray jsar = new JSONArray();

try {

PreparedStatement pst=conn.prepareStatement(sql);
pst.setString(1, user_id);
ResultSet rs = pst.executeQuery();
while(rs.next()){
JSONObject jsonObjs = new JSONObject();
String user_name = rs.getString("user_name");
String user_sex = rs.getString("user_sex");
if (user_sex == null) {
user_sex = "--";
} else if (user_sex.equals("0")) {
user_sex = "男";
} else {
user_sex = "女";
}
String user_tel = rs.getString("user_tel");
if (user_name == null) {
user_name = "未填写";
}
jsonObjs.put("user_tel", rs.getString(1));
jsonObjs.put("user_pw", rs.getString(2));
jsonObjs.put("user_name", rs.getString(3));
jsonObjs.put("user_sex", rs.getString(4));
//jsonObjs.put("user_credit", rs.getString(5));
jsonObjs.put("user_real_name", rs.getString(5));
jsonObjs.put("user_email", rs.getString(6));
jsar.put(jsonObjs);
}
rs.close();
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
return jsar;
}

//查看用户的信用额度,返回信用额,如果不存在该用户返回0
public JSONArray selectUserCredit(String user_id) {
JSONArray jsar = new JSONArray();

try {
String sql = "select user_credit from user_info where user_id=?";
PreparedStatement pst=conn.prepareStatement(sql);
pst.setString(1, user_id);
ResultSet rs = pst.executeQuery();
if (rs.next()) {
JSONObject jsonObjs = new JSONObject();
jsonObjs.put("user_credit", rs.getString(1));
}else{
return null;
}
rs.close();
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
return jsar;
}



//修改昵称的方法 修改成功返回1,失败返回0
public JSONArray updateUserName(String user_id,String user_name){
JSONArray jsar = new JSONArray();
try {
String sql="update user_info set user_name=? where user_id=?";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, user_name);
pst.setString(2, user_id);
ResultSet rs = pst.executeQuery();
if (rs.next()) {
JSONObject jsonObjs = new JSONObject();

if(i==1){
JSONObject jsonObjs = new JSONObject();
ss="1";
}else{
ss="0";
}
pst.close();
} catch (SQLException e){
e.printStackTrace();
}
return ss;
}

//修改性别的方法 修改成功返回1,失败返回0
public JSONArray updateUserSex(String user_id,String user_sex){

try {
String sql="update user_info set user_sex=? where user_id=?";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, user_sex);
pst.setString(2, user_id);
int i=pst.executeUpdate();
if(i==1){
ss="1";
}else{
ss="0";
}
pst.close();
} catch (SQLException e){
e.printStackTrace();
}
return ss;
}
//修改真实姓名的方法 修改成功返回1,失败返回0
public JSONArray updateUserRealName(String user_id,String user_real_name){

try {
String sql="update user_info set user_real_name=? where user_id=?";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, user_real_name);
pst.setString(2, user_id);
int i=pst.executeUpdate();
if(i==1){
ss="1";
}else{
ss="0";
}
pst.close();
} catch (SQLException e){
e.printStackTrace();
}
return ss;
}

// 修改用户密码 pw1是原来密码,新密码是pw2
//返回1说明修改成功,0说明原来的密码不对

public JSONArray updateUserPw(String user_id, String user_pw1, String user_pw2) {

int i = 0;
String s="";
try {
System.out.println(user_id);
System.out.println(user_pw1);
System.out.println(user_pw2);
String sql1 = "select user_pw from user_info where user_id=?";
String sql2 = "update user_info set user_pw=? where user_id=?";
PreparedStatement pst1=conn.prepareStatement(sql1);
PreparedStatement pst2=conn.prepareStatement(sql2);
pst1.setString(1, user_id);
pst2.setString(1, user_pw2);
pst2.setString(2, user_id);
ResultSet rs = pst1.executeQuery();
try {
if (rs.next()) {
s = rs.getString("user_pw");
}
} catch (Exception e) {
e.printStackTrace();
}
if (s.equals(user_pw1)) {
i=pst2.executeUpdate();
}
if (i == 1) {
ss = "1";
} else {
ss = "0";
}
rs.close();
pst1.close();
pst2.close();
} catch (SQLException e) {
e.printStackTrace();
}
return ss;
}

//修改邮箱
public JSONArray updateUserEmail(String user_id,String user_email){

try {
String sql="update user_info set user_email=? where user_id=?";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, user_email);
pst.setString(2, user_id);
int i=pst.executeUpdate();
if(i==1){
ss="1";
}else{
ss="0";
}
pst.close();
} catch (SQLException e){
e.printStackTrace();
}
return ss;
}

}

 

package data;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import json.JSONArray;
import json.JSONObject;

import data.JDBCUtil;
public class dbUserPurse {
private String ss="";
Connection conn = JDBCUtil.getConn();
//钱包信息
public JSONArray SelectUserPurse(String user_id){
//返回用户的账户余额
JSONArray jsar = new JSONArray();
try {
String sql = "select user_money from user_purse where user_id=?";
PreparedStatement pst = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);// 创建Statement对象
//PreparedStatement pst = conn.prepareStatement(sql);// 创建Statement对象
pst.setString(1, user_id);
ResultSet rs = pst.executeQuery();
while(rs.next()){
JSONObject jsonObjs = new JSONObject();
jsonObjs.put("user_money", rs.getString(1));
jsar.put(jsonObjs);
}
rs.close();
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
return jsar;
}

//充值在我的余额中
public JSONArray ChargeUserPurse(String user_money,String user_id,String user_pay_pwd){
//根据用户输入的金额以及密码与用户id充值用户的账户余额
JSONArray jsar = new JSONArray();
try {
String sql = "insert into user_purse(user_money) values(?) where user_id=? and user_pay_pwd=?";
PreparedStatement pst = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);// 创建Statement对象
//PreparedStatement pst = conn.prepareStatement(sql);// 创建Statement对象
pst.setString(1, user_money);
pst.setString(2, user_id);
pst.setString(3, user_pay_pwd);
ResultSet rs = pst.executeQuery();
while(rs.next()){
JSONObject jsonObjs = new JSONObject();
jsonObjs.put("user_money", rs.getString(1));
jsonObjs.put("user_id", rs.getString(2));
jsonObjs.put("user_pay_pwd", rs.getString(3));
jsar.put(jsonObjs);
}
rs.close();
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
return jsar;
}


//修改支付密码
public JSONArray AlterUserPayPW(String user_id,String user_pay_pwd){

JSONArray jsar = new JSONArray();
try {
String sql = "alter user_purse set user_pay_pw=? where user_id=?";
PreparedStatement pst = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);// 创建Statement对象
//PreparedStatement pst = conn.prepareStatement(sql);// 创建Statement对象
pst.setString(1, user_pay_pwd);
pst.setString(2, user_id);
ResultSet rs = pst.executeQuery();
while(rs.next()){
JSONObject jsonObjs = new JSONObject();
jsonObjs.put("user_pay_pw", rs.getString(1));
jsar.put(jsonObjs);
}
rs.close();
pst.close();
} catch (SQLException e) {
e.printStackTrace();
}
return jsar;
}

//下单
//
// public String payOrder(String order_id,String user_tel,String user_pay_pw,double total_price){
// //订单号、下单用户手机、支付密码、价格
// //此方法完成金钱的转移,成功返回success
// //余额不足返回price,密码错误返回password
// String pw="";
// double money=0;
// try{
// String sql1="select user_pay_pw,user_money from user_purse where user_tel=?";
// PreparedStatement pst = conn.prepareStatement(sql1);
// pst.setString(1, user_tel);
// ResultSet rs = pst.executeQuery();
// if(rs.next()){
// pw=rs.getString("user_pay_pw");
// money=rs.getDouble("user_money");
// }
// rs.close();
// pst.close();
// if(pw.equals(user_pay_pw)==false){
// return "password";
// }
// if(money<total_price){
// return "price";
// }
// try{
// String sql2="update user_purse set user_money =user_money+? where user_tel in(select user_tel from user_info where user_id in(select user_id from space_info where space_id in(select space_id from book_order_info where order_id=?)))";
// String sql3="update user_purse set user_money =user_money-? where user_tel =?";
// PreparedStatement pst2 = conn.prepareStatement(sql2);
// PreparedStatement pst3 = conn.prepareStatement(sql3);
// pst2.setDouble(1, total_price);
// pst2.setString(2, order_id);
// pst3.setDouble(1, total_price);
// pst3.setString(2, user_tel);
// pst2.executeUpdate();
// pst3.executeUpdate();
// pst2.close();
// pst3.close();
// }catch(SQLException e){
// e.printStackTrace();
// return "error";
// }
//
// }catch(SQLException e){
// e.printStackTrace();
// return "error";
// }
// return "success";
// }
//
// //添加支付密码的方法
// public String addPayPw(String user_tel,String user_pay_pw){
//
// try{
// String sql="update user_purse set user_pay_pw = ? where user_tel = ?";
// PreparedStatement pst = conn.prepareStatement(sql);
// pst.setString(1, user_pay_pw);
// pst.setString(2, user_tel);
// int i=pst.executeUpdate();
// if(i==1){
// ss="1";
// }else{
// ss="0";
// }
// }catch(SQLException e){
// e.printStackTrace();
// }
// return ss;
// }

}

四、软件测试

      利用chrome测试。