智慧社区管理系统10(车位收费管理列表和功能实现)

 

目录

后端代码

实体类 

mapper层  

mappers sql语句 

Service层 

 接口

实现类 

Controller层 

前端部分

列表显示

 增加和修改

效果图 



这次我们该码写核心功能----车位管理页面 

后端代码

实体类 

package com.woniu.community.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CarCharge {
    private int id;
    private String payDate;//开始时间
    private String endDate;//结束时间
    private double money;//金额
    private Integer status;//状态
    private int ownerId;//关联owner表主键
    private String remarks;//备注
    private String type;//收费类型
    private int parkId;//parking表主键
    private String numbers; //房间号
    private String userName;//业主姓名

}

同时,这个也是要加入sql库中没有的,加入实体类中已实现外连接查询列表功能

mapper层  

package com.woniu.community.mapper;

import com.woniu.community.entity.CarCharge;


import java.util.List;

public interface CarChargeMapper {
    List<CarCharge> selectAll(String numbers,String status,int start,int size );
    int count(String numbers,String status);
    int insertCarCharge(CarCharge carCharge);

    int deleteCarCharge(int id);

    int updateCarCharge(CarCharge carCharge);

    CarCharge selectById(int id);
}

mappers sql语句 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.woniu.community.mapper.CarChargeMapper">
    <resultMap id="carChargeResult" type="CarCharge">
        <result column="id" property="id"></result>
        <result column="pay_date" property="payDate"></result>
        <result column="end_date" property="endDate"></result>
        <result column="money" property="money"></result>
        <result column="status" property="status"></result>
        <result column="owner_id" property="ownerId"></result>
        <result column="remarks" property="remarks"></result>
        <result column="type" property="type"></result>
        <result column="park_id" property="parkId"></result>
        <result column="numbers" property="numbers"></result>
        <result column="username" property="userName"></result>
    </resultMap>
    <select id="selectAll" resultMap="carChargeResult">
        select carcharge.*,parking.numbers,owner.username from carcharge left join parking on carcharge.park_id=parking.id left join owner on carcharge.owner_id=owner.id
    <where>
        <if test="numbers!=null and numbers !='null' and numbers!=''">
        and parking.numbers like '%${numbers}%'
        </if>
        <if test="status!=null and status!='' and status!='null'">
            and carcharge.status = #{status}
        </if>
    </where>
        limit #{start},#{size}
    </select>
    <select id="count"  resultType="int">
        select count(carcharge.id)   from carcharge left join parking on carcharge.park_id=parking.id left join owner on carcharge.owner_id=owner.id
        <where>
            <if test="numbers!=null and numbers !='null' and numbers!=''">
            and parking.numbers like '%${numbers}%'
            </if>
            <if test="status!=null and status!='' and status!='null'">
                and carcharge.status = #{status}
            </if>
        </where>
    </select>
    <insert id="insertCarCharge">
        insert into carcharge (park_id,owner_id,pay_date,end_date,money,status) values (#{parkId},#{ownerId},#{payDate},#{endDate},#{money},#{status})
    </insert>
    <delete id="deleteCarCharge">
        delete from carcharge where id=#{id}
    </delete>
    <update id="updateCarCharge">
        update carcharge set park_id=#{parkId},owner_id=#{ownerId},pay_date=#{payDate},end_date=#{endDate},money=#{money},status=#{status}
        where id=#{id}
    </update>
    <select id="selectById" resultMap="carChargeResult">
        select * from  carcharge where id=#{id}
    </select>

</mapper>

这个mapper.xml文件也是需要外连接,也可以先在sql编译软件上试一下可执行之后再复制粘贴

Service层 

 接口

package com.woniu.community.service;

import com.woniu.community.entity.CarCharge;
import com.woniu.community.utils.HttpResult;

public interface ICarChargeService {
    HttpResult selectAll(String numbers,Integer status,int pageIndex,int pageSize );
    HttpResult insertCarCharge(CarCharge carCharge);

    HttpResult deleteCarCharge(int id);

    HttpResult updateCarCharge(CarCharge carCharge);

    HttpResult selectById(int id);
}

实现类 

package com.woniu.community.service.Impl;

import com.woniu.community.entity.CarCharge;
import com.woniu.community.mapper.CarChargeMapper;
import com.woniu.community.service.ICarChargeService;
import com.woniu.community.utils.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarChargeServiceImpl implements ICarChargeService {
   @Autowired(required = false)
   private CarChargeMapper carChargeMapper;
    @Override
    public HttpResult selectAll(String numbers, Integer status, int pageIndex,int pageSize) {
        List<CarCharge> carCharges = carChargeMapper.selectAll(numbers,status+"" , (pageIndex-1)*pageSize, pageSize);
        int count = carChargeMapper.count(numbers, status+"");
        HttpResult result = null;
        if (carCharges != null && carCharges.size() > 0) {
            result = new HttpResult(carCharges, count, 200, null);
        } else {
            result = new HttpResult(null, 0, 500, "没有更多数据");
        }
        return result;
    }

    @Override
    public HttpResult insertCarCharge(CarCharge carCharge) {
        int count = carChargeMapper.insertCarCharge(carCharge);
        HttpResult result = null;
        if (count > 0 ) {
            result = new HttpResult(null, 0, 200, "新增成功");
        } else {
            result = new HttpResult(null, 0, 500, "新增失败");
        }
        return result;
    }

    @Override
    public HttpResult deleteCarCharge(int id) {
        int count = carChargeMapper.deleteCarCharge(id);
        HttpResult result = null;
        if (count > 0 ) {
            result = new HttpResult(null, 0, 200, "删除成功");
        } else {
            result = new HttpResult(null, 0, 500, "删除失败");
        }
        return result;
    }

    @Override
    public HttpResult updateCarCharge(CarCharge carCharge) {
        int count = carChargeMapper.updateCarCharge(carCharge);
        HttpResult result = null;
        if (count > 0 ) {
            result = new HttpResult(null, 0, 200, "修改成功");
        } else {
            result = new HttpResult(null, 0, 500, "修改失败");
        }
        return result;
    }

    @Override
    public HttpResult selectById(int id) {
        CarCharge carCharge = carChargeMapper.selectById(id);
        HttpResult result = null;
        if (carCharge != null ) {
            result = new HttpResult(carCharge, 0, 200, null);
        } else {
            result = new HttpResult(null, 0, 500, "没有更多数据");
        }
        return result;
    }
}

Controller层 

package com.woniu.community.controller;

import com.woniu.community.entity.CarCharge;
import com.woniu.community.service.ICarChargeService;
import com.woniu.community.utils.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/carcharge")
public class CarChargeController {
    @Autowired(required = false)
    private ICarChargeService carChargeService;

    @RequestMapping("/list")
    HttpResult selectAll(String numbers, Integer status, int pageIndex, int pageSize) {

        return carChargeService.selectAll(numbers, status, pageIndex, pageSize);
    }

    @PostMapping("/add")
    HttpResult insertCarCharge(@RequestBody CarCharge carCharge) {
        return carChargeService.insertCarCharge(carCharge);
    }

    @RequestMapping("/delete")
    HttpResult deleteCarCharge(int id) {
        return carChargeService.deleteCarCharge(id);
    }

    @PostMapping("/update")
    HttpResult updateCarCharge(@RequestBody CarCharge carCharge) {
        return carChargeService.updateCarCharge(carCharge);
    }

    @RequestMapping("/info")
    HttpResult selectById(int id) {
        return carChargeService.selectById(id);
    }
}

前端部分

列表显示


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="assets/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/right.css" rel="stylesheet">
    <script src="assets/jquery-3.5.1.min.js"></script>
    <script src="assets/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <script src="assets/vue.min-v2.5.16.js"></script>
    <script src="assets/vue-router.min-2.7.0.js"></script>
    <script src="assets/axios.min.js"></script>
</head>
<body>
<div id="app" class="container">
    <div class="row">
        <div class="col-md-1" style="height: 50px; line-height: 50px;">
            <label>车位号:</label>
        </div>
        <div class="col-md-2" style="height: 50px; line-height: 50px;">
            <input type="text" class="form-control"v-model="numbers" >
        </div>
        <div class="col-md-2" style="height: 50px; line-height: 50px;">
            <label>缴费状态:</label>
        </div>
        <div class="col-md-3" style="height: 50px; line-height: 50px;">
            <select class="form-control" v-model="status">
                <option></option>
                <option value="0">未缴费</option>
                <option value="1">已缴费</option>

            </select>
        </div>
        <div class="col-md-1 " style="height: 50px; line-height: 50px;">
            <button class="btn btn-default" @click="doQuery" >搜索</button>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12" style="height: 50px; line-height: 50px;">
            <button class="btn btn-default" @click="doAdd">添加</button>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped">
                <caption>车位收费管理</caption>
                <thead>
                <tr >
                    <th>车位号</th>
                    <th>户主</th>
                    <th>开始时间</th>
                    <th>结束时间</th>
                    <th>金额</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="c in carChargeList">
                    <td>{{c.numbers}}</td>
                    <td>{{c.userName}}</td>
                    <td>{{c.payDate}}</td>
                    <td>{{c.endDate}}</td>
                    <td>{{c.money}}</td>
                    <td>{{c.status|statusFilter}}</td>
                    <td>
                        <button v-if="c.status==0" class="btn btn-info"@click="doUpdate(c.id)" >缴费</button>
                        <button  class="btn btn-danger" @click="doDelete(c.id)">删除</button>
                    </td>
                </tr>
                </tbody>
            </table>
            <ul class="pagination" v-for="p in pageNum">
                <li v-if="p==pageIndex" class="active"><a @click="doGo(p)">{{p}}</a></li>
                <li v-else="p==pageIndex" @click="doGo(p)"><a>{{p}}</a></li>
            </ul>
        </div>
    </div>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            carChargeList:null,
            status:'',
            numbers:'',//门牌号
            pageIndex: 1,//当前页数
            pageSize: 10,//每页显示的条数
            pageTotle: 0,//总条数
            pageNum: 0,//页数(分页器)
        },
        filters:{//自定义过滤器
            statusFilter:function(value){//格式化性别字符串
                switch (value) {//0为关闭,1为开启,
                    case 0:
                        return '未缴费';
                    case 1:
                        return '已缴费';
                    default:
                        return'故障';
                }
            }
        },
        methods: {
            requestCarChargeList(url){
                axios.get(url).then(response=>{
                    console.log(response.data);
                    this.carChargeList = response.data.data;
                    this.pageTotle = response.data.pageTotle;
                    this.pageNum = Math.ceil(this.pageTotle / this.pageSize);
                });
            },
            doGo(p){
                this.pageIndex = p;
                var url = " http://localhost:8080/carcharge/list?pageIndex=" + p + "&pageSize=" + this.pageSize;
                this.requestCarChargeList(url);
            },

            doQuery(){
                var url = " http://localhost:8080/carcharge/list?pageIndex=" + this.pageIndex + "&pageSize=" + this.pageSize+"&numbers="+this.numbers+"&status="+this.status;
                this.requestCarChargeList(url);
            },
            doDelete(id){
                //通过axios发送请求
                axios.get("http://localhost:8080/carcharge/delete?id=" + id).then(response => {
                    if (response.data.code == 200) {
                        var url = " http://localhost:8080/carcharge/list?pageIndex=" + this.pageIndex + "&pageSize=" + this.pageSize;
                        this.requestCarChargeList(url);
                    } else {
                        alert(response.data.msg);
                    }
                });
            },
            doAdd(){
                window.parent.main_right.location.href = "carcharge_add_update.html";
            },
            doUpdate(id){
                window.parent.main_right.location.href="carcharge_add_update.html?id="+id;
            },
        },
        created: function () {

            var url="http://localhost:8080/carcharge/list?pageIndex="+this.pageIndex+"&pageSize="+this.pageSize;
            this.requestCarChargeList(url);
        }
    });
</script>
</body>
</html>

这个页面我们要注意vue的双向绑定,因为本表并没有车位号,户主这两个属性,所以需要我们通过外键连接的id来进行双向绑定使数据内容显示在列表中

 增加和修改

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="assets/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/right.css" rel="stylesheet">
    <script src="assets/jquery-3.5.1.min.js"></script>
    <script src="assets/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <script src="assets/vue.min-v2.5.16.js"></script>
    <script src="assets/vue-router.min-2.7.0.js"></script>
    <script src="assets/axios.min.js"></script>
    <script src="assets/date_picker.js"></script>
</head>
<body>
<div id="app" class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="row">
                <div class="col-md-12"
                     style="text-align: center; font-weight: bold; font-size: 18px; height: 80px; line-height: 80px;">
                    {{title}}
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 col-md-offset-3" style="height: 80px;">
                    <label>车位号码</label>
                    <select v-model="parkId">
                        <option v-for="p in parkingList" :value="p.id">{{p.numbers}}</option>
                    </select>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 col-md-offset-3" style="height: 80px;">
                    <label>户主</label>
                    <select v-model="ownerId">
                        <option v-for="o in ownerList" :value="o.id">{{o.userName}}</option>
                    </select>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 col-md-offset-3" style="height: 80px;">
                    <label>开始时间</label>
                    <input type="date" class="form-control" v-model="payDate">
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 col-md-offset-3" style="height: 80px;">
                    <label>结束时间</label>
                    <input type="date" class="form-control" v-model="endDate">
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 col-md-offset-3" style="height: 80px;">
                    <label>金额</label>
                    <input type="text" class="form-control" v-model="money">
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 col-md-offset-3">
                    <label style="margin-right:15px;">缴费状态</label>
                    <label class="radio-inline">
                        <input type="radio" name="status" v-model="status" value="0"/>未缴费
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="status" v-model="status" value="1"/>已缴费
                    </label>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 col-md-offset-3" style="height: 80px;">
                    <button class="btn btn-primary" @click="doSave">保存</button>
                    <button class="btn btn-default" @click="doCancel">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            title: "dddd",
            parkId: null,//车牌号绑定
            ownerId: null,//户主绑定
            payDate: null,//开始时间
            endDate: null,//结束时间
            money: null,//金额
            status: null,//缴费状态
            carChargeId: null,//使用id
            parkingList: null,//车牌号下选框
            ownerList: null,//户主下选列表

        },
        methods: {
            //保存
            doSave() {
                if (this.carChargeId == null) {//添加
                    //通过axios发送请求
                    axios.post("http://localhost:8080/carcharge/add", {
                        parkId: this.parkId,
                        ownerId: this.ownerId,
                        payDate: this.payDate,
                        endDate: this.endDate,
                        money: this.money,
                        status: this.status,
                    }).then(response => {
                        if (response.data.code == 200) {//成功
                            window.parent.main_right.location.href = "carcharge_list.html";
                        } else {//失败
                            alert(response.data.msg);
                        }
                    })
                } else {//修改
                    //通过axios发送请求
                    axios.post("http://localhost:8080/carcharge/update", {
                        id: this.carChargeId,
                        parkId: this.parkId,
                        ownerId: this.ownerId,
                        payDate: this.payDate,
                        endDate: this.endDate,
                        money: this.money,
                        status: this.status,
                    }).then(response => {
                        if (response.data.code == 200) {//成功
                            window.parent.main_right.location.href = "carcharge_list.html";
                        } else {//失败
                            alert(response.data.msg);
                        }
                    })
                }
            },
            //取消按钮
            doCancel() {
                //返回上一个页面
                history.go(-1);
            },
            //请求车牌列表
            requestParkingList() {
                //通过axios发送请求
                axios.get("http://localhost:8080/parking/list?pageIndex=1&pageSize=10000").then(response => {
                    console.log(response.data);
                    this.parkingList = response.data.data;
                });
            },
            //请求户主列表
            requestOwnerList() {
                //通过axios发送请求
                axios.get("http://localhost:8080/owner/list?pageIndex=1&pageSize=10000").then(response => {
                    console.log(response.data);
                    this.ownerList = response.data.data;
                });
            },
            //请求车位缴费列表信息
            requesetCarCharge() {
                axios.get("http://localhost:8080/carcharge/info?id=" + this.carChargeId).then(response => {
                    console.log(response.data);
                    this.parkId = response.data.data.parkId;
                    this.ownerId = response.data.data.ownerId;
                    this.payDate = response.data.data.payDate;
                    this.endDate = response.data.data.endDate;
                    this.money = response.data.data.money;
                    this.status = response.data.data.status;
                });
            }
        },
        created: function () {
            this.requestParkingList();
            this.requestOwnerList();
            var url = window.location.href;
            if (url.indexOf("id") != -1) {
                this.carChargeId = url.substring(url.indexOf("=") + 1);
            }
            console.log("页面跳转传递的id:" + this.carChargeId);
            if (this.carChargeId == null) {//说明添加
                this.title = '添加缴费信息';
            } else {//说明修改
                this.title = '修改缴费信息';
                this.requesetCarCharge();
            }
        }
    });
</script>
</body>
</html>

这里同时要注意双向绑定问题

效果图 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值