Browse Source

帮我买房

张延森 3 years ago
parent
commit
5648ca2349

+ 1
- 1
pom.xml View File

10
 	</parent>
10
 	</parent>
11
 	<groupId>com.yunzhi</groupId>
11
 	<groupId>com.yunzhi</groupId>
12
 	<artifactId>marketing</artifactId>
12
 	<artifactId>marketing</artifactId>
13
-	<version>v1.0.18</version>
13
+	<version>v1.0.19</version>
14
 	<name>marketing-cloud</name>
14
 	<name>marketing-cloud</name>
15
 	<description>新联康营销云</description>
15
 	<description>新联康营销云</description>
16
 
16
 

+ 17
- 18
src/main/java/com/yunzhi/marketing/xlk/controller/SearchHouseController.java View File

106
      */
106
      */
107
     @ApiOperation(value = "wx-保存帮我找房需求", notes = "wx-保存帮我找房需求")
107
     @ApiOperation(value = "wx-保存帮我找房需求", notes = "wx-保存帮我找房需求")
108
     @RequestMapping(value="/wx/searchHouse",method= RequestMethod.POST)
108
     @RequestMapping(value="/wx/searchHouse",method= RequestMethod.POST)
109
-    public ResponseBean searchHouseAdd(@RequestBody SearchHouseDTO searchHouseDTO, @RequestHeader("authorization") String token, HttpServletRequest request){
109
+    public ResponseBean searchHouseAdd(@RequestBody SearchHouseDTO searchHouseDTO,
110
+                                       @RequestHeader("authorization") String token,
111
+                                       HttpServletRequest request){
110
         ResponseBean responseBean = new ResponseBean();
112
         ResponseBean responseBean = new ResponseBean();
111
         String openid = getOpenId(request);
113
         String openid = getOpenId(request);
112
         Integer orgId = getOrgId(request);
114
         Integer orgId = getOrgId(request);
114
         if (null == persons || persons.size() == 0) {
116
         if (null == persons || persons.size() == 0) {
115
             return ResponseBean.error("当前账户信息异常, 清除缓存重试", ResponseBean.ERROR_UNAVAILABLE);
117
             return ResponseBean.error("当前账户信息异常, 清除缓存重试", ResponseBean.ERROR_UNAVAILABLE);
116
         }
118
         }
119
+
120
+        if (StringUtils.isEmpty(searchHouseDTO.getMinPrice())) {
121
+            return ResponseBean.error("请选择预算价格", ResponseBean.ERROR_UNAVAILABLE);
122
+        }
123
+
117
         TaPerson person = persons.get(0);
124
         TaPerson person = persons.get(0);
118
         try {
125
         try {
119
             SearchHouse searchHouse = new SearchHouse();
126
             SearchHouse searchHouse = new SearchHouse();
123
             searchHouse.setStatus("0");
130
             searchHouse.setStatus("0");
124
             searchHouse.setCreatedTime(LocalDateTime.now());
131
             searchHouse.setCreatedTime(LocalDateTime.now());
125
             if (iSearchHouseService.save(searchHouse)){
132
             if (iSearchHouseService.save(searchHouse)){
126
-                SearchHouseVO searchHouseVO = new SearchHouseVO();
127
-                BeanUtils.copyProperties(searchHouse,searchHouseVO);
128
-                // 获取价格相近的楼盘
129
-                LambdaQueryWrapper<TaBuilding> lambdaQueryWrapper = new LambdaQueryWrapper<>();
130
-                lambdaQueryWrapper.eq(!StringUtils.isEmpty(searchHouseDTO.getIntentArea()),TaBuilding::getBuildingArea,searchHouseDTO.getIntentArea());
131
-                lambdaQueryWrapper.between(TaBuilding::getPrice,searchHouseDTO.getMinPrice(),searchHouseDTO.getMaxPrice());
132
-                lambdaQueryWrapper.ne(TaBuilding::getStatus,-1);
133
-                lambdaQueryWrapper.last(" limit 2");
134
-                List<TaBuilding> list = taBuildingService.list(lambdaQueryWrapper);
135
-                if (list.size() < 1){
136
-                    lambdaQueryWrapper = new LambdaQueryWrapper<>();
137
-                    lambdaQueryWrapper.eq(!StringUtils.isEmpty(searchHouseDTO.getIntentArea()),TaBuilding::getBuildingArea,searchHouseDTO.getIntentArea());
138
-                    lambdaQueryWrapper.ne(TaBuilding::getStatus,-1);
139
-                    lambdaQueryWrapper.last(" limit 2");
140
-                    list = taBuildingService.list(lambdaQueryWrapper);
133
+                if (null != searchHouseDTO.getNeedRecommend() && searchHouseDTO.getNeedRecommend()) {
134
+                    List<TaBuilding> buildingList = iSearchHouseService.getRecommendBuildings(getOrgId(request), searchHouseDTO);
135
+
136
+                    SearchHouseVO searchHouseVO = new SearchHouseVO();
137
+                    BeanUtils.copyProperties(searchHouse,searchHouseVO);
138
+                    searchHouseVO.setTaBuildingList(buildingList);
139
+                    responseBean.addSuccess(searchHouseVO);
140
+                } else {
141
+                    responseBean.addSuccess(null);
141
                 }
142
                 }
142
-                searchHouseVO.setTaBuildingList(list);
143
-                responseBean.addSuccess(searchHouseVO);
144
             }else {
143
             }else {
145
                 responseBean.addError("fail");
144
                 responseBean.addError("fail");
146
             }
145
             }

+ 17
- 0
src/main/java/com/yunzhi/marketing/xlk/dto/SearchHouseDTO.java View File

66
      */
66
      */
67
     private String questionnaire;
67
     private String questionnaire;
68
 
68
 
69
+    /**
70
+     * 是否需要智能推荐
71
+     */
72
+    @TableField(exist = false)
73
+    private Boolean needRecommend;
74
+
75
+    /**
76
+     * 当前人员所在城市
77
+     */
78
+    @TableField(exist = false)
79
+    private Integer cityId;
80
+
81
+    /**
82
+     * 当前人员所选的面积
83
+     */
84
+    @TableField(exist = false)
85
+    private Integer areaResultId;
69
 }
86
 }

+ 11
- 0
src/main/java/com/yunzhi/marketing/xlk/mapper/SearchHouseMapper.java View File

2
 
2
 
3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.yunzhi.marketing.entity.TaBuilding;
5
 import com.yunzhi.marketing.xlk.entity.SearchHouse;
6
 import com.yunzhi.marketing.xlk.entity.SearchHouse;
6
 import com.yunzhi.marketing.xlk.vo.SearchHouseVO;
7
 import com.yunzhi.marketing.xlk.vo.SearchHouseVO;
7
 import org.apache.ibatis.annotations.Mapper;
8
 import org.apache.ibatis.annotations.Mapper;
8
 import org.apache.ibatis.annotations.Param;
9
 import org.apache.ibatis.annotations.Param;
9
 
10
 
11
+import java.util.List;
12
+
10
 /**
13
 /**
11
  * <p>
14
  * <p>
12
  * 帮我找房  Mapper 接口
15
  * 帮我找房  Mapper 接口
21
     IPage<SearchHouseVO> selectSearchHouseList(IPage<SearchHouseVO> pg,@Param("params") SearchHouseVO searchHouse);
24
     IPage<SearchHouseVO> selectSearchHouseList(IPage<SearchHouseVO> pg,@Param("params") SearchHouseVO searchHouse);
22
 
25
 
23
     SearchHouseVO selectSearchHouseDetail(String id);
26
     SearchHouseVO selectSearchHouseDetail(String id);
27
+
28
+    List<TaBuilding> getRecommendBuildings(@Param("orgId") Integer orgId,
29
+                                           @Param("cityId") Integer cityId,
30
+                                           @Param("areaId") Integer areaId,
31
+                                           @Param("minPriceW") Integer minPriceW,
32
+                                           @Param("maxPriceW") Integer maxPriceW,
33
+                                           @Param("minPrice") Integer minPrice,
34
+                                           @Param("maxPrice") Integer maxPrice);
24
 }
35
 }

+ 11
- 0
src/main/java/com/yunzhi/marketing/xlk/service/ISearchHouseService.java View File

3
 import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.baomidou.mybatisplus.extension.service.IService;
4
 import com.baomidou.mybatisplus.extension.service.IService;
5
 import com.yunzhi.marketing.base.ResponseBean;
5
 import com.yunzhi.marketing.base.ResponseBean;
6
+import com.yunzhi.marketing.entity.TaBuilding;
7
+import com.yunzhi.marketing.xlk.dto.SearchHouseDTO;
6
 import com.yunzhi.marketing.xlk.entity.SearchHouse;
8
 import com.yunzhi.marketing.xlk.entity.SearchHouse;
7
 import com.yunzhi.marketing.xlk.vo.SearchHouseVO;
9
 import com.yunzhi.marketing.xlk.vo.SearchHouseVO;
8
 
10
 
11
+import java.util.List;
12
+
9
 /**
13
 /**
10
  * <p>
14
  * <p>
11
  * 帮我找房  服务类
15
  * 帮我找房  服务类
26
     ResponseBean selectSearchHouseList(IPage<SearchHouseVO> pg, SearchHouseVO searchHouse);
30
     ResponseBean selectSearchHouseList(IPage<SearchHouseVO> pg, SearchHouseVO searchHouse);
27
 
31
 
28
     SearchHouseVO selectSearchHouseDetail(String id);
32
     SearchHouseVO selectSearchHouseDetail(String id);
33
+
34
+    /**
35
+     * 推荐楼盘
36
+     * @param searchHouseDTO
37
+     * @return
38
+     */
39
+    List<TaBuilding> getRecommendBuildings(Integer orgId, SearchHouseDTO searchHouseDTO);
29
 }
40
 }

+ 110
- 0
src/main/java/com/yunzhi/marketing/xlk/service/impl/SearchHouseServiceImpl.java View File

3
 import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
 import com.yunzhi.marketing.base.ResponseBean;
5
 import com.yunzhi.marketing.base.ResponseBean;
6
+import com.yunzhi.marketing.common.StringUtils;
7
+import com.yunzhi.marketing.entity.TaBuilding;
6
 import com.yunzhi.marketing.entity.TaCheckin;
8
 import com.yunzhi.marketing.entity.TaCheckin;
9
+import com.yunzhi.marketing.entity.TdCity;
10
+import com.yunzhi.marketing.mapper.TdCityMapper;
11
+import com.yunzhi.marketing.xlk.dto.SearchHouseDTO;
7
 import com.yunzhi.marketing.xlk.entity.SearchHouse;
12
 import com.yunzhi.marketing.xlk.entity.SearchHouse;
8
 import com.yunzhi.marketing.xlk.mapper.SearchHouseMapper;
13
 import com.yunzhi.marketing.xlk.mapper.SearchHouseMapper;
9
 import com.yunzhi.marketing.xlk.service.ISearchHouseService;
14
 import com.yunzhi.marketing.xlk.service.ISearchHouseService;
10
 import com.yunzhi.marketing.xlk.vo.SearchHouseVO;
15
 import com.yunzhi.marketing.xlk.vo.SearchHouseVO;
16
+import io.swagger.models.auth.In;
11
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.beans.factory.annotation.Autowired;
12
 import org.springframework.stereotype.Service;
18
 import org.springframework.stereotype.Service;
13
 
19
 
20
+import java.util.List;
21
+
14
 /**
22
 /**
15
  * <p>
23
  * <p>
16
  * 帮我找房  服务实现类
24
  * 帮我找房  服务实现类
25
     @Autowired
33
     @Autowired
26
     private SearchHouseMapper searchHouseMapper;
34
     private SearchHouseMapper searchHouseMapper;
27
 
35
 
36
+    @Autowired
37
+    private TdCityMapper tdCityMapper;
38
+
28
     /**
39
     /**
29
      * 查询我的找房需求列表
40
      * 查询我的找房需求列表
30
      *
41
      *
43
     public SearchHouseVO selectSearchHouseDetail(String id) {
54
     public SearchHouseVO selectSearchHouseDetail(String id) {
44
         return searchHouseMapper.selectSearchHouseDetail(id);
55
         return searchHouseMapper.selectSearchHouseDetail(id);
45
     }
56
     }
57
+
58
+    /**
59
+     * 推荐逻辑如下
60
+     * 1、先判断区域+价格,如果有符合楼盘,则推荐,如无看2;
61
+     * 2、判断城市+价格,如过有符合楼盘,则推荐,如无看3;
62
+     * 3、如选择了“不限城市”,则判断价格,在当前城市内推荐一个符合的。
63
+     * @param searchHouseDTO
64
+     * @return
65
+     */
66
+    @Override
67
+    public List<TaBuilding> getRecommendBuildings(Integer orgId, SearchHouseDTO searchHouseDTO) {
68
+        // 区域
69
+        String area = searchHouseDTO.getIntentArea();
70
+        Integer areaId = StringUtils.isEmpty(area) ? null : Integer.valueOf(area);
71
+        // 区域所属城市
72
+        Integer areaCity = null;
73
+        if (null != areaId) {
74
+            TdCity city = tdCityMapper.selectById(areaId);
75
+            areaCity = city.getParentid();
76
+        }
77
+
78
+        // 当前城市
79
+        Integer cityId = searchHouseDTO.getCityId();
80
+        // 最小总价
81
+        Integer minPriceW = Integer.parseInt(searchHouseDTO.getMinPrice());
82
+        // 最大总价
83
+        Integer maxPriceW = Integer.parseInt(searchHouseDTO.getMaxPrice());
84
+        // 面积字典
85
+        Integer areaResultId = searchHouseDTO.getAreaResultId();
86
+        //
87
+        Integer[] unitPrice = getUnitPriceRange(minPriceW, maxPriceW, areaResultId);
88
+        // 最小单价
89
+        Integer minPrice = unitPrice[0];
90
+        // 最大单价
91
+        Integer maxPrice = unitPrice[1];
92
+
93
+        if (null != areaId) {
94
+            // 1、先判断区域+价格
95
+            List<TaBuilding> lst1 = searchHouseMapper.getRecommendBuildings(orgId, null, areaId, minPriceW, maxPriceW, minPrice, maxPrice);
96
+            if (null != lst1 && lst1.size() > 0) {
97
+                return lst1;
98
+            }
99
+
100
+            // 2、判断城市+价格
101
+            List<TaBuilding> lst2 = searchHouseMapper.getRecommendBuildings(orgId, areaCity, null, minPriceW, maxPriceW, minPrice, maxPrice);
102
+            if (null != lst2 && lst2.size() > 0) {
103
+                return lst2;
104
+            }
105
+        }
106
+
107
+        // 3、当前城市
108
+        return searchHouseMapper.getRecommendBuildings(orgId, cityId, null, minPriceW, maxPriceW, minPrice, maxPrice);
109
+    }
110
+
111
+    private Integer[] getUnitPriceRange(Integer minPriceW, Integer maxPriceW, Integer areaResultId) {
112
+        Integer minPrice = minPriceW * 10000;
113
+        Integer maxPrice = maxPriceW * 10000;
114
+
115
+        // 字典过滤 - 必须与小程序端保持一致
116
+        switch (areaResultId) {
117
+            case 1:
118
+                // 60㎡ 以下, 则按照 30 - 60 处理
119
+                minPrice = minPrice / 60;
120
+                maxPrice = maxPrice / 30;
121
+                break;
122
+            case 2:
123
+                // 60 - 90
124
+                minPrice = minPrice / 90;
125
+                maxPrice = maxPrice / 60;
126
+                break;
127
+            case 3:
128
+                // 90 - 110
129
+                minPrice = minPrice / 110;
130
+                maxPrice = maxPrice / 90;
131
+                break;
132
+            case 4:
133
+                // 110 - 130
134
+                minPrice = minPrice / 130;
135
+                maxPrice = maxPrice / 110;
136
+                break;
137
+            case 5:
138
+                // 130 - 150
139
+                minPrice = minPrice / 150;
140
+                maxPrice = maxPrice / 130;
141
+                break;
142
+            case 6:
143
+                // 150 - 200
144
+                minPrice = minPrice / 200;
145
+                maxPrice = maxPrice / 150;
146
+                break;
147
+            default:
148
+                // 200 以上
149
+                minPrice = minPrice / 200;
150
+                maxPrice = maxPrice / 200;
151
+                break;
152
+        }
153
+
154
+        return new Integer[] {minPrice, maxPrice};
155
+    }
46
 }
156
 }

+ 22
- 0
src/main/resources/mapper/xlk/SearchHouseMapper.xml View File

39
             LEFT JOIN ta_person p ON t.person_id = p.person_id
39
             LEFT JOIN ta_person p ON t.person_id = p.person_id
40
             WHERE t.id = #{id}
40
             WHERE t.id = #{id}
41
     </select>
41
     </select>
42
+    <select id="getRecommendBuildings" resultType="com.yunzhi.marketing.entity.TaBuilding">
43
+        SELECT
44
+            DISTINCT t.*
45
+        FROM
46
+            ta_building t
47
+            INNER JOIN ta_building_project_type s ON t.building_id = s.building_id
48
+        WHERE
49
+            t.org_id = #{orgId}
50
+        <if test="cityId != null">
51
+            AND t.city_id = #{cityId}
52
+        </if>
53
+        <if test="areaId != null">
54
+            AND t.building_area = #{areaId}
55
+        </if>
56
+            AND (
57
+                ( s.start_price &gt;= #{minPriceW} AND s.end_price &lt;= #{maxPriceW} AND s.price_type = 'total' )
58
+                OR ( s.start_price &gt;= #{minPrice} AND s.end_price &lt;= #{maxPrice} AND s.price_type = 'average' )
59
+            )
60
+            AND t.`status` > - 1
61
+        ORDER BY
62
+            t.is_main ASC
63
+    </select>
42
 </mapper>
64
 </mapper>