【尚庭公寓SpringBoot + Vue 项目实战】移动端找房功能(二十一)

news2025/2/8 11:48:15

【尚庭公寓SpringBoot + Vue 项目实战】移动端找房功能(二十一)


文章目录

      • 【尚庭公寓SpringBoot + Vue 项目实战】移动端找房功能(二十一)
        • 1、业务介绍
        • 2、接口开发
          • 2.1、地区信息
          • 2.2、获取全部支付方式列表
          • 2.3、房间信息
            • 2.2.1. 根据条件分页查询房间列表
            • 2.2.2. 根据ID查询房间详细信息
            • 2.2.3.根据公寓ID分页查询房间列表
          • 2.4、 公寓信息

1、业务介绍

找房模块一共分为三部分

  1. 地区信息
    • 查询省份列表
    • 根据省份id查询城市列表
    • 根据城市id查询区县列表
  2. 公寓信息
  3. 房间信息
    • 根据条件分页查询房间列表
    • 根据id查询房间详细信息
    • 根据公寓id分页查询房间列表

image-20240621162211103

2、接口开发
2.1、地区信息

对于找房模块,地区信息共需三个接口,分别是查询省份列表根据省份ID查询城市列表根据城市ID查询区县列表,具体实现如下

RegionController中增加如下内容

@Tag(name = "地区信息")
@RestController
@RequestMapping("/app/region")
public class RegionController {

    @Autowired
    private ProvinceInfoService provinceInfoService;

    @Autowired
    private CityInfoService cityInfoService;

    @Autowired
    private DistrictInfoService districtInfoService;

    @Operation(summary="查询省份信息列表")
    @GetMapping("province/list")
    public Result<List<ProvinceInfo>> listProvince(){
        List<ProvinceInfo> list = provinceInfoService.list();
        return Result.ok(list);
    }

    @Operation(summary="根据省份id查询城市信息列表")
    @GetMapping("city/listByProvinceId")
    public Result<List<CityInfo>> listCityInfoByProvinceId(@RequestParam Long id){
        LambdaQueryWrapper<CityInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CityInfo::getProvinceId,id);
        List<CityInfo> list = cityInfoService.list(queryWrapper);
        return Result.ok(list);
    }

    @GetMapping("district/listByCityId")
    @Operation(summary="根据城市id查询区县信息")
    public Result<List<DistrictInfo>> listDistrictInfoByCityId(@RequestParam Long id){
        LambdaQueryWrapper<DistrictInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DistrictInfo::getCityId,id);
        List<DistrictInfo> list = districtInfoService.list(queryWrapper);
        return Result.ok(list);
    }
}
2.2、获取全部支付方式列表

对于找房模块,支付方式共需一个接口,即获取全部支付方式列表,具体实现如下

PaymentTypeController中增加如下内容

@Tag(name = "支付方式接口")
@RestController
@RequestMapping("/app/payment")
public class PaymentTypeController {

    @Autowired
    private PaymentTypeService service;

    @Operation(summary = "获取全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> list() {
        List<PaymentType> list = service.list();
        return Result.ok(list);
    }
}
2.3、房间信息

房间信息共需三个接口,分别是根据条件分页查询房间列表根据ID查询房间详细信息根据公寓ID分页查询房间列表,下面逐一实现

首先在RoomController中注入RoomInfoService,如下

@Tag(name = "房间信息")
@RestController
@RequestMapping("/app/room")
public class RoomController {

    @Autowired
    RoomInfoService roomInfoService;
}
2.2.1. 根据条件分页查询房间列表
  • 查看请求和响应的数据结构

    • 请求数据结构

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

      • RoomQueryVo为房间的查询条件,详细结构如下:

        @Data
        @Schema(description = "房间查询实体")
        public class RoomQueryVo {
        
            @Schema(description = "省份Id")
            private Long provinceId;
        
            @Schema(description = "城市Id")
            private Long cityId;
        
            @Schema(description = "区域Id")
            private Long districtId;
        
            @Schema(description = "最小租金")
            private BigDecimal minRent;
        
            @Schema(description = "最大租金")
            private BigDecimal maxRent;
        
            @Schema(description = "支付方式")
            private Long paymentTypeId;
        
            @Schema(description = "价格排序方式", allowableValues = {"desc", "asc"})
            private String orderType;
        
        }
        
    • 响应数据结构

      单个房间信息记录可查看com.atguigu.lease.web.app.vo.room.RoomItemVo,内容如下:

      @Schema(description = "APP房间列表实体")
      @Data
      public class RoomItemVo {
      
          @Schema(description = "房间id")
          private Long id;
      
          @Schema(description = "房间号")
          private String roomNumber;
      
          @Schema(description = "租金(元/月)")
          private BigDecimal rent;
      
          @Schema(description = "房间图片列表")
          private List<GraphVo> graphVoList;
      
          @Schema(description = "房间标签列表")
          private List<LabelInfo> labelInfoList;
      
          @Schema(description = "房间所属公寓信息")
          private ApartmentInfo apartmentInfo;
      }
      
  • 编写Controller层逻辑

    RoomController中增加如下内容

    @Operation(summary = "分页查询房间列表")
    @GetMapping("pageItem")
    public Result<IPage<RoomItemVo>> pageItem(@RequestParam long current, @RequestParam long size, RoomQueryVo queryVo) {
        Page<RoomItemVo> page = new Page<>(current, size);
        IPage<RoomItemVo> list = roomInfoService.pageRoomItemByQuery(page, queryVo);
        return Result.ok(list);
    }
    
  • 编写Service层逻辑

    • RoomInfoService中增加如下内容

      IPage<RoomItemVo> pageRoomItemByQuery(Page<RoomItemVo> page, RoomQueryVo queryVo);
      
    • RoomInfoServiceImpl中增加如下内容

      @Override
      public IPage<RoomItemVo> pageRoomItemByQuery(Page<RoomItemVo> page, RoomQueryVo queryVo) {
          return roomInfoMapper.pageRoomItemByQuery(page, queryVo);
      }
      
  • 编写Mapper层逻辑

    • RoomInfoMapper中增加如下内容

      IPage<RoomItemVo> pageRoomItemByQuery(Page<RoomItemVo> page, RoomQueryVo queryVo);
      
    • RoomInfoMapper中增加如下内容

      <!-- result map -->
      <resultMap id="RoomItemVoMap" type="com.atguigu.lease.web.app.vo.room.RoomItemVo" autoMapping="true">
          <id column="id" property="id"/>
          <!--映射公寓信息-->
          <association property="apartmentInfo" javaType="com.atguigu.lease.model.entity.ApartmentInfo"
                       autoMapping="true">
              <id column="id" property="id"/>
          </association>
          <!--映射图片列表-->
          <collection property="graphVoList" ofType="com.atguigu.lease.web.app.vo.graph.GraphVo"
                      select="selectGraphVoListByRoomId" column="id"/>
          <!--映射标签列表-->
          <collection property="labelInfoList" ofType="com.atguigu.lease.model.entity.LabelInfo"
                      select="selectLabelInfoListByRoomId" column="id"/>
      </resultMap>
      
      <!-- 根据条件查询房间列表 -->
      <select id="pageItem" resultMap="RoomItemVoMap">
          select
              ri.id,
              ri.room_number,
              ri.rent,
              ai.id apartment_id,
              ai.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,
              ai.is_release
          from room_info ri
          left join apartment_info ai on ri.apartment_id = ai.id and ai.is_deleted = 0
          <where>
              ri.is_deleted = 0
              and ri.is_release = 1
              and ri.id not in(
                  select room_id
                  from lease_agreement
                  where is_deleted = 0
                  and status in(2,5))
              <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.minRent != null and queryVo.maxRent != null">
                  and (ri.rent &gt;= #{queryVo.minRent} and ri.rent &lt;= #{queryVo.maxRent})
              </if>
              <if test="queryVo.paymentTypeId != null">
                  and ri.id in (
                  select
                  room_id
                  from room_payment_type
                  where is_deleted = 0
                  and payment_type_id = #{queryVo.paymentTypeId}
                  )
              </if>
          </where>
          <if test="queryVo.orderType == 'desc' or queryVo.orderType == 'asc'">
              order by ri.rent ${queryVo.orderType}
          </if>
      </select>
      
      <!-- 根据房间ID查询图片列表 -->
      <select id="selectGraphVoListByRoomId" resultType="com.atguigu.lease.web.app.vo.graph.GraphVo">
          select id,
                 name,
                 item_type,
                 item_id,
                 url
          from graph_info
          where is_deleted = 0
            and item_type = 2
            and item_id = #{id}
      </select>
      
      <!-- 根据公寓ID查询标签列表 -->
      <select id="selectLabelInfoListByRoomId" resultType="com.atguigu.lease.model.entity.LabelInfo">
          select id,
                 type,
                 name
          from label_info
          where is_deleted = 0
            and id in (select label_id
                       from room_label
                       where is_deleted = 0
                         and room_id = #{id})
      </select>
      

      知识点

      • xml文件<>的转义

        由于xml文件中的<>是特殊符号,需要转义处理。

        原符号转义符号
        <&lt;
        >&gt;
      • Mybatis-Plus分页插件注意事项

        使用Mybatis-Plus的分页插件进行分页查询时,如果结果需要使用<collection>进行映射,只能使用**嵌套查询(Nested Select for Collection),而不能使用嵌套结果映射(Nested Results for Collection)**。

        嵌套查询嵌套结果映射是Collection映射的两种方式,下面通过一个案例进行介绍

        例如有room_infograph_info两张表,其关系为一对多,如下
        在这里插入图片描述

        现需要查询房间列表及其图片信息,期望返回的结果如下

        [
            {
                "id": 1,
                "number": 201,
                "rent": 2000,
                "graphList": [
                    {
                        "id": 1,
                        "url": "http://",
                        "roomId": 1
                    },
                    {
                        "id": 2,
                        "url": "http://",
                        "roomId": 1
                    }
                ]
            },
            {
                "id": 2,
                "number": 202,
                "rent": 3000,
                "graphList": [
                    {
                        "id": 3,
                        "url": "http://",
                        "roomId": 2
                    },
                    {
                        "id": 4,
                        "url": "http://",
                        "roomId": 2
                    }
                ]
            }
        ]
        

        为得到上述结果,可使用以下两种方式

        • 嵌套结果映射

          <select id="selectRoomPage" resultMap="RoomPageMap">
              select ri.id room_id,
                     ri.number,
                     ri.rent,
              	   gi.id graph_id,
                     gi.url,
                     gi.room_id
              from room_info ri
             	left join graph_info gi on ri.id=gi.room_id
          </select>
          
          <resultMap id="RoomPageMap" type="RoomInfoVo" autoMapping="true">
              <id column="room_id" property="id"/>
              <collection property="graphInfoList" ofType="GraphInfo" autoMapping="true">
                  <id column="graph_id" property="id"/>
              </collection>
          </resultMap>
          

          这种方式的执行原理如下图所示

        在这里插入图片描述

        • 嵌套查询

          <select id="selectRoomPage" resultMap="RoomPageMap">
              select id,
                     number,
                     rent
              from room_info
          </select>
          
          <resultMap id="RoomPageMap" type="RoomInfoVo" autoMapping="true">
              <id column="id" property="id"/>
              <collection property="graphInfoList" ofType="GraphInfo" select="selectGraphByRoomId" 				 	column="id"/>
          </resultMap>
          
          <select id="selectGraphByRoomId" resultType="GraphInfo">
              select id,
                     url,
              	   room_id
              from graph_info
              where room_id = #{id}
          </select>
          

          这种方法使用两个独立的查询语句来获取一对多关系的数据。首先,Mybatis会执行主查询来获取room_info列表,然后对于每个room_info,Mybatis都会执行一次子查询来获取其对应的graph_info

          在这里插入图片描述

        若现在使用MybatisPlus的分页插件进行分页查询,假如查询的内容是第1页,每页2条记录,则上述两种方式的查询结果分别是

        • 嵌套结果映射

        在这里插入图片描述

        • 嵌套查询

          在这里插入图片描述

        显然嵌套结果映射的分页逻辑是存在问题的。

2.2.2. 根据ID查询房间详细信息
  • 查看响应数据结构

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

    @Data
    @Schema(description = "APP房间详情")
    public class RoomDetailVo extends RoomInfo {
    
        @Schema(description = "所属公寓信息")
        private ApartmentItemVo apartmentItemVo;
    
        @Schema(description = "图片列表")
        private List<GraphVo> graphVoList;
    
        @Schema(description = "属性信息列表")
        private List<AttrValueVo> attrValueVoList;
    
        @Schema(description = "配套信息列表")
        private List<FacilityInfo> facilityInfoList;
    
        @Schema(description = "标签信息列表")
        private List<LabelInfo> labelInfoList;
    
        @Schema(description = "支付方式列表")
        private List<PaymentType> paymentTypeList;
    
        @Schema(description = "杂费列表")
        private List<FeeValueVo> feeValueVoList;
    
        @Schema(description = "租期列表")
        private List<LeaseTerm> leaseTermList;
    
    }
    
  • 编写Controller层逻辑

    RoomController中增加如下内容

    @Operation(summary = "根据id获取房间的详细信息")
    @GetMapping("getDetailById")
    public Result<RoomDetailVo> getDetailById(@RequestParam Long id) {
        RoomDetailVo roomInfo = service.getDetailById(id);
        return Result.ok(roomInfo);
    }
    
  • 编写查询房间信息逻辑

    • 编写Service层逻辑

      • RoomInfoService中增加如下内容

        RoomDetailVo getDetailById(Long id);
        
      • RoomInfoServiceImpl中增加如下内容

        @Override
        public RoomDetailVo getDetailById(Long id) {
            //1.查询房间信息
            RoomInfo roomInfo = roomInfoMapper.selectById(id);
            if (roomInfo == null) {
                return null;
            }
            //2.查询图片
            List<GraphVo> graphVoList = graphInfoMapper.selectListByItemTypeAndId(ItemType.ROOM, id);
            //3.查询租期
            List<LeaseTerm> leaseTermList = leaseTermMapper.selectListByRoomId(id);
            //4.查询配套
            List<FacilityInfo> facilityInfoList = facilityInfoMapper.selectListByRoomId(id);
            //5.查询标签
            List<LabelInfo> labelInfoList = labelInfoMapper.selectListByRoomId(id);
            //6.查询支付方式
            List<PaymentType> paymentTypeList = paymentTypeMapper.selectListByRoomId(id);
            //7.查询基本属性
            List<AttrValueVo> attrValueVoList = attrValueMapper.selectListByRoomId(id);
            //8.查询杂费信息
            List<FeeValueVo> feeValueVoList = feeValueMapper.selectListByApartmentId(roomInfo.getApartmentId());
            //9.查询公寓信息
            ApartmentItemVo apartmentItemVo = apartmentInfoService.selectApartmentItemVoById(roomInfo.getApartmentId());
        
            RoomDetailVo roomDetailVo = new RoomDetailVo();
            BeanUtils.copyProperties(roomInfo, roomDetailVo);
        
            roomDetailVo.setApartmentItemVo(apartmentItemVo);
            roomDetailVo.setGraphVoList(graphVoList);
            roomDetailVo.setAttrValueVoList(attrValueVoList);
            roomDetailVo.setFacilityInfoList(facilityInfoList);
            roomDetailVo.setLabelInfoList(labelInfoList);
            roomDetailVo.setPaymentTypeList(paymentTypeList);
            roomDetailVo.setFeeValueVoList(feeValueVoList);
            roomDetailVo.setLeaseTermList(leaseTermList);
        
            return roomDetailVo;
        }
        
    • 编写Mapper层逻辑

      • 编写查询房间图片逻辑

        • GraphInfoMapper中增加如下内容

          List<GraphVo> selectListByItemTypeAndId(ItemType itemType, Long id);
          
        • GraphInfoMapper.xml增加如下内容

          <select id="selectListByItemTypeAndId" resultType="com.atguigu.lease.web.app.vo.graph.GraphVo">
              select name,
                     url
              from graph_info
              where is_deleted = 0
                and item_type = #{itemType}
                and item_id = #{id}
          </select>
          
      • 编写查询房间可选租期逻辑

        • LeaseTermMapper中增加如下内容

          List<LeaseTerm> selectListByRoomId(Long id);
          
        • LeaseTermMapper.xml中增加如下内容

          <select id="selectListByRoomId" resultType="com.atguigu.lease.model.entity.LeaseTerm">
              select id,
                     month_count,
                     unit
              from lease_term
              where is_deleted = 0
                and id in (select lease_term_id
                           from room_lease_term
                           where is_deleted = 0
                             and room_id = #{id})
          </select>
          
      • 编写查询房间配套逻辑

        • FacilityInfoMapper中增加如下内容

          List<FacilityInfo> selectListByRoomId(Long id);
          
        • FacilityInfoMapper.xml中增加如下内容

          <select id="selectListByRoomId" resultType="com.atguigu.lease.model.entity.FacilityInfo">
              select id,
                     type,
                     name,
                     icon
              from facility_info
              where is_deleted = 0
                and id in (select facility_id
                           from room_facility
                           where is_deleted = 0
                             and room_id = #{id})
          </select>
          
      • 编写查询房间标签逻辑

        • LabelInfoMapper中增加如下内容

          List<LabelInfo> selectListByRoomId(Long id);
          
        • LabelInfoMapper.xml中增加如下内容

          <select id="selectListByRoomId" resultType="com.atguigu.lease.model.entity.LabelInfo">
              select id,
                     type,
                     name
              from label_info
              where is_deleted = 0
                and id in (select label_id
                           from room_label
                           where is_deleted = 0
                             and room_id = #{id})
          </select>
          
      • 编写查询房间可选支付方式逻辑

        • PaymentTypeMapper中增加如下内容

          List<PaymentType> selectListByRoomId(Long id);
          
        • PaymentTypeMapper.xml中增加如下内容

          <select id="selectListByRoomId" resultType="com.atguigu.lease.model.entity.PaymentType">
              select id,
                     name,
                     pay_month_count,
                     additional_info
              from payment_type
              where is_deleted = 0
                and id in (select payment_type_id
                           from room_payment_type
                           where is_deleted = 0
                             and room_id = #{id})
          </select>
          
      • 编写查询房间属性逻辑

        • AttrValueMapper中增加如下内容

          List<AttrValueVo> selectListByRoomId(Long id);
          
        • AttrValueMapper.xml中增加如下内容

          <select id="selectListByRoomId" resultType="com.atguigu.lease.web.app.vo.attr.AttrValueVo">
              select av.id,
                     av.name,
                     av.attr_key_id,
                     ak.name attr_key_name
              from attr_value av
                       left join attr_key ak on av.attr_key_id = ak.id and ak.is_deleted = 0
              where av.is_deleted = 0
                and av.id in (select attr_value_id
                              from room_attr_value
                              where is_deleted = 0
                                and room_id = #{id})
          </select>
          
      • 编写查询房间杂费逻辑

        • FeeValueMapper中增加如下内容

          List<FeeValueVo> selectListByApartmentId(Long id);
          
        • FeeValueMapper.xml中增加如下内容

          <select id="selectListByApartmentId" resultType="com.atguigu.lease.web.app.vo.fee.FeeValueVo">
              select fv.id,
                     fv.name,
                     fv.unit,
                     fv.fee_key_id,
                     fk.name fee_key_name
              from fee_value fv
                       left join fee_key fk on fv.fee_key_id = fk.id and fk.is_deleted = 0
              where fv.is_deleted = 0
                and fv.id in (select fee_value_id
                              from apartment_fee_value
                              where is_deleted = 0
                                and apartment_id = #{id})
          </select>
          
  • 编写查询所属公寓信息逻辑

    • 编写Service层逻辑

      ApartmentInfoService中增加如下内容

      ApartmentItemVo selectApartmentItemVoById(Long id);
      

      ApartmentInfoServiceImpl中增加如下内容

      @Override
      public ApartmentItemVo selectApartmentItemVoById(Long id) {
      
          ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(id);
      
          List<LabelInfo> labelInfoList = labelInfoMapper.selectListByApartmentId(id);
      
          List<GraphVo> graphVoList = graphInfoMapper.selectListByItemTypeAndId(ItemType.APARTMENT, id);
      
          BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(id);
      
          ApartmentItemVo apartmentItemVo = new ApartmentItemVo();
          BeanUtils.copyProperties(apartmentInfo, apartmentItemVo);
      
          apartmentItemVo.setGraphVoList(graphVoList);
          apartmentItemVo.setLabelInfoList(labelInfoList);
          apartmentItemVo.setMinRent(minRent);
          return apartmentItemVo;
      }
      
  • 编写Mapper层逻辑

    • 编写查询标签信息逻辑

      • LabelInfoMapper中增加如下内容

          List<LabelInfo> selectListByApartmentId(Long id);
        
      • LabelInfoMapper.xml中增加如下内容

          <select id="selectListByApartmentId" resultType="com.atguigu.lease.model.entity.LabelInfo">
              select id,
                     type,
                     name
              from label_info
              where is_deleted = 0
                and id in (select label_id
                           from apartment_label
                           where is_deleted = 0
                             and apartment_id = #{id})
          </select>
        
      • 编写查询公寓最小租金逻辑

        • RoomInfoMapper中增加如下内容

          BigDecimal selectMinRentByApartmentId(Long id);
          
        • RoomInfoMapper.xml中增加如下内容

          <select id="selectMinRentByApartmentId" resultType="java.math.BigDecimal">
              select min(rent)
              from room_info
              where is_deleted = 0
              and is_release = 1
              and apartment_id = #{id}
          </select>
          
2.2.3.根据公寓ID分页查询房间列表
  • 查看请求和响应的数据结构

    • 请求的数据结构

      • currentsize为分页相关参数,分别表示当前所处页面每个页面的记录数
      • id为公寓ID。
    • 响应的数据结构

      • 查看web-admin模块下的com.atguigu.lease.web.app.vo.room.RoomItemVo,如下

        @Schema(description = "APP房间列表实体")
        @Data
        public class RoomItemVo {
        
            @Schema(description = "房间id")
            private Long id;
        
            @Schema(description = "房间号")
            private String roomNumber;
        
            @Schema(description = "租金(元/月)")
            private BigDecimal rent;
        
            @Schema(description = "房间图片列表")
            private List<GraphVo> graphVoList;
        
            @Schema(description = "房间标签列表")
            private List<LabelInfo> labelInfoList;
        
            @Schema(description = "房间所属公寓信息")
            private ApartmentInfo apartmentInfo;
        
        }
        
  • 编写Controller层逻辑

    RoomController中增加如下内容

    @Operation(summary = "根据公寓id分页查询房间列表")
    @GetMapping("pageItemByApartmentId")
    public Result<IPage<RoomItemVo>> pageItemByApartmentId(@RequestParam long current, @RequestParam long size, @RequestParam Long id) {
        IPage<RoomItemVo> page = new Page<>(current, size);
        IPage<RoomItemVo> result = service.pageItemByApartmentId(page, id);
        return Result.ok(result);
    }
    
  • 编写Service层逻辑

    RoomInfoService中增加如下内容

    IPage<RoomItemVo> pageItemByApartmentId(IPage<RoomItemVo> page, Long id);
    

    RoomInfoServiceImpl中增加如下内容

    @Override
    public IPage<RoomItemVo> pageItemByApartmentId(IPage<RoomItemVo> page, Long id) {
        return roomInfoMapper.pageItemByApartmentId(page, id);
    }
    
  • 编写Mapper层逻辑

    RoomInfoMapper中增加如下内容

    IPage<RoomItemVo> pageItemByApartmentId(IPage<RoomItemVo> page, Long id);
    

    RoomInfoMapper.xml中增加如下内容

    <select id="pageItemByApartmentId" resultMap="RoomItemVoMap">
        select ri.id,
               ri.room_number,
               ri.rent,
               ai.id apartment_id,
               ai.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,
               ai.is_release
        from room_info ri
                 left join apartment_info ai on ri.apartment_id = ai.id and ai.is_deleted = 0
        where ri.is_deleted = 0
          and ri.is_release = 1
          and ai.id = #{id}
          and ri.id not in (select room_id
                            from lease_agreement
                            where is_deleted = 0
                              and status in (2, 5))
    
    </select>
    
2.4、 公寓信息

公寓信息只需一个接口,即根据ID查询公寓详细信息,具体实现如下

首先在ApartmentController中注入ApartmentInfoService,如下

@RestController
@Tag(name = "公寓信息")
@RequestMapping("/app/apartment")
public class ApartmentController {
    @Autowired
    private ApartmentInfoService service;
}
  • 查看响应的数据结构

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

    @Data
    @Schema(description = "APP端公寓信息详情")
    public class ApartmentDetailVo extends ApartmentInfo {
    
        @Schema(description = "图片列表")
        private List<GraphVo> graphVoList;
    
        @Schema(description = "标签列表")
        private List<LabelInfo> labelInfoList;
    
        @Schema(description = "配套列表")
        private List<FacilityInfo> facilityInfoList;
    
        @Schema(description = "租金最小值")
        private BigDecimal minRent;
    }
    
  • 编写Controller层逻辑

    ApartmentController中增加如下内容

    @Operation(summary = "根据id获取公寓信息")
    @GetMapping("getDetailById")
    public Result<ApartmentDetailVo> getDetailById(@RequestParam Long id) {
        ApartmentDetailVo apartmentDetailVo = service.getApartmentDetailById(id);
        return Result.ok(apartmentDetailVo);
    }
    
  • 编写Service层逻辑

    • ApartmentInfoService中增加如下内容

      ApartmentDetailVo getDetailById(Long id);
      
    • ApartmentInfoServiceImpl中增加如下内容

      @Override
      public ApartmentDetailVo getDetailById(Long id) {
          //1.查询公寓信息
          ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(id);
          //2.查询图片信息
          List<GraphVo> graphVoList = graphInfoMapper.selectListByItemTypeAndId(ItemType.APARTMENT, id);
          //3.查询标签信息
          List<LabelInfo> labelInfoList = labelInfoMapper.selectListByApartmentId(id);
          //4.查询配套信息
          List<FacilityInfo> facilityInfoList = facilityInfoMapper.selectListByApartmentId(id);
          //5.查询最小租金
          BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(id);
      
          ApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();
      
          BeanUtils.copyProperties(apartmentInfo, apartmentDetailVo);
          apartmentDetailVo.setGraphVoList(graphVoList);
          apartmentDetailVo.setLabelInfoList(labelInfoList);
          apartmentDetailVo.setFacilityInfoList(facilityInfoList);
          apartmentDetailVo.setMinRent(minRent);
          return apartmentDetailVo;
      }
      
  • 编写Mapper层逻辑

    • 编写查询公寓配套逻辑

      • FacilityInfoMapper中增加如下内容

        List<FacilityInfo> selectListByApartmentId(Long id);
        
      • FacilityInfoMapper.xml中增加如下内容

        <select id="selectListByApartmentId" resultType="com.atguigu.lease.model.entity.FacilityInfo">
            select id,
                   type,
                   name,
                   icon
            from facility_info
            where is_deleted = 0
              and id in (select facility_id
                         from apartment_facility
                         where is_deleted = 0
                           and apartment_id = #{id})
        </select>
        

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringCloud中Eureka和Nacos的区别和各自的优点

Eureka注册中心 Eureka作为一个注册中心&#xff0c;服务提供者把服务注册到注册中心&#xff0c;服务消费者去注册中心拉取信息&#xff0c; 然后通过负载均衡得到对应的服务器去访问。 服务提供者每隔30s向注册中心发送请求&#xff0c;报告自己的状态&#xff0c;当超过一定…

【网络安全的神秘世界】关于Linux中一些好玩的字符游戏

&#x1f31d;博客主页&#xff1a;泥菩萨 &#x1f496;专栏&#xff1a;Linux探索之旅 | 网络安全的神秘世界 | 专接本 | 每天学会一个渗透测试工具 佛祖保佑 把 motd 通过xtp拖到Linux中 liyangUbuntu2204:~$ cp motd /etc/motd #一定要放在etc下 liyangUbuntu2204:~$ exi…

windows设置开机启动项

将文件放到下面路径即可实现每次开机启动 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

数据分析-相关性

0、提高数据样本质量 首先是确保数据采集的准确性与可靠性&#xff0c;也就是如何降低数据误差 系统误差是由测量工具不精确和测量方法选择不当造成的。这类误差我们可以通过校准工具或者选择更合适的测量方法来消除&#xff1b;随机误差是由环境因素等外部不可控原因导致的&…

RStudio Desktop 安装

RStudio 下载 macOS 安装 RStudio Desktop 打开报错 R not found Could not locate an R installation on the system.安装R https://cloud.r-project.org/bin/macosx/安装 R-4.4.1-arm64.pkg 成功打开 参考 RStudio 桌面版安装R

React的Redux的状态管理

步骤 1.创建新项目 npx create-react-app react-redux 2.安装配套工具 npm i reduxjs/toolkit react-redux 3.启动项目 npm run start 4.在src目录下创建store文件夹 5.在store文件夹下创建modules文件夹 6.在store文件夹里创建index.js文件 7.在counterStore.js文件…

Redis的实战常用一、验证码登录(解决session共享问题)(思路、意识)

一、基于session实现登录功能 第一步&#xff1a;发送验证码&#xff1a; 用户在提交手机号后&#xff0c;会校验手机号是否合法&#xff1a; 如果不合法&#xff0c;则要求用户重新输入手机号如果手机号合法&#xff0c;后台此时生成对应的验证码&#xff0c;同时将验证码进行…

Vue81-独享路由守卫

一、 独享路由守卫的定义 当只有某个特定的路由需要做校验的时候&#xff0c;可以在改路由组件规则的地方单独配置独属于改组件的路由守卫。 二、示例 1、需求 系统只在进入新闻路由页面的时候做校验。 2、代码实现 注意&#xff1a; 独享路由守卫&#xff0c;只有前置路由守…

C语言入门系列:数据类型转换

文章目录 一&#xff0c;自动类型转换1&#xff0c;赋值运算1.1&#xff0c;浮点数赋值给整型变量-不安全1.2&#xff0c;整数赋值给浮点数变量-安全1.3&#xff0c;窄类型赋值给宽类型-安全1.4&#xff0c;宽类型赋值给窄类型-不安全 2&#xff0c;混合类型的运算2.1&#xff…

Kotlin 中的内联函数

1 inline 内联函数&#xff1a;消除 Lambda 带来的运行时开销。 举例来说&#xff1a; fun main() {val num1 100val num2 80val result num1AndNum2(num1, num2) { n1, n2 ->n1 n2} }fun num1AndNum2(num1: Int, num2: Int, operation: (Int, Int) -> Int): Int …

【自撰写】【国际象棋入门】第8课 国际象棋残局基础

第8课 国际象棋残局基础 一、残局的特点 残局是棋局的最后&#xff08;收尾&#xff09;阶段&#xff0c;虽然此时棋盘上的子力已经所剩无几&#xff0c;但依照不同的局面分类&#xff0c;残局中存在着许多有意思的变化&#xff0c;初始局面中的细小变化也可能引发到截然不同…

Redis源码学习:ziplist的数据结构和连锁更新问题

ziplist ziplist 是 Redis 中一种紧凑型的列表结构&#xff0c;专门用来存储元素数量少且每个元素较小的数据。它是一个双端链表&#xff0c; 可以在任意一端进行压入/弹出操作&#xff0c;并且该操作的时间复杂度为O(1)。 ziplist数据结构 <zlbytes><zltail>&l…

期货交易豆粕品种详细分析

文章目录 1、豆粕期货标准&#xff08;2024年6月22号数据&#xff09;2、豆粕是什么3、豆粕1、5、9合约区别4、影响豆粕的价格因素1、大豆的供应情况。2、豆粕的季节性3、油粕比&#xff08;豆油和豆粕的价格关系 &#xff09; 5、美国大豆的生产/库存炒作6、豆粕双方&#xff…

Linux中tar压缩与解压缩

TAR是Unix/Linux中常用的归档工具&#xff0c;它可以对文件或目录进行打包但不压缩&#xff0c;或者配合其他工具进行压缩。 压缩文件或目录 以下是一些基本的tar压缩命令&#xff1a; 1.压缩单个文件&#xff1a; tar -cvf archive.tar file1 2.压缩多个文件&#xff1a; t…

微软Edge浏览器全解析

微软Edge浏览器全解析(一) 解决浏览器的主页被篡改后无法通过浏览器的自带设置来恢复的问题 相信各位都有发现新买的联想电脑浏览器的主页设置不太满意,但从浏览器自带的设置上又无法解决此问题,网上找了许多方法都无济于事,特别对有着强迫症的小伙伴们更是一种煎熬。 通…

cocos 如何使用九宫格图片,以及在微信小程序上失效。

1.在图片下方&#xff0c;点击edit。 2.拖动线条&#xff0c;使四角不被拉伸。 3.使用。 其他 在微信小程序上失效&#xff0c;需要将packable合图功能取消掉。

26.2 Django简介

1. Python三大主流框架 根据当前的信息和流行度, Python的三大框架可以归纳为Django, Flask和FastAPI, 以下是对它们的清晰分点表示和归纳:* 1. Django: 一个高级的Python Web框架, 以快速开发和实用简洁的设计出名.它遵循MVC设计模式(但更倾向于MTV模式), 并提供了许多内置的…

实施高效冷却技术:确保滚珠丝杆稳定运行!

滚珠丝杆在运行过程中&#xff0c;由于摩擦、惯性力等因素&#xff0c;会产生一定的热量&#xff0c;当热量无法及时散发时&#xff0c;滚珠丝杆的温度就会升高&#xff0c;会直接影响滚珠丝杆的精度和稳定性&#xff0c;从而影响最终的产品质量。为了让滚珠丝杆保持应有的精度…

【博客719】时序数据库基石:LSM Tree的增删查改

时序数据库基石&#xff1a;LSM Tree的增删查改 LSM结构 LSM树将任何的对数据操作都转化为对内存中的Memtable的一次插入。Memtable可以使用任意内存数据结构&#xff0c;如HashTable&#xff0c;BTree&#xff0c;SkipList等。对于有事务控制需要的存储系统&#xff0c;需要在…

数据库设计文档编写

PS&#xff1a;建议使用第三种方法 方法1&#xff1a;使用 Navicat 生成数据库设计文档 效果 先看简单的效果图&#xff0c;如果效果合适&#xff0c;大家在进行测试使用&#xff0c;不合适直接撤退&#xff0c;也不浪费时间。 随后在docx文档中生成目标字段的表格&#xf…