|
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
5
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
6
|
import com.shigongli.common.BaseController;
|
7
|
7
|
import com.shigongli.common.ResponseBean;
|
|
8
|
+import com.shigongli.common.ScreenShotUtil;
|
8
|
9
|
import com.shigongli.common.StringUtils;
|
9
|
10
|
import com.shigongli.constants.StatusConstant;
|
10
|
11
|
import com.shigongli.entity.TaPerson;
|
|
@@ -16,17 +17,15 @@ import io.swagger.annotations.ApiParam;
|
16
|
17
|
import org.slf4j.Logger;
|
17
|
18
|
import org.slf4j.LoggerFactory;
|
18
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
19
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
20
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
21
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
22
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
23
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
20
|
+import org.springframework.beans.factory.annotation.Value;
|
|
21
|
+import org.springframework.web.bind.annotation.*;
|
24
|
22
|
import com.shigongli.service.ITaHouseService;
|
25
|
23
|
import com.shigongli.entity.TaHouse;
|
26
|
|
-import org.springframework.web.bind.annotation.RestController;
|
27
|
24
|
|
28
|
25
|
import javax.servlet.http.HttpServletRequest;
|
|
26
|
+import java.util.HashMap;
|
29
|
27
|
import java.util.List;
|
|
28
|
+import java.util.Map;
|
30
|
29
|
|
31
|
30
|
/**
|
32
|
31
|
* <p>
|
|
@@ -44,12 +43,18 @@ public class TaHouseController extends BaseController {
|
44
|
43
|
|
45
|
44
|
private final Logger logger = LoggerFactory.getLogger(TaHouseController.class);
|
46
|
45
|
|
|
46
|
+ @Value("weather-shot.url")
|
|
47
|
+ String weatherURL;
|
|
48
|
+
|
47
|
49
|
@Autowired
|
48
|
50
|
public ITaHouseService iTaHouseService;
|
49
|
51
|
|
50
|
52
|
@Autowired
|
51
|
53
|
ITaShopKeeperService iTaShopKeeperService;
|
52
|
54
|
|
|
55
|
+ @Autowired
|
|
56
|
+ ScreenShotUtil screenShotUtil;
|
|
57
|
+
|
53
|
58
|
//
|
54
|
59
|
// /**
|
55
|
60
|
// * 分页查询列表
|
|
@@ -179,8 +184,56 @@ public class TaHouseController extends BaseController {
|
179
|
184
|
*/
|
180
|
185
|
@RequestMapping(value="/ma/taHouse/{id}",method= RequestMethod.GET)
|
181
|
186
|
@ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
|
182
|
|
- public ResponseBean houseDetail(@ApiParam("对象ID") @PathVariable String id) throws Exception{
|
|
187
|
+ public ResponseBean houseDetail(@ApiParam("房源ID") @PathVariable String id) throws Exception{
|
183
|
188
|
return ResponseBean.success(iTaHouseService.getById(id));
|
184
|
189
|
}
|
185
|
190
|
|
|
191
|
+ @GetMapping("/ma/taHouse/{id}/share")
|
|
192
|
+ @ApiOperation(value="获取分享内容", notes = "获取分享内容", httpMethod = "GET", response = ResponseBean.class)
|
|
193
|
+ public ResponseBean getShareImage(@ApiParam("房源ID") @PathVariable String id) {
|
|
194
|
+ TaHouse taHouse = iTaHouseService.getById(id);
|
|
195
|
+ if (taHouse == null || StatusConstant.DELETE.equals(taHouse.getStatus())) {
|
|
196
|
+ return ResponseBean.error("房源不存在", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ String city = getCity(taHouse.getAddress());
|
|
200
|
+ if (StringUtils.isEmpty(city)) {
|
|
201
|
+ city = "南京";
|
|
202
|
+ }
|
|
203
|
+
|
|
204
|
+ String shot = null;
|
|
205
|
+ try {
|
|
206
|
+ shot = screenShotUtil.shot(String.format(weatherURL, city));
|
|
207
|
+ } catch (Exception e) {
|
|
208
|
+ e.printStackTrace();
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ Map<String, Object> res = new HashMap<>();
|
|
212
|
+ res.put("image", shot);
|
|
213
|
+ return ResponseBean.success(res);
|
|
214
|
+ }
|
|
215
|
+
|
|
216
|
+ private String getCity (String address) {
|
|
217
|
+ if (StringUtils.isEmpty(address)) {
|
|
218
|
+ return null;
|
|
219
|
+ }
|
|
220
|
+
|
|
221
|
+ String[] parts = address.split("市");
|
|
222
|
+ String city = parts[0];
|
|
223
|
+ // 省
|
|
224
|
+ if (city.contains("省")) {
|
|
225
|
+ return city.split("省")[1];
|
|
226
|
+ }
|
|
227
|
+ // 自治区
|
|
228
|
+ if (city.contains("区")) {
|
|
229
|
+ return city.split("区")[1];
|
|
230
|
+ }
|
|
231
|
+ // 直辖市
|
|
232
|
+ if (city.contains("市")) {
|
|
233
|
+ return city.split("市")[1];
|
|
234
|
+ }
|
|
235
|
+
|
|
236
|
+ return city;
|
|
237
|
+ }
|
|
238
|
+
|
186
|
239
|
}
|