张延森 5 anos atrás
pai
commit
7fd7e38fba

+ 76
- 6
src/main/java/com/huiju/estateagents/controller/MiniAppController.java Ver arquivo

@@ -16,12 +16,14 @@ import com.huiju.estateagents.common.CommConstant;
16 16
 import com.huiju.estateagents.common.WxUtils;
17 17
 import com.huiju.estateagents.entity.*;
18 18
 import com.huiju.estateagents.event.EventBus;
19
+import com.huiju.estateagents.mapper.TaOrgCityMapper;
19 20
 import com.huiju.estateagents.mapper.TaShareMapper;
20 21
 import com.huiju.estateagents.service.*;
21 22
 import com.huiju.estateagents.common.JWTUtils;
22 23
 import com.huiju.estateagents.third.entity.TaThirdPartyMiniappConfig;
23 24
 import com.huiju.estateagents.third.service.ITaThirdPartyMiniappConfigService;
24 25
 import me.chanjar.weixin.common.error.WxErrorException;
26
+import net.bytebuddy.asm.Advice;
25 27
 import org.apache.commons.collections.CollectionUtils;
26 28
 import org.apache.commons.lang3.StringUtils;
27 29
 import org.apache.http.HttpStatus;
@@ -85,6 +87,14 @@ public class MiniAppController extends BaseController {
85 87
     @Autowired
86 88
     public ITdPointsRulesService iTdPointsRulesService;
87 89
 
90
+    @Autowired
91
+    public ITaMiniappService iTaMiniappService;
92
+
93
+    @Autowired
94
+    public TaOrgCityMapper taOrgCityMapper;
95
+
96
+    @Autowired
97
+    public ITdCityService iTdCityService;
88 98
 
89 99
     /**
90 100
      * 验证接入
@@ -97,6 +107,60 @@ public class MiniAppController extends BaseController {
97 107
         return echostr;
98 108
     }
99 109
 
110
+
111
+    /**
112
+     * 小程序数据预拉取 https://developers.weixin.qq.com/miniprogram/dev/framework/ability/pre-fetch.html
113
+     * @param appid
114
+     * @param timestamp
115
+     * @param token
116
+     * @param code
117
+     * @param path
118
+     * @param query
119
+     * @param scene
120
+     * @return
121
+     */
122
+    @GetMapping("/preload")
123
+    public ResponseBean getPreloadData(
124
+            @RequestParam(name = "appid") String appid,
125
+            @RequestParam(name = "timestamp") Long timestamp,
126
+            String token,
127
+            String code,
128
+            String path,
129
+            String query,
130
+            Integer scene
131
+    ) {
132
+        // 获取小程序信息
133
+        TaMiniapp taMiniapp = iTaMiniappService.getInfoWithTpls(appid);
134
+        if (null == taMiniapp) {
135
+            return ResponseBean.error("当前 appid 未在系统内注册", ResponseBean.ERROR_ILLEGAL_PARAMS);
136
+        }
137
+
138
+        // 获取组织信息
139
+        TaOrg taOrg = taOrgService.getById(taMiniapp.getOrgId());
140
+        if (null == taOrg) {
141
+            return ResponseBean.error("当前 appid 未设置对应组织", ResponseBean.ERROR_UNAVAILABLE);
142
+        }
143
+
144
+        // 获取城市列表
145
+        QueryWrapper<TaOrgCity> queryCity = new QueryWrapper<>();
146
+        queryCity.eq("id", taOrg.getOrgId());
147
+        queryCity.eq("status", CommConstant.STATUS_NORMAL);
148
+        List<TaOrgCity> taOrgCityList = taOrgCityMapper.selectList(queryCity);
149
+
150
+        // 获取默认扩展设置
151
+        QueryWrapper<TaCustomImg> queryExt = new QueryWrapper<>();
152
+        queryExt.eq("org_id", taOrg.getOrgId());
153
+        queryExt.eq("status", CommConstant.STATUS_NORMAL);
154
+        List<TaCustomImg> taCustomImg = iTaCustomImgService.list(queryExt);
155
+
156
+        return ResponseBean.success(new HashMap<String, Object>(){{
157
+            put("miniapp", taMiniapp);
158
+            put("org", taOrg);
159
+            put("cityList", taOrgCityList);
160
+            put("customImg", taCustomImg);
161
+        }});
162
+    }
163
+
100 164
     /**
101 165
      * 登陆接口
102 166
      */
@@ -104,8 +168,10 @@ public class MiniAppController extends BaseController {
104 168
     public ResponseBean login(
105 169
             String code,
106 170
             @RequestParam(required = false) String from,
107
-            @RequestParam(required = false)String recommender,
108
-            @RequestParam(required = false)String targetId,
171
+            @RequestParam(required = false) String recommender,
172
+            @RequestParam(required = false) String targetId,
173
+            @RequestParam(required = false) String lon,
174
+            @RequestParam(required = false) String lat,
109 175
             HttpServletRequest request) {
110 176
         String appid = request.getHeader("appid");
111 177
 
@@ -218,7 +284,7 @@ public class MiniAppController extends BaseController {
218 284
             // 所有人员都返回 org yansen 2019-11-13 19:56:18
219 285
 //            if (CommConstant.PERSON_REALTY_CONSULTANT.equals(taPerson.getPersonType())){
220 286
                 QueryWrapper<TaOrg>orgQueryWrapper = new QueryWrapper<>();
221
-                orgQueryWrapper.eq("org_id",taPerson.getOrgId());
287
+                orgQueryWrapper.eq("org_id", orgId);
222 288
                 TaOrg org = taOrgService.getOne(orgQueryWrapper);
223 289
                 taPerson.setOrg(org);
224 290
 //            }
@@ -230,21 +296,25 @@ public class MiniAppController extends BaseController {
230 296
 
231 297
             //返回是否授权标识
232 298
             QueryWrapper<TaCustomImg> queryWrapper = new QueryWrapper<>();
233
-            queryWrapper.eq("org_id", getOrgId(request));
299
+            queryWrapper.eq("org_id", orgId);
234 300
             queryWrapper.eq("img_type", "auth");
235 301
             List<TaCustomImg>  taCustomImgs = iTaCustomImgService.list(queryWrapper);
236 302
             result.put("avatarAuth", CollectionUtils.isEmpty(taCustomImgs) ? false : "1".equals(taCustomImgs.get(0).getImgUrl()) ? true: false);
237 303
 
238
-
239 304
             String token = (String) miniResp.get("token");
240 305
             sysTokenService.saveToken(token);
241 306
 
242 307
             //把積分規則返回給小程序
243 308
             QueryWrapper<TdPointsRules> tdPointsRulesQueryWrapper = new QueryWrapper<>();
244
-            tdPointsRulesQueryWrapper.eq("org_id",taPerson.getOrgId());
309
+            tdPointsRulesQueryWrapper.eq("org_id", orgId);
245 310
             List<TdPointsRules> rulesPointList = iTdPointsRulesService.list(tdPointsRulesQueryWrapper);
246 311
             result.put("rulesPointList",rulesPointList);
247 312
 
313
+            // 定位城市
314
+            String location = null == lon ? null : lon + "," + lat;
315
+            TdCity tdCity = iTdCityService.getLocationCity(location, orgId);
316
+            result.put("city", tdCity);
317
+
248 318
             return ResponseBean.success(result);
249 319
         } catch (WxErrorException e) {
250 320
             System.err.println(e.getError());

+ 2
- 2
src/main/java/com/huiju/estateagents/controller/TaBuildingController.java Ver arquivo

@@ -322,9 +322,9 @@ public class TaBuildingController extends BaseController {
322 322
      * @return
323 323
      */
324 324
     @RequestMapping(value = "/wx/building/main", method = RequestMethod.GET)
325
-    public ResponseBean getWxMainBuildingList(HttpServletRequest request){
325
+    public ResponseBean getWxMainBuildingList(String cityId, HttpServletRequest request){
326 326
         Integer orgId = getOrgId(request);
327
-        return taBuildingService.getWxMainBuildingList(orgId);
327
+        return taBuildingService.getWxMainBuildingList(cityId, orgId);
328 328
     }
329 329
 
330 330
     /**

+ 2
- 1
src/main/java/com/huiju/estateagents/controller/TdCityController.java Ver arquivo

@@ -189,8 +189,9 @@ public class TdCityController extends BaseController {
189 189
     @RequestMapping(value="/wx/location/city",method= RequestMethod.GET)
190 190
     public ResponseBean wxLocationCityDetail(@RequestParam(value = "location") String location,HttpServletRequest request){
191 191
         ResponseBean responseBean = new ResponseBean();
192
+        Integer orgId = getOrgId(request);
192 193
         try {
193
-            TdCity tdCity = iTdCityService.getLocationCity(location);
194
+            TdCity tdCity = iTdCityService.getLocationCity(location, orgId);
194 195
             responseBean.addSuccess(tdCity);
195 196
         }catch (Exception e){
196 197
             logger.error("tdCityList -=- {}",e.toString());

+ 1
- 0
src/main/java/com/huiju/estateagents/interceptor/AccessInterceptor.java Ver arquivo

@@ -52,6 +52,7 @@ public class AccessInterceptor implements HandlerInterceptor {
52 52
             "/wx/chat", // 聊天暂时不鉴权
53 53
             "/api/wx/",
54 54
             "/api/wx/tdCity",
55
+            "/api/wx/preload",
55 56
             "/api/admin/signin",
56 57
             "/api/taCheckin/activity",
57 58
             "/api/wx/qrcode/scene",

+ 1
- 1
src/main/java/com/huiju/estateagents/mapper/TaBuildingMapper.java Ver arquivo

@@ -92,5 +92,5 @@ public interface TaBuildingMapper extends BaseMapper<TaBuilding> {
92 92
      */
93 93
     int countNumByHeavy(@Param("heavy") Integer heavy, @Param("dynamicId") String dynamicId);
94 94
 
95
-    List<TaBuilding> selectMainBuildings(@Param("orgId") Integer orgId);
95
+    List<TaBuilding> selectMainBuildings(@Param("cityId") String cityId, @Param("orgId") Integer orgId);
96 96
 }

+ 2
- 0
src/main/java/com/huiju/estateagents/mapper/TdCityMapper.java Ver arquivo

@@ -26,4 +26,6 @@ public interface TdCityMapper extends BaseMapper<TdCity> {
26 26
      * @return
27 27
      */
28 28
     List<TdCity> selectWxCity(@Param("orgId") Integer orgId);
29
+
30
+    TdCity getOrgDefaultCity(@Param("orgId") Integer orgId);
29 31
 }

+ 1
- 1
src/main/java/com/huiju/estateagents/service/ITaBuildingService.java Ver arquivo

@@ -133,7 +133,7 @@ public interface ITaBuildingService extends IService<TaBuilding> {
133 133
      * 微信小程序 楼盘列表
134 134
      * @return
135 135
      */
136
-    ResponseBean getWxMainBuildingList(Integer orgId);
136
+    ResponseBean getWxMainBuildingList(String cityId, Integer orgId);
137 137
 
138 138
     ResponseBean getWxBuildingById(String buildingId);
139 139
 

+ 2
- 0
src/main/java/com/huiju/estateagents/service/ITaMiniappService.java Ver arquivo

@@ -14,4 +14,6 @@ import com.huiju.estateagents.entity.TaMiniapp;
14 14
 public interface ITaMiniappService extends IService<TaMiniapp> {
15 15
 
16 16
     TaMiniapp saveInfoWithTpls(TaMiniapp taMiniapp, Integer channelId) throws Exception;
17
+
18
+    TaMiniapp getInfoWithTpls(String appid);
17 19
 }

+ 2
- 2
src/main/java/com/huiju/estateagents/service/ITdCityService.java Ver arquivo

@@ -18,12 +18,12 @@ public interface ITdCityService extends IService<TdCity> {
18 18
     List<TdCity> selectCity(String leveltype,String status);
19 19
 
20 20
     // 微信端城市
21
-    List<TdCity> selectWxCity(String leveltype,Integer orgId);
21
+    List<TdCity> selectWxCity(String leveltype, Integer orgId);
22 22
 	
23 23
 	/**
24 24
 	 * 根据经纬度获取城市详情信息
25 25
 	 * @param location
26 26
 	 * @return
27 27
 	 */
28
-	TdCity getLocationCity(String location);
28
+	TdCity getLocationCity(String location, Integer orgId);
29 29
 }

+ 2
- 2
src/main/java/com/huiju/estateagents/service/impl/TaBuildingServiceImpl.java Ver arquivo

@@ -764,8 +764,8 @@ public class TaBuildingServiceImpl extends ServiceImpl<TaBuildingMapper, TaBuild
764 764
     }
765 765
 
766 766
     @Override
767
-    public ResponseBean getWxMainBuildingList(Integer orgId) {
768
-        List<TaBuilding> buildingList = taBuildingMapper.selectMainBuildings(orgId);
767
+    public ResponseBean getWxMainBuildingList(String cityId, Integer orgId) {
768
+        List<TaBuilding> buildingList = taBuildingMapper.selectMainBuildings(cityId, orgId);
769 769
         if (null == buildingList) {
770 770
             return ResponseBean.success(new ArrayList<>());
771 771
         }

+ 15
- 0
src/main/java/com/huiju/estateagents/service/impl/TaMiniappServiceImpl.java Ver arquivo

@@ -30,6 +30,9 @@ import java.time.LocalDateTime;
30 30
  */
31 31
 @Service
32 32
 public class TaMiniappServiceImpl extends ServiceImpl<TaMiniappMapper, TaMiniapp> implements ITaMiniappService {
33
+    @Autowired
34
+    TaMiniappMapper taMiniappMapper;
35
+
33 36
     @Autowired
34 37
     TaMiniappTemplateMapper taMiniappTemplateMapper;
35 38
 
@@ -108,4 +111,16 @@ public class TaMiniappServiceImpl extends ServiceImpl<TaMiniappMapper, TaMiniapp
108 111
 
109 112
         return taMiniapp;
110 113
     }
114
+
115
+    @Override
116
+    public TaMiniapp getInfoWithTpls(String appid) {
117
+        TaMiniapp taMiniapp = taMiniappMapper.selectById(appid);
118
+
119
+        QueryWrapper<TaMiniappTemplate> queryWrapper = new QueryWrapper<>();
120
+        queryWrapper.eq("miniapp_id", appid);
121
+        queryWrapper.eq("is_subscribe", 1);
122
+        taMiniapp.setTpls(taMiniappTemplateMapper.selectList(queryWrapper));
123
+
124
+        return taMiniapp;
125
+    }
111 126
 }

+ 9
- 3
src/main/java/com/huiju/estateagents/service/impl/TdCityServiceImpl.java Ver arquivo

@@ -45,7 +45,11 @@ public class TdCityServiceImpl extends ServiceImpl<TdCityMapper, TdCity> impleme
45 45
      * @return
46 46
      */
47 47
     @Override
48
-    public TdCity getLocationCity(String location) {
48
+    public TdCity getLocationCity(String location, Integer orgId) {
49
+        if (null == location) {
50
+            return tdCityMapper.getOrgDefaultCity(orgId);
51
+        }
52
+
49 53
         //获取高德地图的坐标
50 54
         String amapString = CommConstant.AMAP_HTTP + "?location="+location+"&key=" + CommConstant.AMAP_KEY;
51 55
         RestTemplate restTemplate = new RestTemplate();
@@ -62,9 +66,11 @@ public class TdCityServiceImpl extends ServiceImpl<TdCityMapper, TdCity> impleme
62 66
             if (tdCities.size() > 0){
63 67
                 return tdCities.get(0);
64 68
             }
65
-            return null;
69
+//            return null;
66 70
         }
67
-        return null;
71
+
72
+        // 没有匹配到则返回默认城市
73
+        return tdCityMapper.getOrgDefaultCity(orgId);
68 74
     }
69 75
     
70 76
 }

+ 5
- 2
src/main/resources/mapper/TaBuildingMapper.xml Ver arquivo

@@ -232,8 +232,11 @@
232 232
         LEFT JOIN ta_building_tag m ON t.building_id = m.building_id
233 233
         WHERE
234 234
             t.org_id = #{orgId}
235
-        AND t.status = 1
236
-        AND t.is_main = 1
235
+        <if test="cityId != null and cityId != ''">
236
+            AND t.city_id = #{cityId}
237
+        </if>
238
+            AND t.status = 1
239
+            AND t.is_main = 1
237 240
         GROUP BY
238 241
             t.building_id
239 242
         ORDER BY t.order_no

+ 9
- 0
src/main/resources/mapper/TdCityMapper.xml Ver arquivo

@@ -47,5 +47,14 @@ ORDER BY
47 47
                 ORDER BY
48 48
                 c.pinyin
49 49
     </select>
50
+    <select id="getOrgDefaultCity" resultType="com.huiju.estateagents.entity.TdCity">
51
+        SELECT
52
+            t.*
53
+        FROM
54
+            td_city t
55
+            JOIN ta_org s ON t.id = s.default_city_id
56
+        WHERE
57
+            s.org_id = #{orgId}
58
+    </select>
50 59
 
51 60
 </mapper>