Your Name 4 年之前
父節點
當前提交
646c5ff38f

+ 7
- 0
pom.xml 查看文件

@@ -130,6 +130,13 @@
130 130
 			<version>3.0.0</version>
131 131
 		</dependency>
132 132
 		<!--swagger end-->
133
+
134
+		<!-- selenium-java -->
135
+		<dependency>
136
+			<groupId>org.seleniumhq.selenium</groupId>
137
+			<artifactId>selenium-java</artifactId>
138
+			<version>3.4.0</version>
139
+		</dependency>
133 140
 	</dependencies>
134 141
 
135 142
 	<profiles>

+ 4
- 2
src/main/java/com/shigongli/common/OSSUtils.java 查看文件

@@ -11,6 +11,8 @@ import java.io.*;
11 11
 @Component
12 12
 public class OSSUtils {
13 13
 
14
+    public static final String defaultDir = "/shigongli/images/";
15
+
14 16
     @Autowired
15 17
     AliyunConfig aliyunConfig;
16 18
 
@@ -23,7 +25,7 @@ public class OSSUtils {
23 25
     public String putObject(MultipartFile mf, String ... toDirs) throws IOException {
24 26
         String fName = formatFileName(mf.getOriginalFilename());
25 27
         String preFix = String.valueOf(System.currentTimeMillis());
26
-        String toDir = "/";
28
+        String toDir = defaultDir;
27 29
         if (null != toDirs && toDirs.length > 0) {
28 30
             toDir = toDirs[0];
29 31
         }
@@ -36,7 +38,7 @@ public class OSSUtils {
36 38
     public String putObject(File f, String ... toDirs) throws FileNotFoundException {
37 39
         String fName = formatFileName(f.getName());
38 40
         String preFix = String.valueOf(System.currentTimeMillis());
39
-        String toDir = "/";
41
+        String toDir = defaultDir;
40 42
         if (null != toDirs && toDirs.length > 0) {
41 43
             toDir = toDirs[0];
42 44
         }

+ 53
- 0
src/main/java/com/shigongli/common/ScreenShotUtil.java 查看文件

@@ -0,0 +1,53 @@
1
+package com.shigongli.common;
2
+
3
+import com.shigongli.config.ScreenShotConfig;
4
+import org.openqa.selenium.OutputType;
5
+import org.openqa.selenium.TakesScreenshot;
6
+import org.openqa.selenium.WebDriver;
7
+import org.openqa.selenium.chrome.ChromeDriver;
8
+import org.openqa.selenium.chrome.ChromeOptions;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.stereotype.Component;
11
+
12
+import java.io.File;
13
+
14
+@Component
15
+public class ScreenShotUtil {
16
+    @Autowired
17
+    OSSUtils ossUtils;
18
+
19
+    @Autowired
20
+    ScreenShotConfig config;
21
+
22
+    public String shot(String url) throws Exception {
23
+        //驱动地址
24
+        System.setProperty("webdriver.chrome.driver", config.getDriver());
25
+
26
+        WebDriver webDriver = null;
27
+        ChromeOptions options=new ChromeOptions();
28
+        //设置 chrome 的无头模式
29
+        options.addArguments("--headless");
30
+        options.addArguments("--disable-gpu");
31
+        options.addArguments("--no-sandbox");
32
+        options.addArguments("--disable-dev-shm-usage");
33
+        options.addArguments("--start-maximized");
34
+        options.addArguments(String.format("--window-size=%s,%s", config.getWidth(), config.getHeight()));
35
+        //启动一个 chrome 实例
36
+        webDriver = new ChromeDriver(options);
37
+
38
+        //访问网址
39
+        webDriver.get(url);
40
+        Thread.sleep(config.getWait());
41
+
42
+        //截取全屏
43
+        File f  = ((TakesScreenshot)webDriver).getScreenshotAs(OutputType.FILE);
44
+
45
+        // 存入 oss
46
+        String imageUrl = ossUtils.putObject(f);
47
+
48
+        //退出
49
+        webDriver.quit();
50
+
51
+        return imageUrl;
52
+    }
53
+}

+ 16
- 0
src/main/java/com/shigongli/config/ScreenShotConfig.java 查看文件

@@ -0,0 +1,16 @@
1
+package com.shigongli.config;
2
+
3
+
4
+import lombok.Data;
5
+import org.springframework.boot.context.properties.ConfigurationProperties;
6
+import org.springframework.stereotype.Component;
7
+
8
+@Data
9
+@Component
10
+@ConfigurationProperties(prefix = "screen-shot")
11
+public class ScreenShotConfig {
12
+    private String driver;
13
+    private Integer wait;
14
+    private String width;
15
+    private String height;
16
+}

+ 1
- 1
src/main/java/com/shigongli/controller/CommController.java 查看文件

@@ -31,7 +31,7 @@ public class CommController extends BaseController {
31 31
     @PostMapping("/{plat}/image")
32 32
     public ResponseBean uploadImage(@RequestParam("file") MultipartFile multipartFile) {
33 33
         try {
34
-            String img = ossUtils.putObject(multipartFile, "/shigongli/images/");
34
+            String img = ossUtils.putObject(multipartFile);
35 35
             return ResponseBean.success(img);
36 36
         } catch (IOException e) {
37 37
             return ResponseBean.error("上传图片失败: " + e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);

+ 60
- 7
src/main/java/com/shigongli/controller/TaHouseController.java 查看文件

@@ -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
 }

+ 2
- 2
src/main/java/com/shigongli/controller/TaHouseOrderController.java 查看文件

@@ -111,9 +111,9 @@ public class TaHouseOrderController extends BaseController {
111 111
      * 根据id查询对象
112 112
      * @param id  实体ID
113 113
      */
114
-    @RequestMapping(value="/taHouseOrder/{id}",method= RequestMethod.GET)
114
+    @RequestMapping(value="/ma/taHouseOrder/{id}",method= RequestMethod.GET)
115 115
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
-    public ResponseBean taHouseOrderGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
116
+    public ResponseBean taHouseOrderGet(@ApiParam("对象ID") @PathVariable String id) throws Exception{
117 117
         return ResponseBean.success(iTaHouseOrderService.getById(id));
118 118
     }
119 119
 }

+ 19
- 2
src/main/java/com/shigongli/controller/TaHouseSettingController.java 查看文件

@@ -86,6 +86,11 @@ public class TaHouseSettingController extends BaseController {
86 86
             return ResponseBean.error("填写选择房源", ResponseBean.ERROR_MISSING_PARAMS);
87 87
         }
88 88
 
89
+        // 如果是更新内容
90
+        if (!StringUtils.isEmpty(taHouseSetting.getSettingId())) {
91
+            return taHouseSettingUpdate(taHouseSetting.getSettingId(), taHouseSetting);
92
+        }
93
+
89 94
         if (iTaHouseSettingService.save(taHouseSetting)){
90 95
 
91 96
             // 生成订单
@@ -124,8 +129,8 @@ public class TaHouseSettingController extends BaseController {
124 129
      */
125 130
     @RequestMapping(value="/taHouseSetting/{id}",method= RequestMethod.PUT)
126 131
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
127
-    public ResponseBean taHouseSettingUpdate(@ApiParam("对象ID") @PathVariable Integer id,
128
-                                        @ApiParam("更新内容") @RequestBody TaHouseSetting taHouseSetting) throws Exception{
132
+    public ResponseBean taHouseSettingUpdate(@ApiParam("对象ID") @PathVariable String id,
133
+                                             @ApiParam("更新内容") @RequestBody TaHouseSetting taHouseSetting) throws Exception{
129 134
 
130 135
         if (iTaHouseSettingService.updateById(taHouseSetting)){
131 136
             return ResponseBean.success(iTaHouseSettingService.getById(id));
@@ -143,4 +148,16 @@ public class TaHouseSettingController extends BaseController {
143 148
     public ResponseBean taHouseSettingGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
144 149
         return ResponseBean.success(iTaHouseSettingService.getById(id));
145 150
     }
151
+
152
+
153
+    /**
154
+     * 根据房源查询最近的设置记录
155
+     * @param houseId  房源ID
156
+     */
157
+    @RequestMapping(value="/taHouseSetting/last",method= RequestMethod.GET)
158
+    @ApiOperation(value="根据房源查询最近的设置记录", notes = "根据房源查询最近的设置记录", httpMethod = "GET", response = ResponseBean.class)
159
+    public ResponseBean getTaHouseSettingLast(@ApiParam("房源ID") @RequestParam("houseId") String houseId) throws Exception{
160
+        TaHouseSetting taHouseSetting = iTaHouseSettingService.getLastByHouse(houseId);
161
+        return ResponseBean.success(taHouseSetting);
162
+    }
146 163
 }

+ 2
- 0
src/main/java/com/shigongli/mapper/TaHouseSettingMapper.java 查看文件

@@ -3,6 +3,7 @@ package com.shigongli.mapper;
3 3
 import com.shigongli.entity.TaHouseSetting;
4 4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
6 7
 
7 8
 /**
8 9
  * <p>
@@ -15,4 +16,5 @@ import org.apache.ibatis.annotations.Mapper;
15 16
 @Mapper
16 17
 public interface TaHouseSettingMapper extends BaseMapper<TaHouseSetting> {
17 18
 
19
+    TaHouseSetting getLastByHouse(@Param("houseId") String houseId);
18 20
 }

+ 1
- 0
src/main/java/com/shigongli/service/ITaHouseSettingService.java 查看文件

@@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 13
  */
14 14
 public interface ITaHouseSettingService extends IService<TaHouseSetting> {
15 15
 
16
+    TaHouseSetting getLastByHouse(String houseId);
16 17
 }

+ 8
- 0
src/main/java/com/shigongli/service/impl/TaHouseSettingServiceImpl.java 查看文件

@@ -4,6 +4,7 @@ import com.shigongli.entity.TaHouseSetting;
4 4
 import com.shigongli.mapper.TaHouseSettingMapper;
5 5
 import com.shigongli.service.ITaHouseSettingService;
6 6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.beans.factory.annotation.Autowired;
7 8
 import org.springframework.stereotype.Service;
8 9
 
9 10
 /**
@@ -17,4 +18,11 @@ import org.springframework.stereotype.Service;
17 18
 @Service
18 19
 public class TaHouseSettingServiceImpl extends ServiceImpl<TaHouseSettingMapper, TaHouseSetting> implements ITaHouseSettingService {
19 20
 
21
+    @Autowired
22
+    TaHouseSettingMapper taHouseSettingMapper;
23
+
24
+    @Override
25
+    public TaHouseSetting getLastByHouse(String houseId) {
26
+        return taHouseSettingMapper.getLastByHouse(houseId);
27
+    }
20 28
 }

+ 10
- 0
src/main/resources/application-dev.yml 查看文件

@@ -18,3 +18,13 @@ logging:
18 18
   level:
19 19
     root: info
20 20
     springfox: info
21
+
22
+
23
+###
24
+screen-shot:
25
+  # webdriver.chrome.driver
26
+  driver: E:/work/shigongli/lib/chromedriver.exe
27
+  # milliseconds
28
+  wait: 5000
29
+  width: '520'
30
+  height: '416'

+ 12
- 2
src/main/resources/application.yml 查看文件

@@ -52,6 +52,18 @@ weixin:
52 52
     token: yansenisahero
53 53
     aesKey: oz3KPVpLL1yWPWUKEv1JLIE23yB8wIPA9OkdhKKK0UB
54 54
 
55
+###
56
+screen-shot:
57
+  # webdriver.chrome.driver
58
+  driver: /yunpan/shigongli/service/lib/chromedriver
59
+  # milliseconds
60
+  wait: 3000
61
+  width: '520'
62
+  height: '416'
63
+
64
+# weather-shot
65
+weather-shot:
66
+  url: https://sgl.ycjcjy.com/weather.html?city=%s
55 67
 
56 68
 ###
57 69
 spring:
@@ -59,5 +71,3 @@ spring:
59 71
     name: demo
60 72
   profiles:
61 73
     active: @profileActive@
62
-
63
-

+ 12
- 0
src/main/resources/mapper/TaHouseSettingMapper.xml 查看文件

@@ -2,4 +2,16 @@
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.shigongli.mapper.TaHouseSettingMapper">
4 4
 
5
+    <select id="getLastByHouse" resultType="com.shigongli.entity.TaHouseSetting">
6
+        SELECT
7
+            *
8
+        FROM
9
+            ta_house_setting t
10
+        WHERE
11
+            t.house_id = #{houseId}
12
+            AND t.`status` = 1
13
+            AND t.start_date &lt;= DATE_FORMAT( now( ), '%Y-%m-%d' ) AND t.end_date &gt;= DATE_FORMAT( now( ), '%Y-%m-%d' )
14
+        ORDER BY t.create_date DESC
15
+        LIMIT 1
16
+    </select>
5 17
 </mapper>