Commit c8921587 authored by lixuan's avatar lixuan

feat: 房源

parent a20733e8
Pipeline #145561 canceled with stages
...@@ -7,6 +7,8 @@ import org.apache.ibatis.annotations.Param; ...@@ -7,6 +7,8 @@ import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
public interface GridRegionMapper { public interface GridRegionMapper {
long countByExample(GridRegionExample example); long countByExample(GridRegionExample example);
...@@ -98,4 +100,6 @@ public interface GridRegionMapper { ...@@ -98,4 +100,6 @@ public interface GridRegionMapper {
GridRegion selectByWgName(@Param("wgName") String wgName); GridRegion selectByWgName(@Param("wgName") String wgName);
List<GridRegion> getAllLevelThree(@Param("wgCodeLikes")List<String> wgCodeLikes, @Param("wgType")String wgType, @Param("name") String name); List<GridRegion> getAllLevelThree(@Param("wgCodeLikes")List<String> wgCodeLikes, @Param("wgType")String wgType, @Param("name") String name);
List<GridRegion> selectByCodes(@Param("codes") Set<String> codes);
} }
...@@ -28,11 +28,16 @@ import org.springframework.util.StringUtils; ...@@ -28,11 +28,16 @@ import org.springframework.util.StringUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
public class HouseResourceServiceImpl implements HouseResourceService { public class HouseResourceServiceImpl implements HouseResourceService {
private static final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
private final HouseResourceMapper houseResourceMapper; private final HouseResourceMapper houseResourceMapper;
private final BusinessEntityInfoMapper businessEntityInfoMapper; private final BusinessEntityInfoMapper businessEntityInfoMapper;
...@@ -411,7 +416,7 @@ public class HouseResourceServiceImpl implements HouseResourceService { ...@@ -411,7 +416,7 @@ public class HouseResourceServiceImpl implements HouseResourceService {
businessEntityStatisticsDetail.setXsCount(list.stream().map(HouseResourcePage::getIncome).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); businessEntityStatisticsDetail.setXsCount(list.stream().map(HouseResourcePage::getIncome).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
businessEntityStatisticsDetail.setSsCount(list.stream().map(HouseResourcePage::getTaxCount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add)); businessEntityStatisticsDetail.setSsCount(list.stream().map(HouseResourcePage::getTaxCount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
businessEntityStatisticsDetail.setGsCount(list.stream().filter(x -> x.getGs().equals(Boolean.TRUE)).count()); businessEntityStatisticsDetail.setGsCount(list.stream().filter(x -> Objects.nonNull(x.getGs())).filter(x -> x.getGs().equals(Boolean.TRUE)).count());
List<String> houseResourceIds = list.stream().map(HouseResourcePage::getId).collect(Collectors.toList()); List<String> houseResourceIds = list.stream().map(HouseResourcePage::getId).collect(Collectors.toList());
List<HouseResourceBusinessEntityInfoMapping> houseResourceMappings = houseResourceBusinessEntityInfoMappingMapper.selectByHouseResourceIds(houseResourceIds); List<HouseResourceBusinessEntityInfoMapping> houseResourceMappings = houseResourceBusinessEntityInfoMappingMapper.selectByHouseResourceIds(houseResourceIds);
...@@ -547,45 +552,72 @@ public class HouseResourceServiceImpl implements HouseResourceService { ...@@ -547,45 +552,72 @@ public class HouseResourceServiceImpl implements HouseResourceService {
} }
private List<HouseResourcePage> handleHouseList(List<HouseResourcePage> list, boolean houseNumberSortFlag) { private List<HouseResourcePage> handleHouseList(List<HouseResourcePage> list, boolean houseNumberSortFlag) {
list.parallelStream().forEach(x -> { if (CollectionUtils.isEmpty(list)) {
GridRegionExample twoExample = new GridRegionExample(); return Collections.emptyList();
twoExample.createCriteria().andWgTypeEqualTo(String.valueOf(x.getType())).andWgCodeEqualTo(x.getTwo()); }
List<GridRegion> two = gridRegionMapper.selectByExample(twoExample);
if (!CollectionUtils.isEmpty(two)) { CompletableFuture<Set<String>> twoCodesFuture = CompletableFuture.supplyAsync(() -> list.stream().map(HouseResourcePage::getTwo).collect(Collectors.toSet()), executor);
x.setWgName2(two.get(0).getWgName()); CompletableFuture<Set<String>> threeCodesFuture = CompletableFuture.supplyAsync(() -> list.stream().map(HouseResourcePage::getThree).collect(Collectors.toSet()), executor);
} CompletableFuture<Set<String>> fourCodesFuture = CompletableFuture.supplyAsync(() -> list.stream().map(HouseResourcePage::getFour).collect(Collectors.toSet()), executor);
GridRegionExample threeExample = new GridRegionExample(); CompletableFuture<List<String>> idsFuture = CompletableFuture.supplyAsync(() -> list.stream().map(HouseResourcePage::getId).collect(Collectors.toList()), executor);
threeExample.createCriteria().andWgTypeEqualTo(String.valueOf(x.getType())).andWgCodeEqualTo(x.getThree());
List<GridRegion> three = gridRegionMapper.selectByExample(threeExample); Set<String> twoCodes = twoCodesFuture.join();
if (!CollectionUtils.isEmpty(three)) { Set<String> threeCodes = threeCodesFuture.join();
x.setWgName3(three.get(0).getWgName()); Set<String> fourCodes = fourCodesFuture.join();
} List<String> ids = idsFuture.join();
if (!StringUtils.hasText(x.getWgName4())) {
GridRegionExample fourExample = new GridRegionExample();
fourExample.createCriteria().andWgTypeEqualTo(String.valueOf(x.getType())).andWgCodeEqualTo(x.getFour()); CompletableFuture<Map<String, GridRegion>> twoMapFuture = CompletableFuture.supplyAsync(() -> gridRegionMapper.selectByCodes(twoCodes).stream().collect(Collectors.toMap(GridRegion::getWgCode, gridRegion -> gridRegion, (e, r) -> e)), executor);
List<GridRegion> four = gridRegionMapper.selectByExample(fourExample); CompletableFuture<Map<String, GridRegion>> threeMapFuture = CompletableFuture.supplyAsync(() -> gridRegionMapper.selectByCodes(threeCodes).stream().collect(Collectors.toMap(GridRegion::getWgCode, gridRegion -> gridRegion, (e, r) -> e)), executor);
if (!CollectionUtils.isEmpty(four)) { CompletableFuture<Map<String, GridRegion>> fourMapFuture = CompletableFuture.supplyAsync(() -> gridRegionMapper.selectByCodes(fourCodes).stream().collect(Collectors.toMap(GridRegion::getWgCode, gridRegion -> gridRegion, (e, r) -> e)), executor);
x.setWgName4(four.get(0).getWgName()); CompletableFuture<Map<String, List<HouseResourceBusinessEntityInfoMapping>>> mappingMapFuture = CompletableFuture.supplyAsync(() -> houseResourceBusinessEntityInfoMappingMapper.selectByHouseResourceIds(ids).stream().collect(Collectors.groupingBy(HouseResourceBusinessEntityInfoMapping::getHouseResourceId)), executor);
}
Map<String, GridRegion> twoMap = twoMapFuture.join();
Map<String, GridRegion> threeMap = threeMapFuture.join();
Map<String, GridRegion> fourMap = fourMapFuture.join();
Map<String, List<HouseResourceBusinessEntityInfoMapping>> mappingMap = mappingMapFuture.join();
List<String> entityInfoIds = mappingMap.values().stream()
.flatMap(List::stream)
.map(HouseResourceBusinessEntityInfoMapping::getBusinessEntityInfoId)
.collect(Collectors.toList());
Map<String, List<BusinessEntityInfo>> entityInfoMap = businessEntityInfoMapper.selectByIdList(entityInfoIds)
.stream().collect(Collectors.groupingBy(BusinessEntityInfo::getId));
List<HouseResourcePage> result = list.parallelStream().map(x -> {
HouseResourcePage page = new HouseResourcePage();
BeanUtils.copyProperties(x, page);
GridRegion two = twoMap.get(page.getTwo());
if (two != null) page.setWgName2(two.getWgName());
GridRegion three = threeMap.get(page.getThree());
if (three != null) page.setWgName3(three.getWgName());
if (!StringUtils.hasText(page.getWgName4())) {
GridRegion four = fourMap.get(page.getFour());
if (four != null) page.setWgName4(four.getWgName());
} }
x.setHouseResourceAttributeText(HouseEnums.HouseResourceAttributeEnum.getDescByCode(x.getHouseResourceAttribute())); page.setHouseResourceAttributeText(HouseEnums.HouseResourceAttributeEnum.getDescByCode(page.getHouseResourceAttribute()));
x.setHouseResourceTypeText(HouseEnums.HouseResourceTypeEnum.getDescByCode(x.getHouseResourceType())); page.setHouseResourceTypeText(HouseEnums.HouseResourceTypeEnum.getDescByCode(page.getHouseResourceType()));
x.setOrientationText(HouseEnums.OrientationEnum.getDescByCode(x.getOrientation())); page.setOrientationText(HouseEnums.OrientationEnum.getDescByCode(page.getOrientation()));
x.setDecorationConditionText(HouseEnums.DecorationConditionEnum.getDescByCode(x.getDecorationCondition())); page.setDecorationConditionText(HouseEnums.DecorationConditionEnum.getDescByCode(page.getDecorationCondition()));
x.setRentalUnitText(HouseEnums.RentalUnitEnum.getDescByCode(x.getRentalUnit())); page.setRentalUnitText(HouseEnums.RentalUnitEnum.getDescByCode(page.getRentalUnit()));
x.setHireStatusText(HouseEnums.hireStatusTextEnum.getDescByCode(x.getHireStatus())); page.setHireStatusText(HouseEnums.hireStatusTextEnum.getDescByCode(page.getHireStatus()));
List<HouseResourceBusinessEntityInfoMapping> houseResourceBusinessEntityInfoMappings = houseResourceBusinessEntityInfoMappingMapper.selectByHouseResourceId(x.getId()); List<HouseResourceBusinessEntityInfoMapping> mappings = mappingMap.get(page.getId());
if (!CollectionUtils.isEmpty(houseResourceBusinessEntityInfoMappings)) { if (!CollectionUtils.isEmpty(mappings)) {
List<BusinessEntityInfo> businessEntityInfos = businessEntityInfoMapper.selectByIdList(houseResourceBusinessEntityInfoMappings.stream().map(HouseResourceBusinessEntityInfoMapping::getBusinessEntityInfoId).collect(Collectors.toList())); List<String> entityIds = mappings.stream().map(HouseResourceBusinessEntityInfoMapping::getBusinessEntityInfoId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(businessEntityInfos)) { List<BusinessEntityInfo> infos = entityIds.stream().map(entityInfoMap::get).filter(Objects::nonNull).flatMap(List::stream).collect(Collectors.toList());
x.setBusinessEntityInfoNames(businessEntityInfos.stream().map(BusinessEntityInfo::getName).collect(Collectors.toList())); if (!CollectionUtils.isEmpty(infos)) {
page.setBusinessEntityInfoNames(infos.stream().map(BusinessEntityInfo::getName).collect(Collectors.toList()));
} }
} }
}); return page;
}).collect(Collectors.toList());
if (houseNumberSortFlag) { if (houseNumberSortFlag) {
return list.stream().sorted(Comparator.comparing(HouseResourcePage::getHouseNumber, Comparator.nullsLast(String::compareTo))).collect(Collectors.toList()); return result.stream().sorted(Comparator.comparing(HouseResourcePage::getHouseNumber, Comparator.nullsLast(String::compareTo))).collect(Collectors.toList());
} else { } else {
return list; return result;
} }
} }
......
...@@ -818,5 +818,13 @@ ...@@ -818,5 +818,13 @@
and level = 3 and level = 3
order by position asc order by position asc
</select> </select>
<select id="selectByCodes" resultType="com.ruoyi.system.domain.grid.GridRegion">
SELECT *
FROM grid_region
WHERE is_valid = '1'
AND wg_code IN
<foreach collection="codes" item="code" open="(" separator="," close=")">
#{code}
</foreach>
</select>
</mapper> </mapper>
...@@ -296,7 +296,8 @@ ...@@ -296,7 +296,8 @@
t4.industry_classification, t4.industry_classification,
ROUND(IFNULL(t1.unit_price,0) * 10000 / 365 / t1.house_area, 1) AS dayPrice, ROUND(IFNULL(t1.unit_price,0) * 10000 / 365 / t1.house_area, 1) AS dayPrice,
t4.name, t4.name,
t5.year t5.year,
t4.gs
FROM FROM
house_resource t1 house_resource t1
LEFT JOIN grid_region t2 ON t2.wg_code = t1.four LEFT JOIN grid_region t2 ON t2.wg_code = t1.four
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment