1
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.gxwebsoft.house.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.house.entity.HouseInfo;
|
||||
import com.gxwebsoft.house.service.HouseInfoService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 房源测试数据控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2025-08-07
|
||||
*/
|
||||
@Tag(name = "房源测试数据管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/house/test-data")
|
||||
public class HouseTestDataController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private HouseInfoService houseInfoService;
|
||||
|
||||
@Operation(summary = "创建测试数据")
|
||||
@PostMapping("/create")
|
||||
public ApiResult<?> createTestData() {
|
||||
try {
|
||||
// 创建5个测试房源,价格不同
|
||||
createTestHouse("碧园大厦B", "223", new BigDecimal("8920"), 10058);
|
||||
createTestHouse("碧园大厦B", "155", new BigDecimal("6200"), 10058);
|
||||
createTestHouse("碧园大厦B", "92", new BigDecimal("3680"), 10058);
|
||||
createTestHouse("龙光国际A", "99", new BigDecimal("4455"), 10058);
|
||||
createTestHouse("万达广场C", "120", new BigDecimal("5500"), 10058);
|
||||
|
||||
return success("测试数据创建成功!");
|
||||
} catch (Exception e) {
|
||||
return fail("创建测试数据失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void createTestHouse(String title, String extent, BigDecimal monthlyRent, Integer tenantId) {
|
||||
HouseInfo house = new HouseInfo();
|
||||
house.setHouseTitle(title);
|
||||
house.setExtent(extent);
|
||||
house.setMonthlyRent(monthlyRent);
|
||||
house.setRent(monthlyRent);
|
||||
house.setTenantId(tenantId);
|
||||
house.setStatus(0); // 通过状态
|
||||
house.setDeleted(0);
|
||||
house.setRecommend(0);
|
||||
house.setUserId(1);
|
||||
house.setCreateTime(new Date());
|
||||
house.setUpdateTime(new Date());
|
||||
house.setCityByHouse("南宁");
|
||||
house.setHouseType("办公室");
|
||||
house.setLeaseMethod("整租");
|
||||
house.setFloor("10层");
|
||||
house.setRealName("测试用户");
|
||||
house.setPhone("13800138000");
|
||||
house.setProvince("广西");
|
||||
house.setCity("南宁");
|
||||
house.setRegion("青秀区");
|
||||
house.setAddress("测试地址");
|
||||
|
||||
houseInfoService.save(house);
|
||||
}
|
||||
}
|
||||
@@ -128,6 +128,49 @@
|
||||
OR a.room_number LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
)
|
||||
</if>
|
||||
<!-- 价格区间筛选 -->
|
||||
<if test="param.priceScene != null">
|
||||
<choose>
|
||||
<when test="param.priceScene == '1000以下'">
|
||||
AND a.monthly_rent < 1000
|
||||
</when>
|
||||
<when test="param.priceScene == '1000-3000'">
|
||||
AND a.monthly_rent >= 1000 AND a.monthly_rent <= 3000
|
||||
</when>
|
||||
<when test="param.priceScene == '3000-5000'">
|
||||
AND a.monthly_rent >= 3000 AND a.monthly_rent <= 5000
|
||||
</when>
|
||||
<when test="param.priceScene == '5000-10000'">
|
||||
AND a.monthly_rent >= 5000 AND a.monthly_rent <= 10000
|
||||
</when>
|
||||
<when test="param.priceScene == '10000-20000'">
|
||||
AND a.monthly_rent >= 10000 AND a.monthly_rent <= 20000
|
||||
</when>
|
||||
<when test="param.priceScene == '20000以上'">
|
||||
AND a.monthly_rent > 20000
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
<!-- 面积区间筛选 -->
|
||||
<if test="param.extentScene != null">
|
||||
<choose>
|
||||
<when test="param.extentScene == '50以下'">
|
||||
AND a.extent < 50
|
||||
</when>
|
||||
<when test="param.extentScene == '50-100'">
|
||||
AND a.extent >= 50 AND a.extent <= 100
|
||||
</when>
|
||||
<when test="param.extentScene == '100-150'">
|
||||
AND a.extent >= 100 AND a.extent <= 150
|
||||
</when>
|
||||
<when test="param.extentScene == '150-200'">
|
||||
AND a.extent >= 150 AND a.extent <= 200
|
||||
</when>
|
||||
<when test="param.extentScene == '200以上'">
|
||||
AND a.extent > 200
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
</where>
|
||||
<trim prefix="ORDER BY" suffixOverrides=",">
|
||||
<if test="param.sortScene == '综合排序'">
|
||||
@@ -137,24 +180,19 @@
|
||||
a.create_time desc,
|
||||
</if>
|
||||
<if test="param.sortScene == '价格(低-高)'">
|
||||
a.monthly_rent asc,
|
||||
CAST(IFNULL(a.monthly_rent, 0) AS DECIMAL(10,2)) asc,
|
||||
</if>
|
||||
<if test="param.sortScene == '价格(高-低)'">
|
||||
a.monthly_rent desc,
|
||||
CAST(IFNULL(a.monthly_rent, 0) AS DECIMAL(10,2)) desc,
|
||||
</if>
|
||||
<if test="param.sortScene == '面积(小-大)'">
|
||||
a.extent asc,
|
||||
CAST(IFNULL(a.extent, 0) AS DECIMAL(10,2)) asc,
|
||||
</if>
|
||||
<if test="param.sortScene == '面积(大-小)'">
|
||||
a.extent desc,
|
||||
</if>
|
||||
<if test="param.priceScene != null">
|
||||
ABS(a.monthly_rent - #{param.priceScene}),
|
||||
</if>
|
||||
|
||||
<if test="param.extentScene != null">
|
||||
ABS(a.extent - #{param.extentScene}),
|
||||
CAST(IFNULL(a.extent, 0) AS DECIMAL(10,2)) desc,
|
||||
</if>
|
||||
<!-- 默认排序:推荐优先,然后按创建时间倒序 -->
|
||||
a.recommend desc, a.create_time desc
|
||||
</trim>
|
||||
|
||||
</sql>
|
||||
|
||||
@@ -63,7 +63,10 @@ public class HouseInfoServiceImpl extends ServiceImpl<HouseInfoMapper, HouseInfo
|
||||
@Override
|
||||
public PageResult<HouseInfo> pageRel(HouseInfoParam param) {
|
||||
PageParam<HouseInfo, HouseInfoParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// 只有在没有指定排序场景时才使用默认排序
|
||||
if (param.getSortScene() == null || param.getSortScene().isEmpty()) {
|
||||
page.setDefaultOrder("create_time desc");
|
||||
}
|
||||
List<HouseInfo> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
@@ -73,7 +76,10 @@ public class HouseInfoServiceImpl extends ServiceImpl<HouseInfoMapper, HouseInfo
|
||||
List<HouseInfo> list = baseMapper.selectListRel(param);
|
||||
// 排序
|
||||
PageParam<HouseInfo, HouseInfoParam> page = new PageParam<>();
|
||||
page.setDefaultOrder("create_time desc");
|
||||
// 只有在没有指定排序场景时才使用默认排序
|
||||
if (param.getSortScene() == null || param.getSortScene().isEmpty()) {
|
||||
page.setDefaultOrder("create_time desc");
|
||||
}
|
||||
return page.sortRecords(list);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user