Sfoglia il codice sorgente

Merge branch 'master' of http://git.ycjcjy.com/whole-estate/service

zjxpcyc 6 anni fa
parent
commit
208e41b29b
24 ha cambiato i file con 811 aggiunte e 7 eliminazioni
  1. 26
    0
      whole-estate/pom.xml
  2. 241
    0
      whole-estate/src/main/java/com/example/wholeestate/common/http/OkHttpRequestUtils.java
  3. 24
    1
      whole-estate/src/main/java/com/example/wholeestate/controller/ActivityController.java
  4. 11
    0
      whole-estate/src/main/java/com/example/wholeestate/controller/BuildingController.java
  5. 1
    0
      whole-estate/src/main/java/com/example/wholeestate/controller/CustomerController.java
  6. 12
    0
      whole-estate/src/main/java/com/example/wholeestate/controller/WxUserController.java
  7. 5
    1
      whole-estate/src/main/java/com/example/wholeestate/dao/BuildingImgMapper.java
  8. 5
    1
      whole-estate/src/main/java/com/example/wholeestate/model/Building.java
  9. 4
    0
      whole-estate/src/main/java/com/example/wholeestate/model/Customer.java
  10. 6
    1
      whole-estate/src/main/java/com/example/wholeestate/service/IActivityService.java
  11. 8
    0
      whole-estate/src/main/java/com/example/wholeestate/service/IBuildingService.java
  12. 8
    0
      whole-estate/src/main/java/com/example/wholeestate/service/ICustomerService.java
  13. 16
    0
      whole-estate/src/main/java/com/example/wholeestate/service/impl/ActivityServiceImpl.java
  14. 37
    0
      whole-estate/src/main/java/com/example/wholeestate/service/impl/BuildingServiceImpl.java
  15. 43
    2
      whole-estate/src/main/java/com/example/wholeestate/service/impl/CustomerServiceImpl.java
  16. 137
    0
      whole-estate/src/main/java/com/example/wholeestate/utils/BeanTools.java
  17. 72
    0
      whole-estate/src/main/java/com/example/wholeestate/utils/StringConverter.java
  18. 22
    0
      whole-estate/src/main/java/com/example/wholeestate/wx/WxBase.java
  19. 22
    0
      whole-estate/src/main/java/com/example/wholeestate/wx/WxConstant.java
  20. 26
    0
      whole-estate/src/main/java/com/example/wholeestate/wx/WxMiniProperties.java
  21. 20
    0
      whole-estate/src/main/java/com/example/wholeestate/wx/mini/IWxMini.java
  22. 56
    0
      whole-estate/src/main/java/com/example/wholeestate/wx/mini/impl/WxMiniImpl.java
  23. 5
    0
      whole-estate/src/main/resources/application.yml
  24. 4
    1
      whole-estate/src/main/resources/mapper/BuildingImgMapper.xml

+ 26
- 0
whole-estate/pom.xml Vedi File

@@ -123,6 +123,32 @@
123 123
             <version>2.7.0</version>
124 124
         </dependency>
125 125
 
126
+        <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
127
+        <dependency>
128
+            <groupId>com.squareup.okhttp3</groupId>
129
+            <artifactId>okhttp</artifactId>
130
+            <version>3.11.0</version>
131
+        </dependency>
132
+
133
+        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
134
+        <dependency>
135
+            <groupId>com.google.guava</groupId>
136
+            <artifactId>guava</artifactId>
137
+            <version>26.0-jre</version>
138
+        </dependency>
139
+
140
+        <dependency>
141
+            <groupId>org.jodd</groupId>
142
+            <artifactId>jodd-bean</artifactId>
143
+            <version>3.7.1</version>
144
+        </dependency>
145
+
146
+        <dependency>
147
+            <groupId>commons-collections</groupId>
148
+            <artifactId>commons-collections</artifactId>
149
+            <version>3.2.1</version>
150
+        </dependency>
151
+
126 152
     </dependencies>
127 153
 
128 154
     <build>

+ 241
- 0
whole-estate/src/main/java/com/example/wholeestate/common/http/OkHttpRequestUtils.java Vedi File

@@ -0,0 +1,241 @@
1
+package com.example.wholeestate.common.http;
2
+
3
+import com.google.common.collect.Maps;
4
+import okhttp3.*;
5
+
6
+import java.io.ByteArrayOutputStream;
7
+import java.io.File;
8
+import java.io.FileInputStream;
9
+import java.util.Iterator;
10
+import java.util.Map;
11
+
12
+/**
13
+ * 封装请求
14
+ * @author weiximei
15
+ */
16
+public class OkHttpRequestUtils {
17
+
18
+    // 定义请求客户端
19
+    private static OkHttpClient client = new OkHttpClient();
20
+
21
+    /**
22
+     * get 请求
23
+     * @param url 请求URL
24
+     * @return
25
+     * @throws Exception
26
+     */
27
+    public static String doGet(String url) throws Exception {
28
+       return doGet(url, Maps.newHashMap());
29
+    }
30
+
31
+
32
+    /**
33
+     * get 请求
34
+     * @param url 请求URL
35
+     * @param query 携带参数参数
36
+     * @return
37
+     * @throws Exception
38
+     */
39
+    public static String doGet(String url, Map<String, Object> query) throws Exception {
40
+
41
+        return doGet(url, Maps.newHashMap(), query);
42
+    }
43
+
44
+    /**
45
+     * get 请求
46
+     * @param url url
47
+     * @param header 请求头参数
48
+     * @param query 参数
49
+     * @return
50
+     */
51
+    public static String doGet(String url, Map<String, Object> header, Map<String, Object> query) throws Exception {
52
+
53
+        // 创建一个请求 Builder
54
+        Request.Builder builder = new Request.Builder();
55
+        // 创建一个 request
56
+        Request request = builder.url(url).build();
57
+
58
+        // 创建一个 HttpUrl.Builder
59
+        HttpUrl.Builder urlBuilder = request.url().newBuilder();
60
+        // 创建一个 Headers.Builder
61
+        Headers.Builder headerBuilder = request.headers().newBuilder();
62
+
63
+        // 装载请求头参数
64
+        Iterator<Map.Entry<String, Object>> headerIterator = header.entrySet().iterator();
65
+        headerIterator.forEachRemaining(e -> {
66
+            headerBuilder.add(e.getKey(), (String) e.getValue());
67
+        });
68
+
69
+        // 装载请求的参数
70
+        Iterator<Map.Entry<String, Object>> queryIterator = query.entrySet().iterator();
71
+        queryIterator.forEachRemaining(e -> {
72
+            urlBuilder.addQueryParameter(e.getKey(), (String) e.getValue());
73
+        });
74
+
75
+        // 设置自定义的 builder
76
+        builder.url(urlBuilder.build()).headers(headerBuilder.build());
77
+
78
+        Request buildRequest = builder.build();
79
+
80
+        System.out.println("OkHttp 发起的请求:" + buildRequest.url().toString());
81
+
82
+        try (Response execute = client.newCall(buildRequest).execute()) {
83
+            return execute.body().string();
84
+        }
85
+    }
86
+
87
+    /**
88
+     * post 请求, 请求参数 并且 携带文件上传
89
+     * @param url
90
+     * @param header
91
+     * @param parameter
92
+     * @param file
93
+     * @return
94
+     * @throws Exception
95
+     */
96
+    public static String doPost(String url, Map<String, Object> header, Map<String, Object> parameter, File file) throws Exception {
97
+
98
+        // 创建一个请求 Builder
99
+        Request.Builder builder = new Request.Builder();
100
+        // 创建一个 request
101
+        Request request = builder.url(url).build();
102
+
103
+        // 创建一个 Headers.Builder
104
+        Headers.Builder headerBuilder = request.headers().newBuilder();
105
+
106
+        // 装载请求头参数
107
+        Iterator<Map.Entry<String, Object>> headerIterator = header.entrySet().iterator();
108
+        headerIterator.forEachRemaining(e -> {
109
+            headerBuilder.add(e.getKey(), (String) e.getValue());
110
+        });
111
+
112
+        MultipartBody.Builder requestBuilder = new MultipartBody.Builder();
113
+
114
+        // 状态请求参数
115
+        Iterator<Map.Entry<String, Object>> queryIterator = parameter.entrySet().iterator();
116
+        queryIterator.forEachRemaining(e -> {
117
+            requestBuilder.addFormDataPart(e.getKey(), (String) e.getValue());
118
+        });
119
+
120
+        if (null != file) {
121
+            // application/octet-stream
122
+            requestBuilder.addFormDataPart("uploadFiles", file.getName(), RequestBody.create(MediaType.parse("application/octet-stream"), file));
123
+        }
124
+
125
+        // 设置自定义的 builder
126
+        builder.headers(headerBuilder.build()).post(requestBuilder.build());
127
+
128
+        // 然后再 build 一下
129
+        try (Response execute = client.newCall(builder.build()).execute()) {
130
+            return execute.body().string();
131
+        }
132
+    }
133
+
134
+    /**
135
+     * post 请求, 请求参数 并且 携带文件上传二进制流
136
+     * @param url
137
+     * @param header
138
+     * @param parameter
139
+     * @param fileName 文件名
140
+     * @param fileByte 文件的二进制流
141
+     * @return
142
+     * @throws Exception
143
+     */
144
+    public static String doPost(String url, Map<String, Object> header, Map<String, Object> parameter, String fileName, byte [] fileByte) throws Exception {
145
+// 创建一个请求 Builder
146
+        Request.Builder builder = new Request.Builder();
147
+        // 创建一个 request
148
+        Request request = builder.url(url).build();
149
+
150
+        // 创建一个 Headers.Builder
151
+        Headers.Builder headerBuilder = request.headers().newBuilder();
152
+
153
+        // 装载请求头参数
154
+        Iterator<Map.Entry<String, Object>> headerIterator = header.entrySet().iterator();
155
+        headerIterator.forEachRemaining(e -> {
156
+            headerBuilder.add(e.getKey(), (String) e.getValue());
157
+        });
158
+
159
+        MultipartBody.Builder requestBuilder = new MultipartBody.Builder();
160
+
161
+        // 状态请求参数
162
+        Iterator<Map.Entry<String, Object>> queryIterator = parameter.entrySet().iterator();
163
+        queryIterator.forEachRemaining(e -> {
164
+            requestBuilder.addFormDataPart(e.getKey(), (String) e.getValue());
165
+        });
166
+
167
+        if (fileByte.length > 0) {
168
+            // application/octet-stream
169
+            requestBuilder.addFormDataPart("uploadFiles", fileName, RequestBody.create(MediaType.parse("application/octet-stream"), fileByte));
170
+        }
171
+
172
+        // 设置自定义的 builder
173
+        builder.headers(headerBuilder.build()).post(requestBuilder.build());
174
+
175
+        try (Response execute = client.newCall(builder.build()).execute()) {
176
+            return execute.body().string();
177
+        }
178
+    }
179
+
180
+
181
+    /**
182
+     * post 请求  携带文件上传
183
+     * @param url
184
+     * @param file
185
+     * @return
186
+     * @throws Exception
187
+     */
188
+    public static String doPost(String url, File file) throws Exception {
189
+        return doPost(url, Maps.newHashMap(), Maps.newHashMap(), file);
190
+    }
191
+
192
+    /**
193
+     * post 请求
194
+     * @param url
195
+     * @param header 请求头
196
+     * @param parameter 参数
197
+     * @return
198
+     * @throws Exception
199
+     */
200
+    public static String doPost(String url, Map<String, Object> header, Map<String, Object> parameter) throws Exception {
201
+        return doPost(url, header, parameter, null);
202
+    }
203
+
204
+    /**
205
+     * post 请求
206
+     * @param url
207
+     * @param parameter 参数
208
+     * @return
209
+     * @throws Exception
210
+     */
211
+    public static String doPost(String url, Map<String, Object> parameter) throws Exception {
212
+        return doPost(url, Maps.newHashMap(), parameter, null);
213
+    }
214
+
215
+    public static void main(String[] args) throws Exception {
216
+
217
+        byte [] fileByte = null;
218
+
219
+        File file = new File("C:\\Users\\szc\\Pictures\\file-read-4182.jpg");
220
+        FileInputStream fileInputStream = new FileInputStream(file);
221
+
222
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
223
+        byte[] b = new byte[1024];
224
+        int n;
225
+        while ((n = fileInputStream.read(b)) != -1)
226
+        {
227
+            bos.write(b, 0, n);
228
+        }
229
+        fileInputStream.close();
230
+        bos.close();
231
+        fileByte = bos.toByteArray();
232
+
233
+
234
+        Map<String, Object> queryMap = Maps.newHashMap();
235
+        queryMap.put("pageNum","2");
236
+        queryMap.put("pageSize","50");
237
+        System.out.println(OkHttpRequestUtils.doPost("http://localhost:8080/uploadImage" , Maps.newHashMap(), Maps.newHashMap(),file.getName(), fileByte));
238
+
239
+    }
240
+
241
+}

+ 24
- 1
whole-estate/src/main/java/com/example/wholeestate/controller/ActivityController.java Vedi File

@@ -189,7 +189,7 @@ public class ActivityController extends BaseController {
189 189
         return responseBean;
190 190
     }
191 191
 
192
-    @RequestMapping(value = "/wx/activity/{openid}", method = RequestMethod.GET)
192
+    @RequestMapping(value = "/wx/activity/byuser/{openid}", method = RequestMethod.GET)
193 193
     @ApiOperation(value = "微信小程序 根据openid查询参加过的活动列表", notes = "微信小程序 根据openid查询参加过的活动列表")
194 194
     @ApiImplicitParams({
195 195
             @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "pageNum", value = "pageNum第几页"),
@@ -212,4 +212,27 @@ public class ActivityController extends BaseController {
212 212
         return responseBean;
213 213
     }
214 214
 
215
+    @RequestMapping(value = "/wx/activity", method = RequestMethod.GET)
216
+    @ApiOperation(value = "微信活动列表", notes = "微信活动列表")
217
+    @ApiImplicitParams({
218
+            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "pageNum", value = "pageNum第几页"),
219
+            @ApiImplicitParam(paramType = "query", dataTypeClass = Integer.class, name = "pageSize", value = "pageSize一页多少行")
220
+    })
221
+    public ResponseBean getWxList(@RequestParam(defaultValue = "1") Integer pageNum,
222
+                                @RequestParam(defaultValue = "10") Integer pageSize) {
223
+        ResponseBean responseBean = new ResponseBean();
224
+        responseBean = iActivityService.getList(pageNum, pageSize, null,null,null);
225
+        return responseBean;
226
+    }
227
+
228
+    @RequestMapping(value = "/wx/activity/{activityId}", method = RequestMethod.GET)
229
+    @ApiOperation(value = "活动详情", notes = "活动详情")
230
+    @ApiImplicitParams({
231
+            @ApiImplicitParam(paramType = "path", dataTypeClass = String.class, name = "activityId", value = "activityId活动id")
232
+    })
233
+    public ResponseBean getWxById(@PathVariable String activityId) {
234
+        ResponseBean responseBean = new ResponseBean();
235
+        responseBean = iActivityService.getWxActivityId(activityId);
236
+        return responseBean;
237
+    }
215 238
 }

+ 11
- 0
whole-estate/src/main/java/com/example/wholeestate/controller/BuildingController.java Vedi File

@@ -265,4 +265,15 @@ public class BuildingController extends BaseController {
265 265
         ResponseBean  responseBean = iBuildingService.buildingUpdate(parameter);
266 266
         return responseBean;
267 267
     }
268
+
269
+
270
+    @RequestMapping(value = "/wx/buildingSelectId/{id}", method = RequestMethod.GET)
271
+    @ApiOperation(value = "楼盘详情", notes = "楼盘详情")
272
+    @ApiImplicitParams({
273
+            @ApiImplicitParam(paramType = "path", dataTypeClass=String.class, name = "id", value = "楼盘id"),
274
+    })
275
+    public ResponseBean wxBuildingSelectId(@PathVariable(value = "id") String id){
276
+        ResponseBean  responseBean = iBuildingService.buildingAllSelectId(id);
277
+        return responseBean;
278
+    }
268 279
 }

+ 1
- 0
whole-estate/src/main/java/com/example/wholeestate/controller/CustomerController.java Vedi File

@@ -82,4 +82,5 @@ public class CustomerController extends BaseController {
82 82
         return responseBean;
83 83
     }
84 84
 
85
+
85 86
 }

+ 12
- 0
whole-estate/src/main/java/com/example/wholeestate/controller/WxUserController.java Vedi File

@@ -10,6 +10,8 @@ import io.swagger.annotations.ApiOperation;
10 10
 import org.springframework.beans.factory.annotation.Autowired;
11 11
 import org.springframework.web.bind.annotation.*;
12 12
 
13
+import javax.servlet.http.HttpSession;
14
+
13 15
 @RestController
14 16
 @RequestMapping("/")
15 17
 @Api(value = "微信小程序 用户 API", description = "微信小程序 用户 API")
@@ -50,4 +52,14 @@ public class WxUserController extends BaseController {
50 52
         return responseBean;
51 53
     }
52 54
 
55
+    @RequestMapping(value = "/wx/getOpenid", method = RequestMethod.GET)
56
+    @ApiOperation(value = "微信小程序获取 openid", notes = "微信小程序获取 openid")
57
+    @ApiImplicitParams({
58
+            @ApiImplicitParam(paramType = "query", dataTypeClass=String.class, name = "code", value = "code"),
59
+    })
60
+    public ResponseBean getOpenid(@RequestParam(value = "code") String code, HttpSession session){
61
+        ResponseBean  responseBean = iCustomerService.wxOpenid(code);
62
+        return responseBean;
63
+    }
64
+
53 65
 }

+ 5
- 1
whole-estate/src/main/java/com/example/wholeestate/dao/BuildingImgMapper.java Vedi File

@@ -1,7 +1,11 @@
1 1
 package com.example.wholeestate.dao;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.example.wholeestate.model.BuildingDynamic;
4 5
 import com.example.wholeestate.model.BuildingImg;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.List;
5 9
 
6 10
 /**
7 11
  * <p>
@@ -12,5 +16,5 @@ import com.example.wholeestate.model.BuildingImg;
12 16
  * @since 2019-03-21
13 17
  */
14 18
 public interface BuildingImgMapper extends BaseMapper<BuildingImg> {
15
-
19
+    List<BuildingImg> getBuildingImgByApartment(@Param("id") String id);
16 20
 }

+ 5
- 1
whole-estate/src/main/java/com/example/wholeestate/model/Building.java Vedi File

@@ -100,5 +100,9 @@ public class Building implements Serializable {
100 100
     @TableField(exist = false)
101 101
     private List<BuildingImg> BuildingImg;
102 102
 
103
-
103
+    /**
104
+     * 户型
105
+     */
106
+    @TableField(exist = false)
107
+    private List<BuildingApartment> buildingApartment;
104 108
 }

+ 4
- 0
whole-estate/src/main/java/com/example/wholeestate/model/Customer.java Vedi File

@@ -49,5 +49,9 @@ public class Customer implements Serializable {
49 49
 
50 50
     private String avatar;
51 51
 
52
+    /**
53
+     * 0 未注册 1 已注册
54
+     */
55
+    private Integer hasReg;
52 56
 
53 57
 }

+ 6
- 1
whole-estate/src/main/java/com/example/wholeestate/service/IActivityService.java Vedi File

@@ -39,5 +39,10 @@ public interface IActivityService extends IService<Activity> {
39 39
      */
40 40
     ResponseBean getWxActivityList(Integer pageNum, Integer pageSize);
41 41
 
42
-
42
+    /**
43
+     * 微信 精彩活动详情
44
+     * @param activityId
45
+     * @return
46
+     */
47
+    ResponseBean getWxActivityId(String activityId);
43 48
 }

+ 8
- 0
whole-estate/src/main/java/com/example/wholeestate/service/IBuildingService.java Vedi File

@@ -29,6 +29,14 @@ public interface IBuildingService extends IService<Building> {
29 29
      */
30 30
     ResponseBean buildingSelectId(String id);
31 31
 
32
+    /**
33
+     * 楼盘详情
34
+     * @param id
35
+     * @return
36
+     */
37
+    ResponseBean buildingAllSelectId(String id);
38
+
39
+
32 40
     /**
33 41
      * 修改楼盘
34 42
      * @param parameter

+ 8
- 0
whole-estate/src/main/java/com/example/wholeestate/service/ICustomerService.java Vedi File

@@ -42,6 +42,14 @@ public interface ICustomerService extends IService<Customer> {
42 42
      */
43 43
     ResponseBean getWXCustomer(String openid);
44 44
 
45
+    /**
46
+     * 根据 code 获取 openid
47
+     *
48
+     * @param code
49
+     * @return
50
+     */
51
+    ResponseBean wxOpenid(String code);
52
+
45 53
 
46 54
     ResponseBean updateCustomer(String parameter);
47 55
 }

+ 16
- 0
whole-estate/src/main/java/com/example/wholeestate/service/impl/ActivityServiceImpl.java Vedi File

@@ -92,4 +92,20 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> i
92 92
         responseBean.addSuccess(activityIPage);
93 93
         return responseBean;
94 94
     }
95
+
96
+    @Override
97
+    public  ResponseBean getWxActivityId(String activityId) {
98
+        ResponseBean responseBean = new ResponseBean();
99
+
100
+        QueryWrapper<Activity> activityQueryWrapper = new QueryWrapper<>();
101
+        activityQueryWrapper.eq("activity_id", activityId);
102
+        Activity activity = activityMapper.selectOne(activityQueryWrapper);
103
+        if (null == activity) {
104
+            responseBean.addError("活动不存在!");
105
+            return responseBean;
106
+        }
107
+
108
+        responseBean.addSuccess(activity);
109
+        return responseBean;
110
+    }
95 111
 }

+ 37
- 0
whole-estate/src/main/java/com/example/wholeestate/service/impl/BuildingServiceImpl.java Vedi File

@@ -93,6 +93,34 @@ public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> i
93 93
         return response;
94 94
     }
95 95
 
96
+    @Override
97
+    public ResponseBean buildingAllSelectId(String id) {
98
+        ResponseBean response= new ResponseBean();
99
+        QueryWrapper<Building> buildingtWrapper = new QueryWrapper<>();
100
+        buildingtWrapper.lambda().gt(Building::getStatus,-1);
101
+        buildingtWrapper.lambda().eq(Building::getBuildingId,id);
102
+        Building building= buildingMapper.selectOne(buildingtWrapper);
103
+        //查询当前图片
104
+        QueryWrapper<BuildingImg> BuildingImgQueryWrapper = new QueryWrapper<>();
105
+        BuildingImgQueryWrapper.eq("building_id", id);
106
+        BuildingImgQueryWrapper.eq("img_type", "banner");
107
+        List<BuildingImg> buildingImg= buildingImgMapper.selectList(BuildingImgQueryWrapper);
108
+        building.setBuildingImg(buildingImg);
109
+        // 查询户型
110
+        QueryWrapper<BuildingApartment> AppointmentQueryWrapper = new QueryWrapper<>();
111
+        AppointmentQueryWrapper.eq("building_id", id);
112
+        AppointmentQueryWrapper.eq("status", 1);
113
+        List<BuildingApartment> appoint= buildingApartmentMapper.selectList(AppointmentQueryWrapper);
114
+
115
+        for (BuildingApartment apar:appoint) {
116
+            List<BuildingImg> imgs = buildingImgMapper.getBuildingImgByApartment(apar.getApartmentId());
117
+            apar.setBuildingImgList(imgs);
118
+        }
119
+        building.setBuildingApartment(appoint);
120
+        response.addSuccess(building);
121
+        return response;
122
+    }
123
+
96 124
     @Override
97 125
     public ResponseBean buildingUpdate(String parameter) {
98 126
         ResponseBean response= new ResponseBean();
@@ -389,6 +417,15 @@ public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> i
389 417
         QueryWrapper<Building> buildingQueryWrapper = new QueryWrapper<>();
390 418
         buildingQueryWrapper.eq("status", 1);
391 419
         List<Building> buildingList = buildingMapper.selectList(buildingQueryWrapper);
420
+
421
+        for (Building build:buildingList) {
422
+            QueryWrapper<BuildingImg> BuildingImgQueryWrapper = new QueryWrapper<>();
423
+            BuildingImgQueryWrapper.eq("building_id", build.getBuildingId());
424
+            BuildingImgQueryWrapper.eq("img_type", "banner");
425
+            List<BuildingImg> buildingImg = buildingImgMapper.selectList(BuildingImgQueryWrapper);
426
+            build.setBuildingImg(buildingImg);
427
+        }
428
+
392 429
         responseBean.addSuccess(buildingList);
393 430
 
394 431
         return responseBean;

+ 43
- 2
whole-estate/src/main/java/com/example/wholeestate/service/impl/CustomerServiceImpl.java Vedi File

@@ -13,6 +13,8 @@ import com.example.wholeestate.dao.CustomerMapper;
13 13
 
14 14
 import com.example.wholeestate.model.Customer;
15 15
 import com.example.wholeestate.service.ICustomerService;
16
+import com.example.wholeestate.utils.BeanTools;
17
+import com.example.wholeestate.wx.mini.IWxMini;
16 18
 import org.apache.http.HttpStatus;
17 19
 import org.springframework.beans.factory.annotation.Autowired;
18 20
 import org.springframework.stereotype.Service;
@@ -36,6 +38,9 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
36 38
     @Autowired
37 39
     private CustomerMapper customerMapper;
38 40
 
41
+    @Autowired
42
+    private IWxMini iWxMini;
43
+
39 44
     private IdGen idGen = IdGen.get();
40 45
 
41 46
     @Override
@@ -74,9 +79,20 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
74 79
         Customer customer = JSONObject.parseObject(parameter, Customer.class);
75 80
         customer.setCreateDate(LocalDateTime.now());
76 81
         customer.setStatus(1);
82
+        customer.setHasReg(1);
77 83
 
78
-        customer.setCustomerId(idGen.nextId()+"");
79
-        customerMapper.insert(customer);
84
+        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
85
+        queryWrapper.eq("openid", customer.getOpenid());
86
+        Customer selectOne = customerMapper.selectOne(queryWrapper);
87
+        if (null == selectOne) {
88
+            responseBean.addError("用户不存在!");
89
+            return responseBean;
90
+        }
91
+
92
+        BeanTools.copyProperties(customer, selectOne);
93
+
94
+        customerMapper.update(selectOne, queryWrapper);
95
+        responseBean.addSuccess("操作成功!");
80 96
         return responseBean;
81 97
     }
82 98
 
@@ -95,6 +111,31 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
95 111
         return responseBean;
96 112
     }
97 113
 
114
+    @Override
115
+    public ResponseBean wxOpenid(String code) {
116
+        ResponseBean responseBean = new ResponseBean();
117
+        String openid = iWxMini.getOpenid(code);
118
+
119
+        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
120
+        queryWrapper.eq("openid", openid);
121
+        Customer customer = customerMapper.selectOne(queryWrapper);
122
+        if (null != customer) {
123
+            responseBean.addSuccess(customer);
124
+            return responseBean;
125
+        }
126
+
127
+        customer = new Customer();
128
+        customer.setCustomerId(idGen.nextId() + "");
129
+        customer.setCreateDate(LocalDateTime.now());
130
+        customer.setOpenid(openid);
131
+        customer.setHasReg(0);
132
+
133
+        customerMapper.insert(customer);
134
+
135
+        responseBean.addSuccess(customer);
136
+        return responseBean;
137
+    }
138
+
98 139
     @Override
99 140
     public ResponseBean updateCustomer(String parameter) {
100 141
         ResponseBean responseBean = new ResponseBean();

+ 137
- 0
whole-estate/src/main/java/com/example/wholeestate/utils/BeanTools.java Vedi File

@@ -0,0 +1,137 @@
1
+package com.example.wholeestate.utils;
2
+
3
+import jodd.bean.BeanCopy;
4
+import jodd.typeconverter.TypeConverterManager;
5
+import org.apache.commons.collections.BeanMap;
6
+import org.springframework.beans.BeanUtils;
7
+import org.springframework.beans.BeanWrapper;
8
+import org.springframework.beans.BeanWrapperImpl;
9
+
10
+import java.beans.PropertyDescriptor;
11
+import java.lang.reflect.Method;
12
+import java.util.*;
13
+
14
+@SuppressWarnings("deprecation")
15
+public final class BeanTools {
16
+
17
+    private static Map<String, Object> toBeanMethodMap = new HashMap<String, Object>();
18
+
19
+    /**
20
+     * <pre>
21
+     * 功能:实现BEAN的属性对拷
22
+     * 创建人:JokenWang
23
+     * </pre>
24
+     *
25
+     * @param fromBean        待转换的源bean
26
+     * @param toBeanClassName 转换成目标bean的名称 形如:ItemSeries.class.getName()
27
+     * @return 目标BEAN类
28
+     */
29
+    public static <T> T convertBean(Object fromBean, Class<T> toBeanClassName) {
30
+        T toBean = null;
31
+        try {
32
+            toBean = getBeanInstance(toBeanClassName.getName());
33
+            return convertBean(fromBean, toBean);
34
+        } catch (Exception e) {
35
+            e.printStackTrace();
36
+        }
37
+        return toBean;
38
+    }
39
+
40
+    private static <T> T convertBean(Object fromBean, T toBean) {
41
+        TypeConverterManager.register(String.class, new StringConverter());
42
+        BeanCopy.beans(fromBean, toBean).copy();
43
+        return toBean;
44
+    }
45
+
46
+    public static Method getDeclaredMethod(Object object, String methodName, Class<?>... parameterTypes) {
47
+        Method method;
48
+        for (Class<?> clazz = object.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
49
+            try {
50
+                method = clazz.getDeclaredMethod(methodName, parameterTypes);
51
+                return method;
52
+            } catch (Exception ignored) {
53
+
54
+            }
55
+        }
56
+        return null;
57
+    }
58
+
59
+    @SuppressWarnings("unchecked")
60
+    public static <T> T getBeanInstance(String clazzName)
61
+            throws InstantiationException, IllegalAccessException, ClassNotFoundException {
62
+
63
+        return (T) Class.forName(clazzName).newInstance();
64
+    }
65
+
66
+    public static Map<String, Object> toBeanMethodMap(String toBean)
67
+            throws InstantiationException, IllegalAccessException, ClassNotFoundException {
68
+
69
+        Class<?> toBeanClazz = getBeanInstance(toBean).getClass();
70
+        Method[] toBeanMethods = toBeanClazz.getDeclaredMethods();
71
+        if (!toBeanClazz.isInstance(Object.class))// 非超类Object
72
+        {
73
+            for (Method method : toBeanMethods) {
74
+                String methodName = method.getName();
75
+                toBeanMethodMap.put(methodName, method);
76
+            }
77
+
78
+            Class<?> toBeanSuperclazz = toBeanClazz.getSuperclass();// 获取父类
79
+            toBeanMethodMap(toBeanSuperclazz.getName());
80
+        }
81
+
82
+        return toBeanMethodMap;
83
+    }
84
+
85
+    public static Map<String, Object> toMap(Object object) {
86
+        Map<String, Object> map = new HashMap<String, Object>();
87
+
88
+        if (object == null) {
89
+            return map;
90
+        }
91
+
92
+        BeanMap beanMap;
93
+        beanMap = new BeanMap(object);
94
+        @SuppressWarnings("unchecked")
95
+        Iterator<String> it = beanMap.keyIterator();
96
+        while (it.hasNext()) {
97
+            String name = it.next();
98
+            Object value = beanMap.get(name);
99
+            // 转换时会将类名也转换成属性,此处去掉
100
+            if (value != null && !name.equals("class")) {
101
+                map.put(name, value);
102
+            }
103
+        }
104
+
105
+        return map;
106
+    }
107
+
108
+    public static Map<String, Object> toMap(Object... objs) {
109
+        Map<String, Object> map = new HashMap<>();
110
+        for (Object object : objs) {
111
+            if (object != null) {
112
+                map.putAll(toMap(object));
113
+            }
114
+        }
115
+        return map;
116
+    }
117
+
118
+    public static String[] getNullPropertyNames (Object source) {
119
+        final BeanWrapper src = new BeanWrapperImpl(source);
120
+        PropertyDescriptor[] pds = src.getPropertyDescriptors();
121
+
122
+        Set<String> emptyNames = new HashSet<String>();
123
+        for(PropertyDescriptor pd : pds) {
124
+            Object srcValue = src.getPropertyValue(pd.getName());
125
+            if (srcValue == null) {
126
+                emptyNames.add(pd.getName());
127
+            }
128
+        }
129
+        String[] result = new String[emptyNames.size()];
130
+        return emptyNames.toArray(result);
131
+    }
132
+
133
+    public static void copyProperties(Object src, Object target) {
134
+        BeanUtils.copyProperties(src, target, getNullPropertyNames(src));
135
+    }
136
+
137
+}

+ 72
- 0
whole-estate/src/main/java/com/example/wholeestate/utils/StringConverter.java Vedi File

@@ -0,0 +1,72 @@
1
+package com.example.wholeestate.utils;
2
+
3
+import jodd.typeconverter.TypeConversionException;
4
+import jodd.typeconverter.TypeConverter;
5
+import jodd.util.ArraysUtil;
6
+
7
+import java.sql.Clob;
8
+import java.sql.SQLException;
9
+import java.util.Date;
10
+
11
+public class StringConverter implements TypeConverter<String> {
12
+
13
+    public String convert(Object value) {
14
+        if (value == null) {
15
+            return null;
16
+        }
17
+
18
+        if (value instanceof CharSequence) { // for speed
19
+            return value.toString();
20
+        }
21
+        Class<?> type = value.getClass();
22
+        if (type == Class.class) {
23
+            return ((Class<?>) value).getName();
24
+        }
25
+        if (type.isArray()) {
26
+            if (type == char[].class) {
27
+                char[] charArray = (char[]) value;
28
+                return new String(charArray);
29
+            }
30
+            if (type == int[].class) {
31
+                return ArraysUtil.toString((int[]) value);
32
+            }
33
+            if (type == long[].class) {
34
+                return ArraysUtil.toString((long[]) value);
35
+            }
36
+            if (type == byte[].class) {
37
+                return ArraysUtil.toString((byte[]) value);
38
+            }
39
+            if (type == float[].class) {
40
+                return ArraysUtil.toString((float[]) value);
41
+            }
42
+            if (type == double[].class) {
43
+                return ArraysUtil.toString((double[]) value);
44
+            }
45
+            if (type == short[].class) {
46
+                return ArraysUtil.toString((short[]) value);
47
+            }
48
+            if (type == boolean[].class) {
49
+                return ArraysUtil.toString((boolean[]) value);
50
+            }
51
+            return ArraysUtil.toString((Object[]) value);
52
+        }
53
+        if (value instanceof Clob) {
54
+            Clob clob = (Clob) value;
55
+            try {
56
+                long length = clob.length();
57
+                if (length > Integer.MAX_VALUE) {
58
+                    throw new TypeConversionException("Clob is too big.");
59
+                }
60
+                return clob.getSubString(1, (int) length);
61
+            } catch (SQLException sex) {
62
+                throw new TypeConversionException(value, sex);
63
+            }
64
+        }
65
+        if (value instanceof Date) {
66
+            java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
67
+            return format1.format(value);
68
+        }
69
+
70
+        return value.toString();
71
+    }
72
+}

+ 22
- 0
whole-estate/src/main/java/com/example/wholeestate/wx/WxBase.java Vedi File

@@ -0,0 +1,22 @@
1
+package com.example.wholeestate.wx;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.example.wholeestate.exception.WholeEstateException;
5
+
6
+/**
7
+ * @author weiximei
8
+ */
9
+public class WxBase {
10
+
11
+    protected void wxMiniErrCode(JSONObject jsonObject) {
12
+
13
+        Integer errcode = jsonObject.getInteger("errcode");
14
+
15
+        if (null != errcode && errcode != 0) {
16
+            String errmsg = jsonObject.getString("errmsg");
17
+            throw new WholeEstateException(errmsg);
18
+        }
19
+
20
+    }
21
+
22
+}

+ 22
- 0
whole-estate/src/main/java/com/example/wholeestate/wx/WxConstant.java Vedi File

@@ -0,0 +1,22 @@
1
+package com.example.wholeestate.wx;
2
+
3
+/**
4
+ * 定义 微信相关 URL
5
+ * @author weiximei
6
+ */
7
+public class WxConstant {
8
+
9
+    // -------------   微信小程序 start  ---------------------
10
+
11
+    /**
12
+     * 根据 code 获取 openid, session_key, unionid 等
13
+     *
14
+     * 请求参数在发起请求的时候拼装
15
+     *
16
+     */
17
+    public static final String  WX_MINI_CODE2_SESSION = "https://api.weixin.qq.com/sns/jscode2session";
18
+
19
+
20
+    // ------------  微信小程序 end --------------------------
21
+
22
+}

+ 26
- 0
whole-estate/src/main/java/com/example/wholeestate/wx/WxMiniProperties.java Vedi File

@@ -0,0 +1,26 @@
1
+package com.example.wholeestate.wx;
2
+
3
+import lombok.Data;
4
+import org.springframework.boot.context.properties.ConfigurationProperties;
5
+import org.springframework.stereotype.Component;
6
+
7
+/**
8
+ * 微信小程序 参数
9
+ * @author weiximei
10
+ */
11
+@Data
12
+@Component
13
+@ConfigurationProperties(prefix = "wx.mini")
14
+public class WxMiniProperties {
15
+
16
+    /**
17
+     * 小程序 appId
18
+     */
19
+    private String appid;
20
+
21
+    /**
22
+     * 小程序 appSecret
23
+     */
24
+    private String secret;
25
+
26
+}

+ 20
- 0
whole-estate/src/main/java/com/example/wholeestate/wx/mini/IWxMini.java Vedi File

@@ -0,0 +1,20 @@
1
+package com.example.wholeestate.wx.mini;
2
+
3
+/**
4
+ * 微信小程序 接口
5
+ * @author weiximei
6
+ */
7
+public interface IWxMini {
8
+
9
+    /**
10
+     * 根据 code 获取
11
+     *
12
+     *      openid
13
+     *
14
+     * @param code
15
+     * @return
16
+     */
17
+    String getOpenid(String code);
18
+
19
+
20
+}

+ 56
- 0
whole-estate/src/main/java/com/example/wholeestate/wx/mini/impl/WxMiniImpl.java Vedi File

@@ -0,0 +1,56 @@
1
+package com.example.wholeestate.wx.mini.impl;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.example.wholeestate.common.http.OkHttpRequestUtils;
5
+import com.example.wholeestate.wx.WxBase;
6
+import com.example.wholeestate.wx.WxConstant;
7
+import com.example.wholeestate.wx.WxMiniProperties;
8
+import com.example.wholeestate.wx.mini.IWxMini;
9
+import com.google.common.collect.Maps;
10
+import lombok.extern.slf4j.Slf4j;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.stereotype.Service;
13
+
14
+import java.util.Map;
15
+
16
+/**
17
+ * 微信 小程序实现
18
+ * @author weiximei
19
+ */
20
+@Service
21
+@Slf4j
22
+public class WxMiniImpl extends WxBase implements IWxMini {
23
+
24
+    @Autowired
25
+    private WxMiniProperties wxMiniProperties;
26
+
27
+    @Override
28
+    public String getOpenid(String code) {
29
+
30
+        Map<String, Object> query = Maps.newHashMap();
31
+        query.put("appid", wxMiniProperties.getAppid());
32
+        query.put("secret",wxMiniProperties.getSecret());
33
+        query.put("js_code", code);
34
+        query.put("grant_type","authorization_code");
35
+
36
+        String result = null;
37
+        try {
38
+            result = OkHttpRequestUtils.doGet(WxConstant.WX_MINI_CODE2_SESSION, query);
39
+            log.info("获取微信小程序 openid 数据:{}", result);
40
+        } catch (Exception e) {
41
+            e.printStackTrace();
42
+            log.error("微信小程序--获取 openid 失败!", e);
43
+        }
44
+
45
+        JSONObject jsonObject = JSONObject.parseObject(result);
46
+
47
+        // 校验 errcode
48
+        wxMiniErrCode(jsonObject);
49
+
50
+        // 开始获取 openid
51
+        String openid = jsonObject.getString("openid");
52
+        return openid;
53
+    }
54
+
55
+
56
+}

+ 5
- 0
whole-estate/src/main/resources/application.yml Vedi File

@@ -29,4 +29,9 @@ logging:
29 29
   level:
30 30
     com.example.wholeestate.dao: debug
31 31
 
32
+# 微信配置
33
+wx:
34
+  mini:
35
+    appid: wx8d70a491c45b400e
36
+    secret: 7f995c77ef093410a3fe9909229796a5
32 37
 

+ 4
- 1
whole-estate/src/main/resources/mapper/BuildingImgMapper.xml Vedi File

@@ -1,5 +1,8 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 <mapper namespace="com.example.wholeestate.dao.BuildingImgMapper">
4
-
4
+    <select id="getBuildingImgByApartment" resultType="com.example.wholeestate.model.BuildingImg" >
5
+      select a.* from ta_building_img a inner join ta_apartment_img b on a.img_id = b.img_id
6
+      where a.status = 1 and b.status=1 and b.apartment_id = #{id}
7
+    </select>
5 8
 </mapper>