东方酒店管理系统(Java版)数据库设计和楼层增删改查操作二

东方酒店管理系统(Java版)数据库设计和楼层增删改查操作二

PD模型设计软件为:PowerDesigner

MySQL数据库可视化管理软件为:NavicatPremium16

1、创建PD模型

需要指定数据库的类型版本:MySQL5.0
在这里插入图片描述

2、PD模型展示

模型设计暂时先创建这些表的结构,对于项目核心业务在里面都已经涉及到了,后面的话对于公告发布、销售额等会根据实际情况来再次完善

下面3的步骤就是导出SQL语句了,那么在这一步有一个很重要也是很容易让人忽略的地方就是忘记设置主键和自增操作,通过如下步骤检查【对于中间表是没有设置标识的】

如果点击2不能弹出的话,需要将修改后的表【应用保存】一下才可以

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-f1PPOiwV-1657813118437)(images/2/1、PD模型的创建.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wJrMqJBs-1657813118438)(images/2/2、PD模型设计.png)]

3、导出的SQL语句(命名可能不是很规范可以自行修改)

也可以选择Summarg选项直接复制SQL语句到NavicatPremium16中执行

需要在mysql8.0+数据库中创建dfjd数据,在将上面建立的表导入到数据库里面(直接在数据库上运行SQL语句可能就会出错),直接复制下面的SQL语句到NavicatPremium16中新建查询来执行即可【下图的Preview就是直接可以查看SQL的直接复制】

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jPgHiLou-1657813118439)(images/2/3、导出SQL语句.png)]

drop table if exists p_announceroom;

drop table if exists p_checkin;

drop table if exists p_hotefloor;

drop table if exists p_maintain;

drop table if exists p_order;

drop table if exists p_room;

drop table if exists p_roomtype;

drop table if exists p_sanitation;

drop table if exists t_checkout;

drop table if exists t_menu;

drop table if exists t_permission;

drop table if exists t_role;

drop table if exists t_role_menu;

drop table if exists t_role_permission;

drop table if exists t_stadd_role;

drop table if exists t_staff_able;

drop table if exists t_user;

/*==============================================================*/
/* Table: p_announceroom                                        */
/*==============================================================*/
create table p_announceroom
(
   id                   int not null auto_increment,
   roomid               int,
   release_money        decimal(10,2),
   release_time         datetime,
   status               int,
   breakfast            int,
   primary key (id)
);

/*==============================================================*/
/* Table: p_checkin                                             */
/*==============================================================*/
create table p_checkin
(
   id                   int not null auto_increment,
   roomtype             varchar(50),
   roomnum              varchar(50),
   customername         varchar(50),
   phone                varchar(11),
   idcode               varchar(18),
   orderid              int,
   checkintime          datetime,
   leavetime            datetime,
   staffid              int,
   status               int,
   payPrice             decimal(10,2),
   remark               varchar(50),
   code                 varchar(50),
   cashpledge           decimal(10,2),
   payment              char(10),
   Inchannel            int,
   primary key (id)
);

/*==============================================================*/
/* Table: p_hotefloor                                           */
/*==============================================================*/
create table p_hotefloor
(
   id                   int not null auto_increment,
   floorname            varchar(3),
   floorstatus          int,
   primary key (id)
);

/*==============================================================*/
/* Table: p_maintain                                            */
/*==============================================================*/
create table p_maintain
(
   id                   int not null auto_increment,
   roomid               int,
   status               int,
   schedule             int,
   blockup              int,
   description          varchar(150),
   starttime            datetime,
   finishtime           datetime,
   staffid              int,
   picture              varchar(100),
   primary key (id)
);

/*==============================================================*/
/* Table: p_order                                               */
/*==============================================================*/
create table p_order
(
   id                   int not null auto_increment,
   userid               int,
   reservation_time     datetime,
   servicetime          datetime,
   payment              int,
   status               int,
   roomtype             int,
   code                 varchar(100),
   actualpayment        decimal(10,2),
   roomprice            decimal(10,2),
   name                 varchar(50),
   mobile               varchar(11),
   idcode               varchar(18),
   checkintime          datetime,
   integral             decimal(10,2),
   primary key (id)
);

/*==============================================================*/
/* Table: p_room                                                */
/*==============================================================*/
create table p_room
(
   id                   int not null auto_increment,
   roomnum              varchar(10),
   status               int,
   floorid              int,
   roomtypeId           int,
   roomdesc             varchar(150),
   roomrequirement      varchar(150),
   photo                varchar(150),
   roomwindow           int,
   primary key (id)
);

/*==============================================================*/
/* Table: p_roomtype                                            */
/*==============================================================*/
create table p_roomtype
(
   id                   int not null auto_increment,
   roomtypename         varchar(20),
   status               int,
   photo                varchar(50),
   livenum              int,
   bednum               int,
   price                decimal(10, 2),
   reservednum          int,
   avilablenum          int,
   livednum             int,
   remark               varchar(100),
   roomnum              int,
   primary key (id)
);

/*==============================================================*/
/* Table: p_sanitation                                          */
/*==============================================================*/
create table p_sanitation
(
   id                   int not null auto_increment,
   roomid               int,
   status               int,
   replacement          varchar(100),
   staffid              int,
   primary key (id)
);

/*==============================================================*/
/* Table: t_checkout                                            */
/*==============================================================*/
create table t_checkout
(
   id                   int not null auto_increment,
   checkinid            int,
   checkoutnumber       varchar(100),
   consumeprice         decimal(10,2),
   createdate           datetime,
   remark               varchar(50),
   staffid              int,
   cashpledge           decimal(10,2),
   overtime             varchar(50),
   deductthedeposit     decimal(10,2),
   status               int,
   primary key (id)
);

/*==============================================================*/
/* Table: t_menu                                                */
/*==============================================================*/
create table t_menu
(
   id                   int not null auto_increment,
   name                 varchar(20),
   linkUrl              varchar(200),
   path                 varchar(200),
   priority             int,
   icon                 varchar(200),
   description          varchar(200),
   parentMenuId         int,
   level                int,
   primary key (id)
);

/*==============================================================*/
/* Table: t_permission                                          */
/*==============================================================*/
create table t_permission
(
   id                   int not null auto_increment,
   name                 varchar(32),
   keyword              varchar(64),
   description          varchar(128),
   primary key (id)
);

/*==============================================================*/
/* Table: t_role                                                */
/*==============================================================*/
create table t_role
(
   id                   int not null auto_increment,
   role_name            varchar(20),
   keyword              varchar(64),
   description          varchar(128),
   primary key (id)
);

/*==============================================================*/
/* Table: t_role_menu                                           */
/*==============================================================*/
create table t_role_menu
(
   role_id              int,
   menu_id              int
);

/*==============================================================*/
/* Table: t_role_permission                                     */
/*==============================================================*/
create table t_role_permission
(
   role_id              int,
   permission_id        int
);

/*==============================================================*/
/* Table: t_stadd_role                                          */
/*==============================================================*/
create table t_stadd_role
(
   roleid               int,
   staffid              int
);

/*==============================================================*/
/* Table: t_staff_able                                          */
/*==============================================================*/
create table t_staff_able
(
   id                   int not null auto_increment,
   username             varchar(20),
   password             varchar(200),
   gender               char,
   age                  int,
   name                 varchar(30),
   telephone            varchar(11),
   hiredate             datetime,
   modificationtime     datetime,
   remark               varchar(100),
   primary key (id)
);

/*==============================================================*/
/* Table: t_user                                                */
/*==============================================================*/
create table t_user
(
   id                   int not null auto_increment,
   username             varchar(50),
   password             varchar(50),
   name                 varbinary(50),
   mobile               varbinary(11),
   idcode               varbinary(18),
   accountbalance       decimal(10,2),
   accountofintegral    decimal(10,2),
   status               int,
   headcover            varchar(100),
   primary key (id)
);

alter table p_announceroom add constraint FK_Reference_14 foreign key (roomid)
      references p_roomtype (id) on delete restrict on update restrict;

alter table p_checkin add constraint FK_Reference_17 foreign key (orderid)
      references p_order (id) on delete restrict on update restrict;

alter table p_checkin add constraint FK_Reference_18 foreign key (staffid)
      references t_staff_able (id) on delete restrict on update restrict;

alter table p_maintain add constraint FK_Reference_11 foreign key (roomid)
      references p_room (id) on delete restrict on update restrict;

alter table p_maintain add constraint FK_Reference_12 foreign key (staffid)
      references t_staff_able (id) on delete restrict on update restrict;

alter table p_order add constraint FK_Reference_15 foreign key (roomtype)
      references p_announceroom (id) on delete restrict on update restrict;

alter table p_order add constraint FK_Reference_16 foreign key (userid)
      references t_user (id) on delete restrict on update restrict;

alter table p_room add constraint FK_Reference_8 foreign key (floorid)
      references p_hotefloor (id) on delete restrict on update restrict;

alter table p_room add constraint FK_Reference_9 foreign key (roomtypeId)
      references p_roomtype (id) on delete restrict on update restrict;

alter table p_sanitation add constraint FK_Reference_10 foreign key (roomid)
      references p_room (id) on delete restrict on update restrict;

alter table p_sanitation add constraint FK_Reference_13 foreign key (staffid)
      references t_staff_able (id) on delete restrict on update restrict;

alter table t_checkout add constraint FK_Reference_19 foreign key (checkinid)
      references p_checkin (id) on delete restrict on update restrict;

alter table t_checkout add constraint FK_Reference_20 foreign key (staffid)
      references t_staff_able (id) on delete restrict on update restrict;

alter table t_menu add constraint FK_Reference_7 foreign key (parentMenuId)
      references t_menu (id) on delete restrict on update restrict;

alter table t_role_menu add constraint FK_Reference_5 foreign key (role_id)
      references t_role (id) on delete restrict on update restrict;

alter table t_role_menu add constraint FK_Reference_6 foreign key (menu_id)
      references t_menu (id) on delete restrict on update restrict;

alter table t_role_permission add constraint FK_Reference_3 foreign key (permission_id)
      references t_permission (id) on delete restrict on update restrict;

alter table t_role_permission add constraint FK_Reference_4 foreign key (role_id)
      references t_role (id) on delete restrict on update restrict;

alter table t_stadd_role add constraint FK_Reference_21 foreign key (roleid)
      references t_role (id) on delete restrict on update restrict;

alter table t_stadd_role add constraint FK_Reference_22 foreign key (staffid)
      references t_staff_able (id) on delete restrict on update restrict;

4、执行SQL语句导出数据库

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pPyPYdWO-1657813118440)(images/2/4、允许SQL文件.png)]

5、在Java项目中编译新增楼层信息

5.1、在DFJD_Common公共模块中创建楼层表的pojo实体类

对于实体类的编写会有很多的get和set方法需要手动的完成,项目中就会实用lombok注解的方式简化开发

在公共模块的pom.xml文件中引入依赖【其他的模块也会继承】

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.24</version>
</dependency>

编写实体类和实用lombok简化

@Data:代码完成get和set方法、@ToString:重写tostring方法方便后面的输出

注意:该注解是依赖于lombok的的,没有就不行,对于时间的格式需要进行指定并且要于前端接收到的格式一致,否则会报错【所有的实体类都需要实现Serializable序列化否则也会报错】

实体类的字段需要前端传递过来的字段也一致否则无法完成数据的接收

package com.zcl.pojo;

import lombok.Data;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * 项目名称:DFJD
 * 描述:楼层实体类
 *
 * @author zhong
 * @date 2022-07-13 20:56
 */
@Data
@ToString
public class Floor implements Serializable {
    
    
    private Integer id;
    /**
     * 楼层名称
     */
    private String floorname;
    /**
     * 楼层状态
     */
    private Integer floorstatus;
    /**
     * 创建时间
     */
    private String date;
}

5.2、创建请求返回数据的实体类【entity包】

所有的数据返回都通过该实体类返回前端

package com.zcl.entity;

import lombok.Data;

import java.io.Serializable;

/**
 * 项目名称:DFJD
 * 描述:返回数据的实体类
 *
 * @author zhong
 * @date 2022-07-14 8:43
 */
@Data
public class Result implements Serializable {
    
    
    /**
     * 执行结果,true为执行成功
     */
    private boolean flage;
    /**
     * 响应提示,主要用于页面展示
     */
    private String message;
    /**
     * 返回的数据
     */
    private Object data;

    /**
     * 两个有参构造,没有返回数据
     * @param flage
     * @param message
     */
    public Result(boolean flage, String message) {
    
    
        super();
        this.flage = flage;
        this.message = message;
    }

    /**
     * 有参构造
     * @param flage
     * @param message
     * @param data
     */
    public Result(boolean flage, String message, Object data) {
    
    
        this.flage = flage;
        this.message = message;
        this.data = data;
    }
}

5.3、创建分页查询的实体类【entity包】

该实体类的作用是:页面进行分页查询的时候可以封住到实体类中方便传递数据进行条件查询

package com.zcl.entity;

import lombok.Data;

import java.io.Serializable;

/**
 * 项目名称:DFJD
 * 描述:封装分页查询条件
 *
 * @author zhong
 * @date 2022-07-14 8:53
 */
@Data
public class QueryPageBean implements Serializable {
    
    
    /**
     * 当前页码
     */
    private Integer currentPage;
    /**
     * 每页显示条数
     */
    private Integer pageSize;
    /**
     * 分页查询条件
     */
    private String queryString;
}

5.4、创建分页查询返回的数据【entity包】

该实用类的作用是:将所有查询到的分页数据封住起来再通过Result返回实体类的data赋值返回给前端获取

package com.zcl.entity;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 项目名称:DFJD
 * 描述:返回分页查询的结果
 *
 * @author zhong
 * @date 2022-07-14 8:51
 */
@Data
public class PageResult implements Serializable {
    
    
    /**
     * 查询的总页数
     */
    private Long total;
    /**
     * 当前页查询的结果
     */
    private List rows;

    /**
     * 有参构造
     * @param total
     * @param rows
     */
    public PageResult(Long total, List rows) {
    
    
        this.total = total;
        this.rows = rows;
    }
}

5.5、定义整个项目返回提示的公共类

作用:为了更好的管理统一返回信息,下面的代码中只是写出了当前楼层的其他模块照样写下去即可,在项目控制器中返回前端响应数据的时候通过该MessageConstant.具体的常量完成调用

package com.zcl.constant;

/**
 * 项目名称:DFJD
 * 描述:整个项目返回的提示信息
 *
 * @author zhong
 * @date 2022-07-14 9:37
 */
public class MessageConstant {
    
    
    public static final String ADD_FLOOR_SUCCESS = "添加楼层成功";
    public static final String ADD_FLOOR_FAIL = "添加楼层失败";
    public static final String DELETE_FLOOR_SUCCESS = "删除楼层成功";
    public static final String DELETE_FLOOR_FAIL = "删除楼层失败";
    public static final String EDIT_FLOOR_SUCCESS = "修改楼层成功";
    public static final String EDIT_FLOOR_FAIL = "修改楼层失败";
}

5.6、完成前端楼层管理页面的搭建【elementUI+Vue+Axios】

在上一篇中说道理具体的配置文件和部署,但没有将如何去抠后台模块,这里实用的模板是LayuiMiNi2,官方地址如下:LayuiMini - 基于Layui的后台管理系统前端模板

下图是我自己抠好的模板

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-krYZpuQE-1657813118440)(images/2/7、后台模板.png)]

前端添加楼层数据请求方式
// 新增保存
submitForm(formName) {
    
    
    this.$refs[formName].validate((valid) => {
    
    
        if (valid) {
    
    
            axios.post('/floor/add.do', this.ruleForm).then(res => {
    
    
                if (res.data.flag) {
    
    
                    this.$message({
    
    
                        message: res.data.message,
                        type: 'success'
                    });
                } else {
    
    
                    this.$message.error(res.data.message);
                }
            }).catch(error => {
    
    
                this.$message.error(error.message);
            }).finally(o => {
    
    
                this.dialogVisible = false;
                this.dialogVisible2 = false;
                this.queryPage();
            });
        } else {
    
    
            this.$message.error('请填写完成表单数据');
            return false;
        }
    });
}
分页查询调用的方法

对于实用过elementUI框架的人都知道下面的一属性值是作为模型数据的,如下:

// 对话框的控制开关
dialogVisible: false,
dialogVisible2: false,
// 添加数据的模型
ruleForm: {
     
     
    floorname: '',
    floorstatus: false
},
// 分页条件模型
pagination: {
     
     
    // 当前页码
    currentPage: 1,
    pageSize: 10,
    // 总页数
    total: 30
}
// 分页查询
queryPage() {
    
    
    var param = {
    
    
        currentPage: this.pagination.currentPage,//页码
        pageSize: this.pagination.pageSize,//每页显示的记录数
        // queryString:this.pagination.queryString 查询条件
    };
    axios.post("/floor/findPage.do", param).then((res) => {
    
    
        // 解析响应的数据,为模型数据赋值
        this.pagination.total = res.data.total;
        this.tableData = res.data.rows;
    });
}

5.7、后端楼层控制器的编写

DFJD_Backend后端模块中编写一个FloorController控制器作为楼层的,里面就是编写前端所发送的请求和接收响应数据的地方

注意点:后端控制器接收前端数据需要字段一致,下面代码实用了@RestController注解返回数据的时候就不需要指定返回的类型格式了

package com.zcl.controller;

import com.zcl.entity.Result;
import com.zcl.pojo.Floor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目名称:DFJD
 * 描述:楼层控制器
 *
 * @author zhong
 * @date 2022-07-14 8:57
 */
@RestController
@RequestMapping("/floor")
public class FloorController {
    
    

    /**
     * 添加楼层控制器
     * @param floor
     * @return
     */
    @RequestMapping("/add")
    public Result add(@RequestBody Floor floor){
    
    
        System.out.println(floor);
        return new Result(true,"请求成功");
    }
}

5.8、楼层接口编写

项目的所有业务接口都存在DFJD_Interface模块中

package com.zcl.service;

import com.zcl.pojo.Floor;

/**
 * 项目名称:DFJD
 * 描述:楼层接口
 *
 * @author zhong
 * @date 2022-07-14 10:26
 */
public interface FloorService {
    
    
    /**
     * 添加楼层
     * @param floor
     */
    void add(Floor floor);
}

5.9、完成接口的具体业务和数据访问层的保存

这一步是重点,对于接口的实现类和数据访问层都在此完成,在DFJD_ServerProvider模块中,代码完成需要注册到dubbo注册中心才能被控制器所接收调用具体的方法

添加楼层实现类编写

重复查询使用了一个自杀式错误来返回,因为我们的添加是没有返回数据的,所以控制器无法判断,但我们控制器通过try可以捕获到错误,有错误就代表是新增失败了

package com.zcl.serviceImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.zcl.dao.FloorDao;
import com.zcl.pojo.Floor;
import com.zcl.service.FloorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 项目名称:DFJD
 * 描述:楼层业务层接口实现
 *
 * @author zhong
 * @date 2022-07-14 10:32
 */
@Service(interfaceClass = FloorService.class)
@Transactional
public class FloorServiceImpl implements FloorService {
    
    
    /**
     * 根据类型注入数据访问层
     * 因为是同一个模块实用@Autowired注入
     */
    @Autowired
    private FloorDao floorDao;

    /**
     * 添加楼层的具体业务实现
     * @param floor
     */
    @Override
    public void add(Floor floor) {
    
    
        // 根据楼层名称查询重复
        Integer count = floorDao.findByFloorNamr(floor.getFloorname());
        if(count > 0){
    
    int i = 1 / 0;}
        // 添加创建时间
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        floor.setDate(format.format(new Date()));
        floorDao.add(floor);
    }
}

数据访问层的接口编写
package com.zcl.dao;

import com.zcl.pojo.Floor;

/**
 * 项目名称:DFJD
 * 描述:楼层数据访问层
 *
 * @author zhong
 * @date 2022-07-14 10:34
 */
public interface FloorDao {
    
    
    void add(Floor floor);
    
    /**
     * 根据楼层名称查询重复
     * @param floorname
     */
    Integer findByFloorNamr(String floorname);
}

数据访问层的映射文件编写

映射文件是存在resources资源包下的,与接口实现类同级关系com.zcl.dao

<?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.zcl.dao.FloorDao">
    <!--添加楼层数据-->
    <insert id="add" parameterType="com.zcl.pojo.Floor">
        insert into p_hotefloor (floorname, floorstatus,date)
        values (#{floorname},#{floorstatus},#{date})
    </insert>

    <!--查询重复-->
    <select id="findByFloorNamr" resultType="java.lang.Integer">
        select count(*)
        from p_hotefloor
        where floorname = #{floorname};
    </select>
</mapper>
启动项目测试
  1. 清空项目的安装包
  2. 查询打包项目
  3. 运行zookeeper服务器,注册dubbo会使用到
  4. 先启动服务提供者DFJD_ServerProvider
  5. 再启动后台系统DFJD_Banckend

6、在Java项目中编译分页查询楼层信息

分页条件查询的几个主要参数:当前页码,每页显示条数,分页条件

分页查询的实体类已经封装好了在PageResult类中,分页查询返回的实体是PageResult而不是Result注意区分不要混淆

使用到mybatis分页查询的一个插件就不需要我们手动的去计算分页的位置了

6.2、控制器编写如下

前端的分页查询在上面页面的位置已经完成编写了,控制器也很简单直接调用查询的接口返回的数据即可

/**
 * 分页条件查询
 * @param pageBean
 * @return
 */
@GetMapping("/findPage")
public PageResult findPage(@RequestBody QueryPageBean pageBean){
    
    
    return floorService.findPage(pageBean);
}

6.3、分页接口和实现类如下

接口

/**
 * 分页查询
 * @param pageBean
 * @return
 */
PageResult findPage(QueryPageBean pageBean);

分页业务实现

需要使用到分页插件来完成分页的数据

/**
 * 楼层分页查询
 * @param pageBean
 * @return
 */
@Override
public PageResult findPage(QueryPageBean pageBean) {
    
    
    // 调用分页查询条件
    PageHelper.startPage(pageBean.getCurrentPage(), pageBean.getPageSize());
    // 调用数据访问层查询数据返回
    Page<Floor> page = floorDao.findByCondition();
    return new PageResult(page.getTotal(),page.getResult());
}    /**
 * 楼层分页查询
 * @param pageBean
 * @return
 */
@Override
public PageResult findPage(QueryPageBean pageBean) {
    
    
    // 调用分页查询条件
    PageHelper.startPage(pageBean.getCurrentPage(), pageBean.getPageSize());
    // 调用数据访问层查询数据返回
    Page<Floor> page = floorDao.findByCondition();
    return new PageResult(page.getTotal(),page.getResult());
}

遇到的问题:当我前端使用axios.get()请求分页数据时后端无法获取到分页数据?试过几个办法都没可以就用回post请求了,如果有懂的麻烦评论一下!!!

6.4、楼层分页查询数据访问层编写

dao接口

返回的类型是Page插件给的

/**
 * 分页条件查询
 * @return
 */
Page<Floor> findByCondition();

映射文件编写

分页的条件会交由mybatis插件来完成不需要我们写

注意:映射文件里面不要写上【;】分号结束,否则就会报错

<!--分页条件查询-->
<select id="findByCondition" resultType="com.zcl.pojo.Floor">
    select *
    from p_hotefloor
</select>

6.5、启动测试

  1. 清楚安装包

  2. 查询打包

  3. 运行业务层模块

  4. 运行后端模块

  5. 分页查询结果

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lTbQiA1V-1657813118441)(images/2/8、分页查询结果.png)]

6.6、点击右下角的分页触发分页

handleSizeChange(val) {
    
    
    this.pagination.pageSize = val;
    this.queryPage();
},
// 点击当前页数事件
handleCurrentChange(val) {
    
    
    // 对当前页进行赋值再调用分页查询
    this.pagination.currentPage = val;
    this.queryPage();
}

6.6、完善页面楼层状态

修改表格数据的状态栏即可,通过vue的判断指令来完成

<el-table-column label="楼层状态" align="center">
    <template slot-scope="scope">
        <div slot="reference" class="name-wrapper" v-if="scope.row.floorstatus == true">
            <el-tag size="medium">正常实用</el-tag>
        </div>
        <div slot="reference" class="name-wrapper" v-else="scope.row.floorstatus == false">
            <el-tag size="danger">停止使用</el-tag>
        </div>
    </template>
</el-table-column>
<el-table-column label="停止时间" align="center" prop="stoptime"></el-table-column>

后面想到添加一个停止时间字段在数据库,添加一个stoptime,类型为varchar:30,同样的实体类中也需要添加上

业务层添加修改为如下

/**
 * 添加楼层的具体业务实现
 * @param floor
 */
@Override
public void add(Floor floor) {
    
    
    // 根据楼层名称查询重复
    Integer count = floorDao.findByFloorNamr(floor.getFloorname());
    if(count > 0){
    
    int i = 1 / 0;}
    // 添加创建时间
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date = format.format(new Date());
    floor.setDate(date);
    if (floor.getFloorstatus() == 0) {
    
    
        floor.setStoptime(date);
    }
    floorDao.add(floor);
}

添加楼层的映射文件也需要进行添加一个字段否则无法添加数据

修改后的效果

需要清空打包内容再重新打包运行

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0BNSu7RE-1657813118442)(images/2/9、优化效果.png)]

7、修改楼层数据

修改楼层同样使用一个对话框,复制一份修改控制开关即可,其他的不需要改变

7.1、前端打开编辑事件和前端按钮设计

这个开关很奇怪,在表单里面你是改变不了他的初始值(ruleForm.floorstatus)我也不知道是为什么,如果你用的是一个新的模型数据(status)不是表单的它就可以改变开关的状态(琢磨了很久)

<el-form-item label="是否启用" prop="floorstatus">
        <el-switch v-if="ruleForm.floorstatus==1" active-value="1"
                   inactive-value="0" class="is-checked" aria-checked="true" v-model="ruleForm.floorstatus"></el-switch>
        <el-switch v-if="ruleForm.floorstatus==0" active-value="1"
                   inactive-value="0"v-model="ruleForm.floorstatus"></el-switch>
    </el-form-item>

编辑打开事件

// 修改事件
handleEdit(id) {
    
    
    this.dialogVisible2 = true;
    // 清空表单
    this.ruleForm = {
    
    
        floorname: '',
        floorstatus: 0
    };
    axios.get('/floor/findById.do?id='+id).then((res) => {
    
    
        if (res.data.flag) {
    
    
            // 回填数据
            this.ruleForm = res.data.data;
        }else {
    
    
            this.$message.error(res.data.message);
        }
    })
}

保存事件与新增一样修改路径即可

7.2、根据id查询楼层控制器

/**
 * 根据id查询楼层数据
 * @param id
 * @return
 */
@RequestMapping("/findById")
public Result findById(Integer id) {
    
    
    try {
    
    
        // 调用查询数据
        Floor floor = floorService.findById(id);
        return new Result(true,MessageConstant.QUERY_FLOOR_SUCCESS,floor);
    } catch (Exception e) {
    
    
        e.printStackTrace();
        return new Result(false,MessageConstant.QUERY_FLOOR_FALL);
    }
}

7.3、查询业务层实现

省略接口的编写

@Override
public Floor findById(Integer id) {
    return floorDao.findById(id);
}

映射文件的编写

<!--根据id查询数据-->
<select id="findById"  resultType="com.zcl.pojo.Floor">
    select *
    from p_hotefloor
    where id = #{id};
</select>

7.4、保存修改数据控制器

/**
 * 编辑楼层数据
 * @param floor
 * @return
 */
@RequestMapping("/editFloor")
public Result editFloor(Floor floor){
    
    
    try {
    
    
        floorService.saveFloor(floor);
        return new Result(true,MessageConstant.EDIT_FLOOR_FAIL);
    } catch (Exception e) {
    
    
        e.printStackTrace();
        return new Result(false,MessageConstant.EDIT_FLOOR_FAIL);
    }
}

其他的接口和业务层调用下面就省略了

业务层

/**
 * 编辑楼层数据
 * @param floor
 */
@Override
public void saveFloor(Floor floor) {
    
    
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    if(floor.getFloorstatus() == 0){
    
    
        floor.setStoptime(format.format(new Date()));
    }else{
    
    
            floor.setStoptime("");
        }
    floorDao.save(floor);
}

7.5、编辑映射文件

<!--根据id编辑楼层数据-->
<update id="save" parameterType="com.zcl.pojo.Floor">
    update p_hotefloor
    set floorname = #{floorname},floorstatus=#{floorstatus},stoptime = #{stoptime}
    where id = #{id};
</update>

启动修改测试

8、停用楼层数据

删除当作是停用,一栋楼哪里能删除的是吧

8.1、点击停用前端询问事件

// 停用事件
handleDelete(id) {
    
    
    this.$confirm('此操作将会停用该楼层, 是否继续?', '提示', {
    
    
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
    
    
        axios.post("/floor/Disable.do?id="+id).then(res =>{
    
    
            if(res.data.flag){
    
    
                this.$message({
    
    
                    type: 'success',
                    message: '停用成功!'
                });
            }else {
    
    
                this.$message.error(res.data.message);
            }
        }).catch(error => {
    
    
            this.$message.error(error.message);
        }).finally(o => {
    
    
            this.dialogVisible = false;
            this.dialogVisible2 = false;
            this.queryPage();
        });

    }).catch(() => {
    
    
        this.$message({
    
    
            type: 'info',
            message: '已取消停用'
        });
    });
}

8.2、后端控制器编写

/**
 * 根据id停用楼层
 * @param id
 * @return
 */
@RequestMapping("/Disable")
public Result disable(Integer id){
    
    
    try {
    
    
        floorService.disableFloor(id);
        return new Result(true,MessageConstant.EDIT_FLOOR_SUCCESS);
    } catch (Exception e) {
    
    
        return new Result(false,MessageConstant.EDIT_FLOOR_FAIL);
        e.printStackTrace();
    }
}

8.3、停用业务实现和映射文件

基本与修改的一样

/**
 * 根据id停用楼层
 * @param id
 */
@Override
public void disableFloor(Integer id) {
    
    
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Floor floor = new Floor();
    floor.setId(id);
    floor.setFloorstatus(0);
    floor.setStoptime(format.format(new Date()));
    floorDao.disableFloor(floor);
}

映射文件

<update id="disableFloor" parameterType="com.zcl.pojo.Floor">
    update p_hotefloor
    set floorstatus=#{floorstatus},stoptime = #{stoptime}
    where id = #{id};
</update>

猜你喜欢

转载自blog.csdn.net/baidu_39378193/article/details/125795151