|
@@ -3,23 +3,24 @@ package com.ruoyi.web.service.impl;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
|
import com.ruoyi.web.domain.dto.house.HouseInfoQueryRequest;
|
|
|
import com.ruoyi.web.domain.entity.HouseInfo;
|
|
|
-import com.ruoyi.web.domain.entity.HouseholdInfo;
|
|
|
+import com.ruoyi.web.domain.entity.PersonHouseRelation;
|
|
|
import com.ruoyi.web.domain.entity.PersonInfo;
|
|
|
import com.ruoyi.web.domain.vo.HouseInfoVO;
|
|
|
import com.ruoyi.web.domain.vo.PersonInfoVO;
|
|
|
import com.ruoyi.web.mapper.HouseInfoMapper;
|
|
|
import com.ruoyi.web.service.HouseInfoService;
|
|
|
+import com.ruoyi.web.service.PersonHouseRelationService;
|
|
|
import com.ruoyi.web.service.PersonInfoService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -33,38 +34,11 @@ public class HouseInfoServiceImpl extends ServiceImpl<HouseInfoMapper, HouseInfo
|
|
|
@Autowired
|
|
|
private PersonInfoService personInfoService;
|
|
|
|
|
|
- /**
|
|
|
- * 查询人员信息列表
|
|
|
- *
|
|
|
- * @param houseInfoQueryRequest
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<HouseInfoVO> getHouseInfo(HouseInfoQueryRequest houseInfoQueryRequest) {
|
|
|
- HouseInfo houseInfoQuery = new HouseInfo();
|
|
|
- if (houseInfoQueryRequest != null) {
|
|
|
- BeanUtils.copyProperties(houseInfoQueryRequest, houseInfoQuery);
|
|
|
- }
|
|
|
- QueryWrapper<HouseInfo> queryWrapper = new QueryWrapper<>(houseInfoQuery);
|
|
|
- List<HouseInfo> houseInfoList = this.list(queryWrapper);
|
|
|
- // houseOwnerId
|
|
|
- return houseInfoList.stream().map(houseInfo -> {
|
|
|
- // 通过房主id 查询房主信息 填充返回
|
|
|
- HouseInfoVO houseInfoVO = new HouseInfoVO();
|
|
|
- BeanUtils.copyProperties(houseInfo, houseInfoVO);
|
|
|
-
|
|
|
- Integer houseOwnerId = houseInfo.getHouseOwnerId();
|
|
|
- PersonInfo houseOwnerInfo = personInfoService.getById(houseOwnerId);
|
|
|
- PersonInfoVO houseOwnerInfoVO = new PersonInfoVO();
|
|
|
- BeanUtils.copyProperties(houseOwnerInfo, houseOwnerInfoVO);
|
|
|
-
|
|
|
- houseInfoVO.setHouseOwnerInfo(houseOwnerInfoVO);
|
|
|
- return houseInfoVO;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private PersonHouseRelationService personHouseRelationService;
|
|
|
|
|
|
/**
|
|
|
- * 分页获取人员列表
|
|
|
+ * 分页获取房屋列表
|
|
|
*
|
|
|
* @param houseInfoQueryRequest
|
|
|
* @return
|
|
@@ -73,6 +47,7 @@ public class HouseInfoServiceImpl extends ServiceImpl<HouseInfoMapper, HouseInfo
|
|
|
public Page<HouseInfoVO> getListHouseInfoByPage(HouseInfoQueryRequest houseInfoQueryRequest) {
|
|
|
long current = houseInfoQueryRequest.getCurrent();
|
|
|
long size = houseInfoQueryRequest.getPageSize();
|
|
|
+ // 1. 分页查询房屋基础信息
|
|
|
Page<HouseInfo> houseInfoPage = this.page(new Page<>(current, size),
|
|
|
getQueryWrapper(houseInfoQueryRequest));
|
|
|
|
|
@@ -82,16 +57,25 @@ public class HouseInfoServiceImpl extends ServiceImpl<HouseInfoMapper, HouseInfo
|
|
|
|
|
|
// 3. 处理每条记录
|
|
|
List<HouseInfoVO> viewList = houseInfoPage.getRecords().stream().map(houseInfo -> {
|
|
|
- // 通过房主id 查询房主信息 填充返回
|
|
|
HouseInfoVO houseInfoVO = new HouseInfoVO();
|
|
|
BeanUtils.copyProperties(houseInfo, houseInfoVO);
|
|
|
|
|
|
+ // 通过关联表 获取 成员数量
|
|
|
+ Integer houseInfoId = houseInfo.getId();
|
|
|
+ Integer memberCount = personHouseRelationService.lambdaQuery()
|
|
|
+ .eq(PersonHouseRelation::getHouseId, houseInfoId)
|
|
|
+ .count()
|
|
|
+ .intValue();
|
|
|
+ houseInfoVO.setMemberCount(memberCount);
|
|
|
+
|
|
|
+ // 通过房主id 查询房主信息 填充返回
|
|
|
Integer houseOwnerId = houseInfo.getHouseOwnerId();
|
|
|
- PersonInfo houseOwnerInfo = personInfoService.getById(houseOwnerId);
|
|
|
PersonInfoVO houseOwnerInfoVO = new PersonInfoVO();
|
|
|
- BeanUtils.copyProperties(houseOwnerInfo, houseOwnerInfoVO);
|
|
|
-
|
|
|
- houseInfoVO.setHouseOwnerInfo(houseOwnerInfoVO);
|
|
|
+ if (houseOwnerId != null) {
|
|
|
+ PersonInfo houseOwnerInfo = personInfoService.getById(houseOwnerId);
|
|
|
+ BeanUtils.copyProperties(houseOwnerInfo, houseOwnerInfoVO);
|
|
|
+ houseInfoVO.setHouseOwnerInfo(houseOwnerInfoVO);
|
|
|
+ }
|
|
|
return houseInfoVO;
|
|
|
}).collect(Collectors.toList());
|
|
|
resultPage.setRecords(viewList);
|
|
@@ -99,6 +83,8 @@ public class HouseInfoServiceImpl extends ServiceImpl<HouseInfoMapper, HouseInfo
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取查询条件
|
|
|
*
|
|
@@ -114,39 +100,47 @@ public class HouseInfoServiceImpl extends ServiceImpl<HouseInfoMapper, HouseInfo
|
|
|
|
|
|
// 从对象中取值
|
|
|
Integer id = houseInfoQueryRequest.getId();
|
|
|
- String houseCode = houseInfoQueryRequest.getHouseCode();
|
|
|
- Integer villageId = houseInfoQueryRequest.getVillageId();
|
|
|
- String villageName = houseInfoQueryRequest.getVillageName();
|
|
|
String doorplateNumber = houseInfoQueryRequest.getDoorplateNumber();
|
|
|
- String houseAddress = houseInfoQueryRequest.getHouseAddress();
|
|
|
Integer houseOwnerId = houseInfoQueryRequest.getHouseOwnerId();
|
|
|
String houseOwnerName = houseInfoQueryRequest.getHouseOwnerName();
|
|
|
- String idCard = houseInfoQueryRequest.getIdCard();
|
|
|
- String phone = houseInfoQueryRequest.getPhone();
|
|
|
- Integer houseType = houseInfoQueryRequest.getHouseType();
|
|
|
Integer houseCategory = houseInfoQueryRequest.getHouseCategory();
|
|
|
- BigDecimal buildingArea = houseInfoQueryRequest.getBuildingArea();
|
|
|
- Integer gridId = houseInfoQueryRequest.getGridId();
|
|
|
+ Integer grid = houseInfoQueryRequest.getGrid();
|
|
|
List<String> houseTags = houseInfoQueryRequest.getHouseTags();
|
|
|
String sortField = houseInfoQueryRequest.getSortField();
|
|
|
String sortOrder = houseInfoQueryRequest.getSortOrder();
|
|
|
|
|
|
- //门牌号、房主、房屋类别、所属网格、家庭标签
|
|
|
+ //门牌号、房主ID、房屋类别、所属网格、家庭标签
|
|
|
queryWrapper.eq(ObjectUtil.isNotEmpty(id), "id", id);
|
|
|
- queryWrapper.eq(StrUtil.isNotBlank(houseCode), "house_code", houseCode);
|
|
|
- queryWrapper.eq(StrUtil.isNotBlank(houseOwnerName), "houseOwner_name", houseOwnerName);
|
|
|
- queryWrapper.eq(StrUtil.isNotBlank(idCard), "id_card", idCard);
|
|
|
- queryWrapper.eq(StrUtil.isNotBlank(phone), "phone", phone);
|
|
|
- queryWrapper.eq(ObjectUtil.isNotEmpty(gridId), "grid_id", gridId);
|
|
|
- queryWrapper.eq(ObjectUtil.isNotEmpty(houseType), "house_type", houseType);
|
|
|
+ queryWrapper.eq(StrUtil.isNotBlank(doorplateNumber), "doorplate_number", doorplateNumber);
|
|
|
+ queryWrapper.eq(ObjectUtil.isNotEmpty(houseOwnerId), "house_owner_id", houseOwnerId);
|
|
|
+ queryWrapper.eq(ObjectUtil.isNotEmpty(grid), "grid", grid);
|
|
|
queryWrapper.eq(ObjectUtil.isNotEmpty(houseCategory), "house_category", houseCategory);
|
|
|
|
|
|
+ // 房主姓名查询条件
|
|
|
+ if (StrUtil.isNotBlank(houseOwnerName)){
|
|
|
+ // 先查询符合姓名条件的人员ID列表
|
|
|
+ List<Integer> ownerIds = personInfoService.list(
|
|
|
+ new LambdaQueryWrapper<PersonInfo>()
|
|
|
+ .like(PersonInfo::getRealname, houseOwnerName)
|
|
|
+ .select(PersonInfo::getId)
|
|
|
+ ).stream().map(PersonInfo::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!ownerIds.isEmpty()) {
|
|
|
+ queryWrapper.in("house_owner_id", ownerIds);
|
|
|
+ } else {
|
|
|
+ // 如果没有匹配的姓名,确保查询不到结果
|
|
|
+ queryWrapper.apply("1 = 0"); // 无匹配结果
|
|
|
+ //queryWrapper.isNull("house_owner_id");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 家庭标签 JSON 数组查询
|
|
|
if (CollUtil.isNotEmpty(houseTags)) {
|
|
|
for (String tag : houseTags) {
|
|
|
queryWrapper.like("house_tags", "\"" + tag + "\"");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// 排序
|
|
|
queryWrapper.orderBy(StrUtil.isNotEmpty(sortField), sortOrder.equals("ascend"), sortField);
|
|
|
return queryWrapper;
|