【尚庭公寓SpringBoot + Vue 项目实战】租约管理(十四)

【尚庭公寓SpringBoot + Vue 项目实战】租约管理(十四)


文章目录

      • 【尚庭公寓SpringBoot + Vue 项目实战】租约管理(十四)
        • 1、业务介绍
        • 2、逻辑介绍
        • 3、接口开发
          • 3.1、保存或更新租约信息
          • 3.2、根据条件分页查询租约列表
          • 3.3、根据ID查询租约信息
          • 3.4、根据ID删除租约信息
          • 3.5、根据ID更新租约状态
          • 3.6、定时检查租约状态

1、业务介绍

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

  1. 保存或更新租约信息
  2. 根据条件分页查询租约列表
  3. 根据ID查询租约信息
  4. 根据ID删除租约信息
  5. 根据ID更新租约状态
  6. 定时检查租约状态
2、逻辑介绍

接口定义-后台-租约管理-租约列表

image-20240617115436657

3、接口开发
3.1、保存或更新租约信息

查看接口

image-20240617115535417

代码开发

LeaseAgreementController中增加如下内容

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

    @Autowired
    private LeaseAgreementService agreementService;

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

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

查看接口

image-20240617121945789

  • 查看请求和响应的数据结构

    • 请求数据结构

      • currentsize为分页相关参数,分别表示当前所处页面每个页面的记录数

      • AgreementQueryVo为公寓的查询条件,详细结构如下:

        @Data
        @Schema(description = "租约查询实体")
        public class AgreementQueryVo {
        
            @Schema(description = "公寓所处省份id")
            private Long provinceId;
        
            @Schema(description = "公寓所处城市id")
            private Long cityId;
        
            @Schema(description = "公寓所处区域id")
            private Long districtId;
        
            @Schema(description = "公寓id")
            private Long apartmentId;
        
            @Schema(description = "房间号")
            private String roomNumber;
        
            @Schema(description = "用户姓名")
            private String name;
        
            @Schema(description = "用户手机号码")
            private String phone;
        }
        
    • 响应数据结构

      单个租约信息的结构可查看com.atguigu.lease.web.admin.vo.agreement.AgreementVo,内容如下:

      @Data
      @Schema(description = "租约信息")
      public class AgreementVo extends LeaseAgreement {
      
          @Schema(description = "签约公寓信息")
          private ApartmentInfo apartmentInfo;
      
          @Schema(description = "签约房间信息")
          private RoomInfo roomInfo;
      
          @Schema(description = "支付方式")
          private PaymentType paymentType;
      
          @Schema(description = "租期")
          private LeaseTerm leaseTerm;
      }
      

代码开发

LeaseAgreementController中增加如下内容

@Operation(summary = "根据条件分页查询租约列表")
@GetMapping("page")
public Result<IPage<AgreementVo>> page(@RequestParam long current, @RequestParam long size, AgreementQueryVo queryVo) {

    Page<AgreementVo> page = new Page<>(current, size);
    IPage<AgreementVo> result = agreementService.pageAgreement(page,queryVo);
    return Result.ok(result);
}

LeaseAgreementService中增加如下内容

IPage<AgreementVo> pageAgreementByQuery(IPage<AgreementVo> page, AgreementQueryVo queryVo);

LeaseAgreementServiceImpl中增加如下内容

@Autowired
private LeaseAgreementMapper leaseAgreementMapper;

/**
     * 分页查询
     *
     * @param page
     * @param queryVo
     * @return
     */
@Override
public IPage<AgreementVo> pageAgreement(Page<AgreementVo> page, AgreementQueryVo queryVo) {

    IPage<AgreementVo> agreementVoIPage = leaseAgreementMapper.pageAgreement(page,queryVo);

    return agreementVoIPage;
}

LeaseAgreementMapper中增加如下内容

IPage<AgreementVo> pageAgreementByQuery(IPage<AgreementVo> page, AgreementQueryVo queryVo);

LeaseAgreementMapper.xml中增加如下内容

<resultMap id="agreementVoMap" type="com.atguigu.lease.web.admin.vo.agreement.AgreementVo" 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"/>
    </association>
    <association property="roomInfo" javaType="com.atguigu.lease.model.entity.RoomInfo" autoMapping="true">
        <id property="id" column="room_id"/>
    </association>
    <association property="paymentType" javaType="com.atguigu.lease.model.entity.PaymentType" autoMapping="true">
        <id property="id" column="payment_type_id"/>
        <result property="name" column="payment_type_name"/>
    </association>
    <association property="leaseTerm" javaType="com.atguigu.lease.model.entity.LeaseTerm" autoMapping="true">
        <id property="id" column="lease_term_id"/>
    </association>
</resultMap>

<select id="pageAgreementByQuery" resultMap="agreementVoMap">
    select la.id,
           la.phone,
           la.name,
           la.identification_number,
           la.lease_start_date,
           la.lease_end_date,
           la.rent,
           la.deposit,
           la.status,
           la.source_type,
           la.additional_info,
           ai.id   apartment_id,
           ai.name apartment_name,
           ai.district_id,
           ai.district_name,
           ai.city_id,
           ai.city_name,
           ai.province_id,
           ai.province_name,
           ri.id   room_id,
           ri.room_number,
           pt.id   payment_type_id,
           pt.name payment_type_name,
           pt.pay_month_count,
           lt.id   lease_term_id,
           lt.month_count,
           lt.unit
    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
          payment_type pt
         on la.payment_type_id = pt.id and pt.is_deleted=0
             left join
          lease_term lt
         on la.lease_term_id = lt.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 queryVo.roomNumber != ''">
                and ri.room_number like concat('%',#{queryVo.roomNumber},'%')
            </if>
            <if test="queryVo.name != null and queryVo.name != ''">
                and la.name like concat('%',#{queryVo.name},'%')
            </if>
            <if test="queryVo.phone != null and queryVo.phone != ''">
                and la.phone like concat('%',#{queryVo.phone},'%')
            </if>
        </where>
</select>
3.3、根据ID查询租约信息

查看接口

image-20240617122500927

代码开发

LeaseAgreementController中增加如下内容

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

LeaseAgreementService中增加如下内容

AgreementVo getAgreementById(Long id);

LeaseAgreementServiceImpl中增加如下内容

    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;

    @Autowired
    private RoomInfoMapper roomInfoMapper;

    @Autowired
    private PaymentTypeMapper paymentTypeMapper;

    @Autowired
    private LeaseTermMapper leaseTermMapper;

    /**
     * 根据id查询租约信息
     *
     * @param id
     * @return
     */
    @Override
    public AgreementVo getLeaseAgreementById(Long id) {
        //查询租约信息
        LeaseAgreement leaseAgreement = this.getById(id);

        //查询签约公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(leaseAgreement.getApartmentId());

        //查询签约信息房间
        RoomInfo roomInfo = roomInfoMapper.selectById(leaseAgreement.getRoomId());

        //查询支付方式
        PaymentType paymentType = paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId());

        //查询租期
        LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseAgreement.getLeaseTermId());

        AgreementVo agreementVo = new AgreementVo();
        BeanUtils.copyProperties(leaseAgreement,agreementVo);
        agreementVo.setApartmentInfo(apartmentInfo);
        agreementVo.setRoomInfo(roomInfo);
        agreementVo.setPaymentType(paymentType);
        agreementVo.setLeaseTerm(leaseTerm);

        return agreementVo;
    }
3.4、根据ID删除租约信息

查看接口

image-20240617122845574

代码开发

LeaseAgreementController中增加如下内容

@Operation(summary = "根据id删除租约信息")
@DeleteMapping("removeById")
public Result removeById(@RequestParam Long id) {
    agreementService.removeById(id);
    return Result.ok();
}
3.5、根据ID更新租约状态

查看接口

image-20240617123014998

代码开发

后台管理系统需要多个修改租约状态的接口,例如修改租约状态为已取消修改租约状态为已退租等等。为省去重复编码,此处将多个接口合并为一个如下,注意,在生产中应避免这样的写法。

LeaseAgreementController中增加如下内容

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

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

  • 启用Spring Boot定时任务

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

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

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

    @Component
    public class ScheduledTasks {
    
        @Autowired
        private LeaseAgreementService leaseAgreementService;
    
        @Scheduled(cron = "0 0 0 * * *")
        public void checkLeaseStatus() {
    
            LambdaUpdateWrapper<LeaseAgreement> updateWrapper = new LambdaUpdateWrapper<>();
            Date now = new Date();
            updateWrapper.le(LeaseAgreement::getLeaseEndDate, now);
            updateWrapper.eq(LeaseAgreement::getStatus, LeaseStatus.SIGNED);
            updateWrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNED, LeaseStatus.WITHDRAWING);
    
            leaseAgreementService.update(updateWrapper);
        }
    }
    

    知识点:

    SpringBoot中的cron表达式语法如下

      ┌───────────── second (0-59)
      │ ┌───────────── minute (0 - 59)
      │ │ ┌───────────── hour (0 - 23)
      │ │ │ ┌───────────── day of the month (1 - 31)
      │ │ │ │ ┌───────────── month (1 - 12) (or JAN-DEC)
      │ │ │ │ │ ┌───────────── day of the week (0 - 7)
      │ │ │ │ │ │          (0 or 7 is Sunday, or MON-SUN)
      │ │ │ │ │ │
      * * * * * *
    

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/716378.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

STM32的通用定时器中断编程

如果遇到需要单片机产生严格时序的场景&#xff08;比如DAC输出特定模拟信号&#xff0c;GPIO口控制模拟开关&#xff09;&#xff0c;延时函数可能就无法胜任了。最近在工作时公司上级教会了我使用“令牌”思维&#xff08;中断标志位)编写单片机裸机程序&#xff0c;今天写一…

c++初始化列表(特点),隐式类型转换(示例,explicit关键字)

目录 初始化列表 定义 特点 必须使用初始化列表的成员变量 初始化顺序 隐式类型转换 示例 explicit关键字 初始化列表 Date::Date(const Date& d) {_year d._year;_month d._month;_day d._day; }Date::Date(const Date& d) :_year(d._year),_month(d._mon…

66aix AI生成系统-中文版安装

66aix是一款多功能的AI助手工具&#xff0c;可以帮助您生成独特的内容&#xff0c;美化和修改您的文章内容或&#xff0c;以及生成图像&#xff0c;去除图像背景。同时&#xff0c;它还包括完整功能的语音转换文本系统。 系统要求 PHP PHP 8 Extensions cURL, OpenSSL, mbstrin…

简易版 | 代码生成器(包含插件)

一、代码生成器 先导入依赖 <!-- Mybatis-Plus --> <dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.6</version> </dependency><!-- 代码生成器 --…

css之浮动float

float 设计初衷 仅仅是为了实现文字环绕 图文混排效果 特性 包裹 收缩 坚挺 隔绝 也就是BFC(Block Formating content) - “块级格式化上下文” 破坏 高度塌陷&#xff08;浮动使高度塌陷不是bug &#xff0c;而是标准&#xff0c;特性使然&#xff09; 清除浮动 clear 作…

MySQL----事务的隔离级别(附带每一级别实例截图)

先来回顾一下事务并发可能存在的三大问题&#xff1a; 脏读&#xff08;Dirty Read&#xff09;–不能接受 一个事务读取了另一个事务未提交的数据。例如当事务A和事务B并发执行时&#xff0c;当事务A更新后&#xff0c;事务B查询读取到A尚未提交的数据&#xff0c;此时事务A…

矩阵乘法的直觉

矩阵乘法是什么意思&#xff1f; 一种常见的观点是矩阵乘法缩放/旋转/倾斜几何平面&#xff1a; NSDT工具推荐&#xff1a; Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器 - REVIT导出3D模型插件 - 3D模型语义搜…

Django REST framework序列化器详解:普通序列化器与模型序列化器的选择与运用

系列文章目录 Django入门全攻略&#xff1a;从零搭建你的第一个Web项目Django ORM入门指南&#xff1a;从概念到实践&#xff0c;掌握模型创建、迁移与视图操作Django ORM实战&#xff1a;模型字段与元选项配置&#xff0c;以及链式过滤与QF查询详解Django ORM深度游&#xff…

实用技巧:跳过TCODE权限检查ALINK_CALL_TRANSACTION

RFC&#xff1a;ALINK_CALL_TRANSACTION 遇到tcode 提示没有权限打开&#xff0c;可以通过这个RFC,debug 修改检查值&#xff0c;打开TCODE。 适用于紧急情况 断点打在20行&#xff0c;SY-SUBRC 的值改成 1

碳化硅陶瓷膜出色的耐腐蚀性能

在科技日新月异的今天&#xff0c;材料科学的发展为各个领域带来了革命性的变革。碳化硅陶瓷膜&#xff0c;作为一种高性能的先进陶瓷材料&#xff0c;凭借其独特的物理和化学特性&#xff0c;正在逐步成为现代工业不可或缺的一部分。 碳化硅陶瓷膜&#xff0c;顾名思义&#x…

TensorRT的循环样例代码

官方文档地址 https://docs.nvidia.com/deeplearning/tensorrt/developer-guide/index.html#define-loops 非顺序结构,其内容确实有点乱,而且没有完整可运行的样例。 可以有多个IIteratorLayer, IRecurrenceLayer, and ILoopOutputLayer 层,最多有2个ITripLimitLayers层。 …

有人说考个PMP证两个星期搞定?

PMP考试的时间并不需要太久&#xff0c;如果高效用心备考的话在对考试需要准备的时间上也只需要2-3个月的业余时间。而一次考试的时间也只需要半天&#xff0c;一门科目&#xff0c;就是《PMBOK》的知识。所以如果想学习项目管理考PMP认证的朋友&#xff0c;大可放心参加考试。…

【递归、搜索与回溯】综合练习三

综合练习三 1.优美的排列3.N 皇后3.有效的数独4.解数独 点赞&#x1f44d;&#x1f44d;收藏&#x1f31f;&#x1f31f;关注&#x1f496;&#x1f496; 你的支持是对我最大的鼓励&#xff0c;我们一起努力吧!&#x1f603;&#x1f603; 1.优美的排列 题目链接&#xff1a;5…

用寄存器读取文件的数据的时候,寄存器怎么读取,寄存器的高位和低位分别是什么

如图所示 寄存器读取数据的时候&#xff0c;数据自身是什么样的&#xff0c;寄存器读的时候就原样存储在寄存器里&#xff0c;高位就是第一个数据&#xff0c;低位就是最后一个数据 寄存器读取数据原理是&#xff0c;将给定的二进制数反转&#xff0c;我理解成调转一下车头&…

驾驭未来:智能网关如何革新车联网体验

车联网&#xff08;Internet of Vehicles&#xff09;是一个跨领域的技术综合体&#xff0c;它基于物联网&#xff0c;利用先进的信息通信技术实现车与车、车与路、车与人、车与服务平台等的全方位网络连接。 龙兴物联智能网关是集成了多协议、多接口&#xff0c;具有综合数据采…

Three.js动效(第15辑):让前端手撕UI,拳打后端的效果。

three.js的设计效果非常复杂&#xff0c;后端提供的数据接口问题百出&#xff0c;这很容易让前端手撕UI、拳打后端&#xff0c;这种请详细该如何办呢&#xff1f; 前端 VS UI&#xff1a; 1. 沟通协调&#xff1a;UI和前端应该加强沟通&#xff0c;理解对方的工作难点和需求&…

「GitHub热点速览」7个学编程必看的开源项目!附链接可直达!

前言 今天特推的两个项目都是异常实用的项目&#xff0c;一个是直接将视频替换成另外一个语种&#xff1b;另外一个则是解决日志阅读问题的 tailspin&#xff0c;让你在成千上万条日志中快速定位特定的日志。 另外&#xff0c;还有两大集成者&#xff0c;一个是解决可观测性的…

去哪儿网PMO张璐受邀为第十三届中国PMO大会演讲嘉宾

全国PMO专业人士年度盛会 去哪儿网PMO张璐女士受邀为PMO评论主办的2024第十三届中国PMO大会演讲嘉宾&#xff0c;演讲议题为“数字化助力组织目标落地”。大会将于6月29-30日在北京举办&#xff0c;敬请关注&#xff01; 议题简要 本次议题将分享去哪儿流程标准化&工具化…

python17 字符串的常用操作

字符串常用方法 代码 字符串常用方法s i am SyLar, I LOVE YOU s1 s.capitalize()# 首字母变成大写 print(s1) s2s.lower() # 全部变成小写 print(s2) s3 s.upper()#全部变成大写 忽略大小写 推荐用这个 print(s3)title abc_def_hi print(标题:,title.title())s4 HelloWor…

2024年第三届数据统计与分析竞赛(A题)数学建模完整思路+完整代码全解全析

本次A题主要涉及正态分布、数据处理、自然语言处理等知识点 问题一题目重述&#xff1a;根据附件中抖音用户的评论数据&#xff0c;对抖音 APP 的“评分”和“点赞数”进行数据统计与分析&#xff0c;并使用假设检验判断这两个指标的分布是否服从正态分布。 接下来对问题一进…