EasyPark共享停车位的设计与实现(个人)

来源:互联网 发布:发型配帽子 知乎 编辑:程序博客网 时间:2024/05/01 22:04

 

EasyPark共享停车位的设计与实现


江宏晖

 

         EasyPark这个项目是我在大学学习Java期间自主设计并编写的一个项目。项目前端的界面布局均由我自主设计,但是前端页面实现部分,请求了实验室里兄弟姐妹的帮助,非常感谢他们。首先我想先向各位大牛小牛们交流一下我萌生这个作品的理由。

        “停车”成为了很多车主面临的一个难题,我此次将开发的APP将在实现共享停车的基础上,增加各类停车策略以实现各类空闲车位资源的合理分配,利用网络技术,建立客户集群,通过“用户-系统-车位”的沟通机制,采用共享经济的模式,尽可能有效地缓解“停车难”问题,并为社会带来良好的经济效益。

         在系统开发的前期,我曾经想过许多种停车场的经营模式,也结合了当时自己的能力,最后才设计出了EasyPark的模型:

用户在注册之后进行登录,并同时获得租户和户主两种身份,本系统采用两种车位租赁形式,为即时租位和预约租位。

即时租位模式:户主即时发布己有车位,登记相关地理位置信息、截止时间以及每小时单价。租客在所处位置即时搜寻附近空余即时车位,选择车位按下“租赁”按钮的同时APP记录停车时间并更改车位状态为“已租出”,在截止时间前按下“结束停车”按钮,APP更改车位状态为“未租出”并计算停车时间以及费用,扣除租客余额添加至户主账户中。

预约租位模式:户主以预约形式发布己有车位,登记相关地理位置信息、车位空闲起始时间、车位空闲截止时间以及期间总价格。租客选择停车目的地位置以及预约车位使用时间段,即可搜索出符合地点及时间段的空闲预约车位,直接点击租赁,APP将车位信息更改为“已租出”状态,扣除租客相对应的停车费添加到户主账户中。

         实现过程中较为困难的两个模块当属数据库建立以及查询指定地区附近车位模块,前者在做的过程中不断进行完善,后者我借用了Redis技术达到了预期效果。

部分接口模块作用:

注册:查询手机号是否已被注册,需在未被注册情况下才能注册;

登录:查询手机号是否存在,验证密码后才能登录;

户主发布即时车位:从前台获取车位名称、地址、经度、纬度、截止时间;

户主查看己有即时车位:从后台获取车位名称、价格、截止时间、使用情况;

租客查询即时车位:从前台获取当前位置经度、纬度、当前时间;

                                     从后台返回车位名称、截止时间、价格;

租赁即时车位:绑定车位租客信息,记录停车时间,更改车位状态;

停止租赁即时车位:从前台获取当前时间,从后台获取停车时间,计算总停车时间及费用,扣除租客余额,增加户主余额,更改车位状态;

租赁预约车位:绑定车位租客信息,扣除租客余额,增加户主余额,更改车位状态;

查看预约车位详情页:从后台获取车位名称、地址、起始/截止时间、价格;

APP部分截图:

 


        APP实现所有设计功能,空闲车位查询反应良好,停车操作状态更改设计反应良好,费用计算设计反应良好,数据库数据更新良好,得到了预期的效果。

        本项目设计功能全部实现,自行设计的交易流程清晰明确,前台模块还实现引用“地图”模块,特色优点在共享形式之外,计费系统还抛弃了以往的按时收费方式,采用按分钟收费(不满一元以一元计算)。对于一个课设成果来说我认为还是比较成功的,但是对于一个真实的APP来说还是欠缺一定的真实性,可在后期结合硬件模块对本APP进行进一步的完善。

     硬件模块我暂时的目标是链接一个蓝牙锁模块,在车主靠近停车位时使用手机蓝牙打开地锁停入车位。

参考文献

[1]张辉.停车位共享系统的设计与实现[J].中国战略新兴产业,

2017(8):117-120

[2] 阎湜,潘鹏,屈婧,乔磊,孙凤禹.共享经济下闲置车位利用对城市交通的影响[J].中国商论,2017(12):165-167

 

附录,实验主要函数与代码。

    /**

    * 户主查询即时租出车位

    */

    @SuppressWarnings("unchecked")

 

    public ServerResponse<List<PageData>> findParkNowByLessor(PageData pd)throws Exception {

        List<PageData> results = (List<PageData>) this.dao.findForList("CarportMapper.findParkNowByLessor", pd);

        if (results ==null) {

            return ServerResponse.createByErrorMessage("没有相关车位");

        }

        return ServerResponse.createBySuccess(results);

    }

    /**

    * 租户查询预约出租车位

    */

    @SuppressWarnings({ "unchecked" })

    public ServerResponse<?> findParkPlanByTenant(PageData pd)throws Exception {

        Double longitude1 = (Double) pd.get("longitude");

        Double latitude1 = (Double) pd.get("latitude");

        int radius1 = 10;

 

        List<PageData> results = (List<PageData>) this.dao.findForList("CarportMapper.findAllParkPlanByTenant",pd);//查找所有车位的经纬度和Id

        List<String> ids = new ArrayList<String>();

        String random = RandomUtil.getStringRandom(8);

        for (PageData pageData : results) {//取每个车位的经纬度和id信息去匹配

            String id = Integer.toString((int) pageData.get("carport_id"));

            double longitude = (Double) pageData.get("longitude");

            double latitude = (Double) pageData.get("latitude");

            JedisUtil.geoADD(random, longitude, latitude, id);

        }

        // ids是指得到的符合经纬度范围的机构id

        ids = JedisUtil.geoRadius(random, longitude1, latitude1, radius1, Const.UNIT, Const.ASC);

 

        if (ids.size() > 0) {

            pd.put("ids", ids);//将符合地区的车位id放入pd

            List<PageData> list = (List<PageData>) dao.findForList("CarportMapper.findParkPlanByTenant", pd);

            return ServerResponse.createBySuccess(list);

        } else {

            return ServerResponse.createByErrorMessage("附近没有车位");

        }

    }

    /**

     * 添加即时停车位

     */

    public ServerResponse<?> addParkNow(PageData requestPd)throws Exception {

        Integer save = (Integer)dao.save("CarportMapper.addParkNow",requestPd);

        if(save!=0){

            

            Long id = (Long) requestPd.get("id");

            PageData pd = new PageData();

            pd.put("carport_id", id);

            dao.save("CarportMapper.addParkUser",pd);

            return ServerResponse.createBySuccess(save);

        }

        return ServerResponse.createByErrorMessage("创建失败!");  

    }

    /**

     *租赁预约车位

     * */

    public ServerResponse<Integer> buyParkPlan(PageData pd)throws Exception {

        Integer update = (Integer) dao.update("CarportMapper.updateTenant", pd);

        if (update != 0) {

            double result = (double)dao.findForObject("CarportMapper.findPrice", pd);

            Integer lessor = (Integer) dao.findForObject("CarportMapper.findLessor", pd);

            pd.put("lessor_id", lessor);

            pd.put("balance_pay", result);

            dao.update("CarportMapper.updateBalanceOfTenant", pd);

            Integer update2 = (Integer) dao.update("CarportMapper.updateBalanceOfLessor", pd);

            if(update2 != 0){

            return ServerResponse.createBySuccessMessage("成功了!"); }

            }

        return ServerResponse.createByErrorMessage("没有相关信息");

    }

    /**

     * 点击结束

     * */

    public ServerResponse<Integer> endPark(PageData pd)throws Exception {

        Integer update1 = (Integer) dao.update("CarportMapper.deleteTenant", pd);

        if (update1 != 0) {

            double result = (double)dao.findForObject("CarportMapper.findPrice", pd);

            Integer lessor = (Integer) dao.findForObject("CarportMapper.findLessor", pd);

            pd.put("lessor_id", lessor);

            Integer start_time = (Integer) dao.findForObject("CarportMapper.findStartTime", pd);

            Integer over_time = Integer.valueOf(pd.getString("time_now_num"));

            int result1 = (int) ((over_time-start_time)*result/3600000);

            pd.put("balance_pay", result1);

            dao.update("CarportMapper.updateBalanceOfTenant", pd);

            Integer update2 = (Integer) dao.update("CarportMapper.updateBalanceOfLessor", pd);

            if(update2 != 0){

            return ServerResponse.createBySuccessMessage("成功了!");  }

        }

        return ServerResponse.createByErrorMessage("没有相关信息");

    }

本文章仅限于本人保存作品之用,若有引用意向,请事先与我联系,望理解,谢谢。