【尚庭公寓SpringBoot + Vue 项目实战】预约看房与租约管理(完结)

【尚庭公寓SpringBoot + Vue 项目实战】预约看房与租约管理(完结)


1、业务说明

预约看房管理共需三个接口,分别是保存或更新看房预约、查询个人预约列表和根据ID查询预约详情信息

租约管理共有六个接口,分别是获取个人租约基本信息列表**、**根据ID获取租约详细信息、根据ID更新租约状态、保存或更新租约、根据房间ID获取可选支付方式和根据房间ID获取可选租期

2、接口开发
2.1、预约看房管理

image-20240621212704787

首先在ViewAppointmentController中注入ViewAppointmentService,如下

@Tag(name = "看房预约信息")
@RestController
@RequestMapping("/app/appointment")
public class ViewAppointmentController {

    @Autowired
    private ViewAppointmentService service;
}
2.1.1.保存或更新看房预约

ViewAppointmentController中增加如下内容

@Operation(summary = "保存或更新看房预约")
@PostMapping("/saveOrUpdate")
public Result saveOrUpdate(@RequestBody ViewAppointment viewAppointment) {

    viewAppointment.setUserId(LoginUserHolder.getLoginUser().getUserId());
    service.saveOrUpdate(viewAppointment);
    return Result.ok();
}
2.1.2. 查询个人预约看房列表
  • 查看响应的数据结构

    查看web-app模块下的com.atguigu.lease.web.app.vo.appointment.AppointmentItemVo,如下

    @Data
    @Schema(description = "APP端预约看房基本信息")
    public class AppointmentItemVo {
    
        @Schema(description = "预约Id")
        private Long id;
    
        @Schema(description = "预约公寓名称")
        private String apartmentName;
    
        @Schema(description = "公寓图片列表")
        private List<GraphVo> graphVoList;
    
        @Schema(description = "预约时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private Date appointmentTime;
    
        @Schema(description = "当前预约状态")
        private AppointmentStatus appointmentStatus;
    }
    
  • 编写Controller层逻辑

    ViewAppointmentController中增加如下内容

    @Operation(summary = "查询个人预约看房列表")
    @GetMapping("listItem")
    public Result<List<AppointmentItemVo>> listItem() {
        List<AppointmentItemVo> list = service.listItemByUserId(LoginUserHolder.getLoginUser().getUserId());
        return Result.ok(list);
    }
    
  • 编写Service层逻辑

    • ViewAppointmentService中增加如下内容

      List<AppointmentItemVo> listItemByUserId(Long userId);
      
    • ViewAppointmentServiceImpl中增加如下内容

      @Override
      public List<AppointmentItemVo> listItemByUserId(Long userId) {
          return viewAppointmentMapper.listItemByUserId(userId);
      }
      
  • 编写Mapper层逻辑

    • ViewAppointmentMapper中增加如下内容

      List<AppointmentItemVo> listItemByUserId(Long userId);
      
    • ViewAppointmentMapper.xml中增加如下内容

      <resultMap id="AppointmentItemVoMap" type="com.atguigu.lease.web.app.vo.appointment.AppointmentItemVo"
                 autoMapping="true">
          <id column="id" property="id"/>
          <collection property="graphVoList" ofType="com.atguigu.lease.web.app.vo.graph.GraphVo" autoMapping="true"/>
      </resultMap>
      
      <select id="listItemByUserId" resultMap="AppointmentItemVoMap">
          select va.id,
                 va.appointment_time,
                 va.appointment_status,
                 ai.name apartment_name,
                 gi.name,
                 gi.url
          from view_appointment va
                   left join apartment_info ai on va.apartment_id = ai.id and ai.is_deleted = 0
                   left join graph_info gi on gi.item_type = 1 and gi.item_id = ai.id and gi.is_deleted = 0
          where va.is_deleted = 0
            and va.user_id = #{userId}
          order by va.create_time desc
      </select>
      
2.1.3. 根据ID查询预约详情信息
  • 查看相应的数据结构

    查看web-app模块下的com.atguigu.lease.web.app.vo.appointment.AppointmentDetailVo,内容如下

    @Data
    @Schema(description = "APP端预约看房详情")
    public class AppointmentDetailVo extends ViewAppointment {
    
        @Schema(description = "公寓基本信息")
        private ApartmentItemVo apartmentItemVo;
    }
    
  • 编写Controller层逻辑

    ViewAppointmentController中增加如下内容

    @GetMapping("getDetailById")
    @Operation(summary = "根据ID查询预约详情信息")
    public Result<AppointmentDetailVo> getDetailById(Long id) {
        AppointmentDetailVo appointmentDetailVo = service.getDetailById(id);
        return Result.ok(appointmentDetailVo);
    }
    
  • 编写Service层逻辑

    • ViewAppointmentService中增加如下内容

      AppointmentDetailVo getDetailById(Long id);
      
    • ViewAppointmentServiceImpl中增加如下内容

      @Override
      public AppointmentDetailVo getDetailById(Long id) {
      
          ViewAppointment viewAppointment = viewAppointmentMapper.selectById(id);
      
          ApartmentItemVo apartmentItemVo = apartmentInfoService.selectApartmentItemVoById(viewAppointment.getApartmentId());
      
          AppointmentDetailVo agreementDetailVo = new AppointmentDetailVo();
          BeanUtils.copyProperties(viewAppointment, agreementDetailVo);
      
          agreementDetailVo.setApartmentItemVo(apartmentItemVo);
      
          return agreementDetailVo;
      }
      
2.2、租约管理

image-20240621212744709

首先在LeaseAgreementController中注入LeaseAgreementService,如下

@RestController
@RequestMapping("/app/agreement")
@Tag(name = "租约信息")
public class LeaseAgreementController {

    @Autowired
    private LeaseAgreementService service;
}
2.2.1. 获取个人租约基本信息列表
  • 查看响应的数据结构

    查看web-appp模块下的com.atguigu.lease.web.app.vo.agreement.AgreementItemVo,内容如下

    @Data
    @Schema(description = "租约基本信息")
    public class AgreementItemVo {
    
        @Schema(description = "租约id")
        private Long id;
    
        @Schema(description = "房间图片列表")
        private List<GraphVo> roomGraphVoList;
    
        @Schema(description = "公寓名称")
        private String apartmentName;
    
        @Schema(description = "房间号")
        private String roomNumber;
    
        @Schema(description = "租约状态")
        private LeaseStatus leaseStatus;
    
        @Schema(description = "租约开始日期")
        @JsonFormat(pattern = "yyyy-MM-dd")
        private Date leaseStartDate;
    
        @Schema(description = "租约结束日期")
        @JsonFormat(pattern = "yyyy-MM-dd")
        private Date leaseEndDate;
    
        @Schema(description = "租约来源")
        private LeaseSourceType sourceType;
    
        @Schema(description = "租金")
        private BigDecimal rent;
    }
    
  • 编写Controller层逻辑

    LeaseAgreementController中增加如下内容

    @Operation(summary = "获取个人租约基本信息列表")
    @GetMapping("listItem")
    public Result<List<AgreementItemVo>> listItem() {
        List<AgreementItemVo> result = service.listItemByPhone(LoginUserHolder.getLoginUser().getUsername());
        return Result.ok(result);
    }
    
  • 编写Service层逻辑

    • LeaseAgreementService中增加如下内容

      List<AgreementItemVo> listItemByPhone(String phone);
      
    • LeaseAgreementServiceImpl中增加如下内容

      @Override
      public List<AgreementItemVo> listItemByPhone(String phone) {
          return leaseAgreementMapper.listItemByPhone(phone);
      }
      
  • 编写Mapper层逻辑

    • LeaseAgreementMapper中增加如下内容

      List<AgreementItemVo> listItemByPhone(String phone);
      
    • LeaseAgreementMapper.xml中增加如下内容

      <resultMap id="AgreementItemVoMap" type="com.atguigu.lease.web.app.vo.agreement.AgreementItemVo" autoMapping="true">
          <id property="id" column="id"/>
          <collection property="roomGraphVoList" ofType="com.atguigu.lease.web.app.vo.graph.GraphVo" autoMapping="true"/>
      </resultMap>
      
      <select id="listItemByPhone" resultMap="AgreementItemVoMap">
          select la.id,
                 la.lease_start_date,
                 la.lease_end_date,
                 la.rent,
                 la.payment_type_id,
                 la.status lease_status,
                 la.source_type,
                 ai.name apartment_name,
                 ri.room_number,
                 gi.name,
                 gi.url
          from lease_agreement la
                   left join apartment_info ai on la.apartment_id = ai.id and ai.is_deleted = 0
                   left join room_info ri on la.room_id = ri.id and ri.is_deleted = 0
                   left join graph_info gi on gi.item_type = 2 and gi.item_id = ri.id and gi.is_deleted = 0
          where la.is_deleted = 0
            and la.phone = #{phone}
      
      </select>
      
2.2.2. 根据ID获取租约详细信息
  • 查看响应的数据结构

    查看web-app模块下的com.atguigu.lease.web.app.vo.agreement.AgreementDetailVo,内容如下

    @Data
    @Schema(description = "租约详细信息")
    public class AgreementDetailVo extends LeaseAgreement {
    
        @Schema(description = "租约id")
        private Long id;
    
        @Schema(description = "公寓名称")
        private String apartmentName;
    
        @Schema(description = "公寓图片列表")
        private List<GraphVo> apartmentGraphVoList;
    
        @Schema(description = "房间号")
        private String roomNumber;
    
        @Schema(description = "房间图片列表")
        private List<GraphVo> roomGraphVoList;
    
        @Schema(description = "支付方式")
        private String paymentTypeName;
    
        @Schema(description = "租期月数")
        private Integer leaseTermMonthCount;
    
        @Schema(description = "租期单位")
        private String leaseTermUnit;
    
    }
    
  • 编写Controller层逻辑

    LeaseAgreementController中增加如下内容

    @Operation(summary = "根据id获取租约详细信息")
    @GetMapping("getDetailById")
    public Result<AgreementDetailVo> getDetailById(@RequestParam Long id) {
        AgreementDetailVo agreementDetailVo = service.getDetailById(id);
        return Result.ok(agreementDetailVo);
    }
    
  • 编写Service层逻辑

    • LeaseAgreementService中增加如下内容

      AgreementDetailVo getDetailById(Long id);
      
    • LeaseAgreementServiceImpl中增加如下内容

      @Override
      public AgreementDetailVo getDetailById(Long id) {
      
          //1.查询租约信息
          LeaseAgreement leaseAgreement = leaseAgreementMapper.selectById(id);
          if (leaseAgreement == null) {
              return null;
          }
          //2.查询公寓信息
          ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(leaseAgreement.getApartmentId());
      
          //3.查询房间信息
          RoomInfo roomInfo = roomInfoMapper.selectById(leaseAgreement.getRoomId());
      
          //4.查询图片信息
          List<GraphVo> roomGraphVoList = graphInfoMapper.selectListByItemTypeAndId(ItemType.ROOM, leaseAgreement.getRoomId());
          List<GraphVo> apartmentGraphVoList = graphInfoMapper.selectListByItemTypeAndId(ItemType.APARTMENT, leaseAgreement.getApartmentId());
      
          //5.查询支付方式
          PaymentType paymentType = paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId());
      
          //6.查询租期
          LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseAgreement.getLeaseTermId());
      
          AgreementDetailVo agreementDetailVo = new AgreementDetailVo();
          BeanUtils.copyProperties(leaseAgreement, agreementDetailVo);
          agreementDetailVo.setApartmentName(apartmentInfo.getName());
          agreementDetailVo.setRoomNumber(roomInfo.getRoomNumber());
          agreementDetailVo.setApartmentGraphVoList(apartmentGraphVoList);
          agreementDetailVo.setRoomGraphVoList(roomGraphVoList);
          agreementDetailVo.setPaymentTypeName(paymentType.getName());
          agreementDetailVo.setLeaseTermMonthCount(leaseTerm.getMonthCount());
          agreementDetailVo.setLeaseTermUnit(leaseTerm.getUnit());
      
          return agreementDetailVo;
      }
      
2.2.3. 根据ID更新租约状态
  • 编写Controller层逻辑

    LeaseAgreementController中增加如下内容

    @Operation(summary = "根据id更新租约状态", description = "用于确认租约和提前退租")
    @PostMapping("updateStatusById")
    public Result updateStatusById(@RequestParam Long id, @RequestParam LeaseStatus leaseStatus) {
        LambdaUpdateWrapper<LeaseAgreement> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(LeaseAgreement::getId, id);
        updateWrapper.set(LeaseAgreement::getStatus, leaseStatus);
        service.update(updateWrapper);
        return Result.ok();
    }
    
2.2.4. 保存或更新租约
  • 编写Controller层逻辑

    LeaseAgreementController中增加如下内容

    @Operation(summary = "保存或更新租约", description = "用于续约")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LeaseAgreement leaseAgreement) {
        service.saveOrUpdate(leaseAgreement);
        return Result.ok();
    }
    
2.2.5. 根据房间ID获取可选支付方式
  • 编写Controller层逻辑

    PaymentTypeController中增加如下内容

    @Operation(summary = "根据房间id获取可选支付方式列表")
    @GetMapping("listByRoomId")
    public Result<List<PaymentType>> list(@RequestParam Long id) {
        List<PaymentType> list = service.listByRoomId(id);
        return Result.ok(list);
    }
    
  • 编写Service层逻辑

    PaymentTypeService中增加如下内容

    List<PaymentType> listByRoomId(Long id);
    

    PaymentTypeServiceImpl中增加如下内容

    @Override
    public List<PaymentType> listByRoomId(Long id) {
        return paymentTypeMapper.selectListByRoomId(id);
    }
    
2.2.6.根据房间ID获取可选租期
  • 编写Controller层逻辑

    LeaseTermController中增加如下内容

    @GetMapping("listByRoomId")
    @Operation(summary = "根据房间id获取可选获取租期列表")
    public Result<List<LeaseTerm>> list(@RequestParam Long id) {
        List<LeaseTerm> list = service.listByRoomId(id);
        return Result.ok(list);
    }
    
  • 编写Service层逻辑

    LeaseTermServcie中曾加如下内容

    List<LeaseTerm> listByRoomId(Long id);
    

    LeaseTermServiceImpl中增加如下内容

    @Override
    public List<LeaseTerm> listByRoomId(Long id) {
        return leaseTermMapper.selectListByRoomId(id);
    }
    
  • 18
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: springboot+vue项目实战是一种常见的开发模式,它将后端的业务逻辑和前端的用户界面分离开来,使得开发更加高效和灵活。在这种模式下,后端使用springboot框架进行开发,前端使用vue框架进行开发,两者通过RESTful API进行通信。这种模式具有易于维护、易于扩展、易于测试等优点,因此在实际项目中得到了广泛应用。 ### 回答2: SpringBootVue是现代web开发中非常流行的技术栈,他们分别代表了后端和前端的强大。结合起来,可以实现更加灵活和高效的web应用开发。本篇文章将介绍如何用SpringBootVue搭建一个完整的web应用,并展示如何运用他们的优势来提高开发效率和用户体验。 首先是SpringBoot后端的实现。使用SpringBoot可以快速搭建一个轻量级的后端架构,它包含了很多优秀的特性,例如自动配置,简单易用的API,以及集成了很多流行的依赖。开发者只需要一个简单的Maven或Gradle配置就可以开始编写Java代码了。 在实现中,我们使用了一个简单的用户管理系统,它包括了用户注册,登录,以及权限管理等基本功能。我们使用MySQL数据库存储用户信息,同时使用SpringSecurity来处理用户认证和授权。 Vue是一个非常强大的JavaScript框架,它拥有很多出色的特性,例如响应式页面设计,单页面应用等。结合Webpack,Vue可以使用诸如Vue Router,Vuex,Element UI等插件来加速开发。在本项目中,我们使用Vue来实现前端界面,同时使用Vue Router来处理页面路由,Vuex来处理状态管理,以及Element UI来提高视觉效果和交互体验。 最后我们将介绍如何使用SpringBootVue来组合一个完整的web应用。我们将使用axios来发起Ajax请求,同时使用SpringBoot提供的Restful API来处理请求,以及使用Vue显示数据和更新页面。我们也会展示如何使用SpringSecurity来保护API,并如何使用拦截器来控制用户权限。 综合起来,这个项目展示了如何使用SpringBootVue来构建一个完整的web应用,通过它你可以了解到SpringBootVue各自的优点,以及如何合理地结合它们来提高开发效率和用户体验。本项目代码开源可供下载、修改和使用。 ### 回答3: SpringBootVue.js是现在很热门的开发框架,它们都有自己的优势和特点,可以很好地实现前后端分离的开发模式。SpringBoot是一个快速开发框架,可以帮助我们快速搭建后端接口,而Vue.js则是一个轻量级的前端开发框架,可以帮助我们快速搭建前端页面和交互。 SpringBootVue.js可以非常完美地结合起来,形成一个完整的项目。在实践中,我们可以先使用SpringBoot搭建后端接口,然后使用Vue.js搭建前端页面和交互。在前后端分离的开发模式下,前后端的开发可以同时进行,互不干扰,提高了开发效率和代码质量。 具体项目实战中,我们可以根据需求来设计和实现项目。例如,我们可以使用SpringBoot来实现一个简单的登录注册接口,然后使用Vue.js来实现用户登录和注册页面。我们也可以使用SpringBoot实现一个简单的数据接口,然后使用Vue.js来实现数据的展示和交互功能。不管是哪种场景,SpringBootVue.js都可以帮助我们快速搭建一个完整的项目。 在项目实战中,我们还需要注意一些细节和技巧。例如,在使用SpringBoot时,我们应该合理地设计接口和参数,统一返回格式和错误码,便于前端调用和处理。在使用Vue.js时,我们应该注意组件的拆分和复用,尽量避免重复性的代码编写,提高代码的可维护性和可拓展性。同时,我们还应该注意前后端数据的交互和安全性,使用合适的加密和验证方式,避免数据泄露和攻击。 总之,SpringBootVue.js的结合是一个非常不错的选择,通过它们的协作,我们可以快速搭建高效、可维护、安全的项目。在实际项目中,我们需要结合具体场景和需求来设计和实现项目,同时注意细节和技巧,才能取得良好的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小林学习编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值