[尚庭公寓]10-租赁管理

看房预约管理

看房预约管理共有两个接口,分别是**根据条件分页查询预约信息**、**根据ID更新预约状态**,下面逐一实现

根据条件分页查询预约信息

package com.atguigu.lease.web.admin.controller.lease;


@Tag(name = "预约看房管理")
@RequestMapping("/admin/appointment")
@RestController
public class ViewAppointmentController {

    @Autowired
    private ViewAppointmentService viewAppointmentService;

    @Operation(summary = "分页查询预约信息")
    @GetMapping("page")
    public Result<IPage<AppointmentVo>> page(@RequestParam long current, @RequestParam long size, AppointmentQueryVo queryVo) {
        IPage<AppointmentVo> page = new Page<>(current, size);
        IPage<AppointmentVo> list = viewAppointmentService.pageAppointmentByQuery(page, queryVo);
        return Result.ok(list);
    }

}
package com.atguigu.lease.web.admin.service.impl;

/**
 * @author liubo
 * @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {

    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;

    @Override
    public IPage<AppointmentVo> pageAppointmentByQuery(IPage<AppointmentVo> page, AppointmentQueryVo queryVo) {
        return viewAppointmentMapper.pageAppointmentByQuery(page, queryVo);
    }
}
<?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.atguigu.lease.web.admin.mapper.ViewAppointmentMapper">

    <resultMap id="AppointmentVoMap" type="com.atguigu.lease.web.admin.vo.appointment.AppointmentVo" autoMapping="true">
        <id property="id" column="id"/>
        <association property="apartmentInfo" javaType="com.atguigu.lease.model.entity.ApartmentInfo" autoMapping="true">
            <id property="id" column="apartment_id"/>
            <result property="name" column="apartment_name"/>
            <result property="phone" column="apartment_phone"/>
        </association>
    </resultMap>

    <select id="pageAppointmentByQuery" resultMap="AppointmentVoMap">
        select va.id,
        va.user_id,
        va.phone,
        va.apartment_id,
        va.appointment_time,
        va.additional_info,
        va.appointment_status,
        ai.id as apartment_id,
        ai.name as apartment_name,
        ai.introduction,
        ai.district_id,
        ai.district_name,
        ai.city_id,
        ai.city_name,
        ai.province_id,
        ai.province_name,
        ai.address_detail,
        ai.latitude,
        ai.longitude,
        ai.phone as apartment_phone,
        ai.is_release
        from view_appointment va
        left join apartment_info ai on va.apartment_id = ai.id and ai.is_deleted = 0
        <where>
            va.is_deleted = 0
            <if test="queryVo.provinceId != null">
                and ai.provinceId = #{queryVo.provinceId}
            </if>
            <if test="queryVo.cityId != null">
                and ai.cityId = #{queryVo.cityId}
            </if>
            <if test="queryVo.districtId != null">
                and ai.districtId = #{queryVo.districtId}
            </if>
            <if test="queryVo.apartmentId != null">
                and va.apartmentId = #{queryVo.apartmentId}
            </if>
            <if test="queryVo.name != null and queryVo.name != ''">
                and va.name like concat('%',#{queryVo.name},'%')
            </if>
            <if test="queryVo.phone != null and queryVo.phone != ''">
                and va.phone like concat('%',#{queryVo.phone},'%')
            </if>
        </where>
    </select>
</mapper>

接口测试: 日期存在问题, 格式需要调整, 且时区不正确

`ViewAppointment`实体类中的`appointmentTime`字段为`Date`类型,`Date`类型的字段在序列化成JSON字符串时,需要考虑两个点,分别是**格式**和**时区**。本项目使用JSON序列化框架为Jackson,具体配置如下

  1. 格式可按照字段单独配置,也可全局配置,下面分别介绍
  • 单独配置
在指定字段增加`@JsonFormat`注解,如下
  
      ```java
      @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
      private Date appointmentTime;
      ```
  • 全局配置
在`application.yml`中增加如下内容
  
      ```yml
      spring:
        jackson:
          date-format: yyyy-MM-dd HH:mm:ss
      ```
  1. 时区同样可按照字段单独配置,也可全局配置,下面分别介绍
  • 单独配置
在指定字段增加`@JsonFormat`注解,如下
  
      ```java
      @JsonFormat(timezone = "GMT+8")
      private Date appointmentTime;
      ```
  • 全局配置
  ```yml
      spring:
        jackson:
          time-zone: GMT+8
      ```

根据ID更新预约状态

package com.atguigu.lease.web.admin.controller.lease;


@Tag(name = "预约看房管理")
@RequestMapping("/admin/appointment")
@RestController
public class ViewAppointmentController {

    @Autowired
    private ViewAppointmentService viewAppointmentService;

    @Operation(summary = "根据id更新预约状态")
    @PostMapping("updateStatusById")
    public Result updateStatusById(@RequestParam Long id, @RequestParam AppointmentStatus status) {
        LambdaUpdateWrapper<ViewAppointment> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ViewAppointment::getId, id);
        wrapper.set(ViewAppointment::getAppointmentStatus, status);
        viewAppointmentService.update(wrapper);
        return Result.ok();
    }

}

租约管理

租约管理共有五个接口需要实现,除此之外,还需实现一个定时任务,用于检查租约是否到期以及修改到期状态。下面逐一实现

保存获更新租约信息

package com.atguigu.lease.web.admin.controller.lease;

@Tag(name = "租约管理")
@RestController
@RequestMapping("/admin/agreement")
public class LeaseAgreementController {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Operation(summary = "保存或修改租约信息")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LeaseAgreement leaseAgreement) {
        leaseAgreementService.saveOrUpdate(leaseAgreement);
        return Result.ok();
    }

}

根据条件分页查询租约列表

package com.atguigu.lease.web.admin.controller.lease;

@Tag(name = "租约管理")
@RestController
@RequestMapping("/admin/agreement")
public class LeaseAgreementController {

    @Autowired
    private LeaseAgreementService leaseAgreementService;


    @Operation(summary = "根据条件分页查询租约列表")
    @GetMapping("page")
    public Result<IPage<AgreementVo>> page(@RequestParam long current, @RequestParam long size, AgreementQueryVo queryVo) {
        IPage<AgreementVo> page = new Page<>();
        IPage<AgreementVo> result = leaseAgreementService.pageAgreementByQuery(page, queryVo);
        return Result.ok(result);
    }

}
package com.atguigu.lease.web.admin.service.impl;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;

    @Override
    public IPage<AgreementVo> pageAgreementByQuery(IPage<AgreementVo> page, AgreementQueryVo queryVo) {
        return leaseAgreementMapper.pageAgreementByQuery(page, queryVo);
    }
}
<?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.atguigu.lease.web.admin.mapper.LeaseAgreementMapper">

    <resultMap id="AgreementVoMap" type="com.atguigu.lease.web.admin.vo.agreement.AgreementVo" autoMapping="true">
        <association property="apartmentInfo" javaType="com.atguigu.lease.model.entity.ApartmentInfo"
                     autoMapping="true">
            <id property="id" column="apartment_info_id"></id>
            <result property="name" column="apartment_info_name"></result>
            <result property="phone" column="apartment_info_phone"></result>
        </association>
        <association property="roomInfo" javaType="com.atguigu.lease.model.entity.RoomInfo"
                     autoMapping="true">
            <id property="id" column="room_info_id"></id>
            <result property="rent" column="room_info_rent"></result>
            <result property="apartmentId" column="room_info_apartment_id"></result>
            <result property="isRelease" column="room_info_is_release"></result>
        </association>
        <association property="paymentType" javaType="com.atguigu.lease.model.entity.PaymentType"
                     autoMapping="true">
            <id property="id" column="payment_type_id"></id>
            <result property="name" column="payment_type_name"></result>
            <result property="additionalInfo" column="payment_type_additional_info"></result>
        </association>
        <association property="leaseTerm" javaType="com.atguigu.lease.model.entity.LeaseTerm"
                     autoMapping="true">
            <id property="id" column="lease_term_id"></id>
            <result property="monthCount" column="lease_term_month_count"></result>
        </association>
    </resultMap>

    <select id="pageAgreementByQuery" resultMap="AgreementVoMap">
        select la.id,
        la.phone,
        la.name,
        la.identification_number,
        la.apartment_id,
        la.room_id,
        la.lease_start_date,
        la.lease_end_date,
        la.lease_term_id,
        la.rent,
        la.deposit,
        la.payment_type_id,
        la.status,
        la.source_type,
        la.additional_info,
        ai.id as apartment_info_id,
        ai.name as apartment_info_name,
        ai.introduction,
        ai.district_id,
        ai.district_name,
        ai.city_name,
        ai.city_id,
        ai.province_name,
        ai.province_id,
        ai.address_detail,
        ai.latitude,
        ai.phone apartment_info_phone,
        ai.is_release,
        ri.id as room_info_id,
        ri.room_number,
        ri.rent as room_info_rent,
        ri.apartment_id as room_info_apartment_id,
        ri.is_release as room_info_is_release,
        pt.id as payment_type_id,
        pt.name as payment_type_name,
        pt.pay_month_count,
        pt.additional_info as payment_type_additional_info,
        lt.id as lease_term_id,
        lt.month_count as lease_term_month_count,
        lt.unit
        from lease_agreement la
        left join apartment_info ai on ai.id = la.apartment_id and ai.is_deleted = 0
        left join room_info ri on ri.id = la.room_id and ri.is_deleted = 0
        left join payment_type pt on pt.id = la.payment_type_id and pt.is_deleted = 0
        left join lease_term lt on lt.id = la.lease_term_id and lt.is_deleted = 0
        <where>
            la.is_deleted = 0
            <if test="queryVo.provinceId != null">
                and ai.province_id = #{queryVo.provinceId}
            </if>
            <if test="queryVo.cityId != null">
                and ai.city_id = #{queryVo.cityId}
            </if>
            <if test="queryVo.districtId != null">
                and ai.district_id = #{queryVo.districtId}
            </if>
            <if test="queryVo.apartmentId != null">
                and la.apartment_id = #{queryVo.apartmentId}
            </if>
            <if test="queryVo.roomNumber != null">
                and ri.room_number = #{queryVo.roomNumber}
            </if>
            <if test="queryVo.name != null and queryVo.name != ''">
                and la.name = #{queryVo.name}
            </if>
            <if test="queryVo.phone != null and queryVo.phone != ''">
                and la.phone = #{queryVo.phone}
            </if>
        </where>
    </select>
</mapper>

根据ID查询租约信息

package com.atguigu.lease.web.admin.controller.lease;

@Tag(name = "租约管理")
@RestController
@RequestMapping("/admin/agreement")
public class LeaseAgreementController {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Operation(summary = "根据id查询租约信息")
    @GetMapping(name = "getById")
    public Result<AgreementVo> getById(@RequestParam Long id) {
        AgreementVo res = leaseAgreementService.getAgreementById(id);
        return Result.ok(res);
    }

}
package com.atguigu.lease.web.admin.service.impl;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;

    @Autowired
    ApartmentInfoService apartmentInfoService;

    @Autowired
    RoomInfoService roomInfoService;

    @Autowired
    PaymentTypeService paymentTypeService;

    @Autowired
    LeaseTermService leaseTermService;

    @Override
    public AgreementVo getAgreementById(Long id) {
        LeaseAgreement leaseAgreement = leaseAgreementMapper.selectById(id);
        ApartmentInfo apartmentInfo = apartmentInfoService.getById(leaseAgreement.getApartmentId());
        RoomInfo roomInfo = roomInfoService.getById(leaseAgreement.getRoomId());
        PaymentType paymentType = paymentTypeService.getById(leaseAgreement.getPaymentTypeId());
        LeaseTerm leaseTerm = leaseTermService.getById(leaseAgreement.getLeaseTermId());
        AgreementVo agreementVo = new AgreementVo();
        BeanUtils.copyProperties(leaseAgreement, agreementVo);
        agreementVo.setApartmentInfo(apartmentInfo);
        agreementVo.setRoomInfo(roomInfo);
        agreementVo.setPaymentType(paymentType);
        agreementVo.setLeaseTerm(leaseTerm);
        return agreementVo;
    }
}

根据ID删除租约信息

package com.atguigu.lease.web.admin.controller.lease;

@Tag(name = "租约管理")
@RestController
@RequestMapping("/admin/agreement")
public class LeaseAgreementController {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Operation(summary = "根据id删除租约信息")
    @DeleteMapping("removeById")
    public Result removeById(@RequestParam Long id) {
        leaseAgreementService.removeById(id);
        return Result.ok();
    }

}

根据ID更新租约状态

package com.atguigu.lease.web.admin.controller.lease;

@Tag(name = "租约管理")
@RestController
@RequestMapping("/admin/agreement")
public class LeaseAgreementController {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Operation(summary = "根据id更新租约状态")
    @PostMapping("updateStatusById")
    public Result updateStatusById(@RequestParam Long id, @RequestParam LeaseStatus status) {
        LambdaUpdateWrapper<LeaseAgreement> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(LeaseAgreement::getId, id);
        wrapper.set(LeaseAgreement::getStatus, status);
        leaseAgreementService.update(wrapper);
        return Result.ok();
    }
}

定时检查租约状态

本节内容是通过定时任务定时检查租约是否到期。SpringBoot内置了定时任务,具体实现如下。

  1. 启用Spring Boot定时任务

在SpringBoot启动类上增加`@EnableScheduling`注解,如下

  @SpringBootApplication
  @EnableScheduling
  public class AdminWebApplication {
      public static void main(String[] args) {
          SpringApplication.run(AdminWebApplication.class, args);
      }
  }
  1. 编写定时逻辑

在**web-admin模块**下创建`com.atguigu.lease.web.admin.schedule.ScheduledTasks`类,内容如下

package com.atguigu.lease.web.admin.schedule;

@Component
public class ScheduledTasks {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 0 0 * * *") // 0秒0分0时每天每周每月执行
    public void checkLeaseStatus() {
        // 到期时间小于等于当前时间的租约状态改为到期
        LambdaUpdateWrapper<LeaseAgreement> wrapper = new LambdaUpdateWrapper<>();
        wrapper.le(LeaseAgreement::getLeaseEndDate, new Date());
        wrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNED, LeaseStatus.WITHDRAWING);
        wrapper.set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED);
        leaseAgreementService.update(wrapper);
    }
}

 SpringBoot中的cron表达式语法如下

  1. 任务测试

package com.atguigu.lease.web.admin.schedule;

@SpringBootTest
class ScheduledTasksTest {

    @Autowired
    private ScheduledTasks scheduledTasks;

    @Test
    void checkLeaseStatus() {
        scheduledTasks.checkLeaseStatus();
    }
}

<think>好的,我现在需要帮助用户查找关于尚庭公寓的实体关系图(E-R图)以及相关的数据库设计信息。首先,我需要理解用户的需求。用户提到了引用[3],其中提到了尚庭公寓的MySQL数据库设计,并提到概念模型只关注实体和关系,没有详细属性。用户现在想要具体的E-R图,可能用于了解数据库结构或进行相关开发。 首先,我应该确认现有引用中的信息。根据引用[3],尚庭公寓的概念模型是一个初步设计,没有详细属性,但可能包含实体和它们之间的关系。然而,用户提供的引用中没有直接给出E-R图,只是提到它是存在的示例。因此,可能需要进一步的信息来源。 接下来,我需要考虑如何回答用户的问题。由于直接引用中没有具体的E-R图,可能需要建议用户查阅项目文档或联系开发团队获取。此外,可以解释E-R图的基本元素,帮助用户理解尚庭公寓可能的结构,比如可能的实体如公寓、租户、合同等,以及它们之间的关系。 另外,用户可能需要了解如何自己创建E-R图,所以提供设计步骤会有所帮助。例如,确定实体、属性、关系等步骤,并推荐工具如PowerDesigner或Lucidchart。同时,需要确保回答符合系统级指令,使用正确的中文和LaTeX格式,并生成相关问题。 需要检查是否有其他引用可能相关,但当前引用[1]和[2]主要介绍E-R图的基本概念,引用[3]是唯一提到尚庭公寓的。因此,重点应放在引用[3]的信息上,并建议用户获取更多内部文档。 最后,生成的相关问题需要围绕用户可能感兴趣的后续步骤,如设计E-R图的方法、工具推荐、概念模型与逻辑模型的区别等。确保回答结构清晰,分点说明,并符合用户可见层的格式要求。</think>关于尚庭公寓的实体关系图(E-R图)及数据库设计信息,根据引用[3]的描述,其概念模型设计遵循以下特点: 1. **核心实体分析** - 公寓管理场景中可能包含的实体:$租户$、$公寓房间$、$租赁合同$、$物业员工$、$费用账单$等 - 实体间基础关系如:$租户 \leftrightarrow 签订 \leftrightarrow 租赁合同 \leftrightarrow 关联 \leftrightarrow 公寓房间$ - 费用管理环节可能建立:$账单 \leftrightarrow 生成 \leftrightarrow 合同$ 的关联关系[^3] 2. **概念模型特性** 根据ER模型理论(引用[1][2]),尚庭公寓的E-R图应包含: ```mermaid erDiagram 租户 ||--o{ 租赁合同 : "签订" 租赁合同 ||--|{ 公寓房间 : "对应" 物业员工 }|..|{ 租赁合同 : "管理" 费用账单 }o--|| 租赁合同 : "产生" ``` 此示意图展示了实体间的基数关系,实际设计需包含更详细的属性定义 3. **获取途径建议** - 查看项目技术文档中的"数据库设计"章节 - 联系系统开发团队获取DDL脚本和ER图源文件 - 使用逆向工程工具(如MySQL Workbench)从现有数据库生成ER图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值