Your Name 4 vuotta sitten
vanhempi
commit
646c5ff38f

+ 7
- 0
pom.xml Näytä tiedosto

130
 			<version>3.0.0</version>
130
 			<version>3.0.0</version>
131
 		</dependency>
131
 		</dependency>
132
 		<!--swagger end-->
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
 	</dependencies>
140
 	</dependencies>
134
 
141
 
135
 	<profiles>
142
 	<profiles>

+ 4
- 2
src/main/java/com/shigongli/common/OSSUtils.java Näytä tiedosto

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

+ 53
- 0
src/main/java/com/shigongli/common/ScreenShotUtil.java Näytä tiedosto

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 Näytä tiedosto

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 Näytä tiedosto

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

+ 60
- 7
src/main/java/com/shigongli/controller/TaHouseController.java Näytä tiedosto

5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.shigongli.common.BaseController;
6
 import com.shigongli.common.BaseController;
7
 import com.shigongli.common.ResponseBean;
7
 import com.shigongli.common.ResponseBean;
8
+import com.shigongli.common.ScreenShotUtil;
8
 import com.shigongli.common.StringUtils;
9
 import com.shigongli.common.StringUtils;
9
 import com.shigongli.constants.StatusConstant;
10
 import com.shigongli.constants.StatusConstant;
10
 import com.shigongli.entity.TaPerson;
11
 import com.shigongli.entity.TaPerson;
16
 import org.slf4j.Logger;
17
 import org.slf4j.Logger;
17
 import org.slf4j.LoggerFactory;
18
 import org.slf4j.LoggerFactory;
18
 import org.springframework.beans.factory.annotation.Autowired;
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
 import com.shigongli.service.ITaHouseService;
22
 import com.shigongli.service.ITaHouseService;
25
 import com.shigongli.entity.TaHouse;
23
 import com.shigongli.entity.TaHouse;
26
-import org.springframework.web.bind.annotation.RestController;
27
 
24
 
28
 import javax.servlet.http.HttpServletRequest;
25
 import javax.servlet.http.HttpServletRequest;
26
+import java.util.HashMap;
29
 import java.util.List;
27
 import java.util.List;
28
+import java.util.Map;
30
 
29
 
31
 /**
30
 /**
32
  * <p>
31
  * <p>
44
 
43
 
45
     private final Logger logger = LoggerFactory.getLogger(TaHouseController.class);
44
     private final Logger logger = LoggerFactory.getLogger(TaHouseController.class);
46
 
45
 
46
+    @Value("weather-shot.url")
47
+    String weatherURL;
48
+
47
     @Autowired
49
     @Autowired
48
     public ITaHouseService iTaHouseService;
50
     public ITaHouseService iTaHouseService;
49
 
51
 
50
     @Autowired
52
     @Autowired
51
     ITaShopKeeperService iTaShopKeeperService;
53
     ITaShopKeeperService iTaShopKeeperService;
52
 
54
 
55
+    @Autowired
56
+    ScreenShotUtil screenShotUtil;
57
+
53
 //
58
 //
54
 //    /**
59
 //    /**
55
 //     * 分页查询列表
60
 //     * 分页查询列表
179
      */
184
      */
180
     @RequestMapping(value="/ma/taHouse/{id}",method= RequestMethod.GET)
185
     @RequestMapping(value="/ma/taHouse/{id}",method= RequestMethod.GET)
181
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
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
         return ResponseBean.success(iTaHouseService.getById(id));
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 Näytä tiedosto

111
      * 根据id查询对象
111
      * 根据id查询对象
112
      * @param id  实体ID
112
      * @param id  实体ID
113
      */
113
      */
114
-    @RequestMapping(value="/taHouseOrder/{id}",method= RequestMethod.GET)
114
+    @RequestMapping(value="/ma/taHouseOrder/{id}",method= RequestMethod.GET)
115
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
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
         return ResponseBean.success(iTaHouseOrderService.getById(id));
117
         return ResponseBean.success(iTaHouseOrderService.getById(id));
118
     }
118
     }
119
 }
119
 }

+ 19
- 2
src/main/java/com/shigongli/controller/TaHouseSettingController.java Näytä tiedosto

86
             return ResponseBean.error("填写选择房源", ResponseBean.ERROR_MISSING_PARAMS);
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
         if (iTaHouseSettingService.save(taHouseSetting)){
94
         if (iTaHouseSettingService.save(taHouseSetting)){
90
 
95
 
91
             // 生成订单
96
             // 生成订单
124
      */
129
      */
125
     @RequestMapping(value="/taHouseSetting/{id}",method= RequestMethod.PUT)
130
     @RequestMapping(value="/taHouseSetting/{id}",method= RequestMethod.PUT)
126
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
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
         if (iTaHouseSettingService.updateById(taHouseSetting)){
135
         if (iTaHouseSettingService.updateById(taHouseSetting)){
131
             return ResponseBean.success(iTaHouseSettingService.getById(id));
136
             return ResponseBean.success(iTaHouseSettingService.getById(id));
143
     public ResponseBean taHouseSettingGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
148
     public ResponseBean taHouseSettingGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
144
         return ResponseBean.success(iTaHouseSettingService.getById(id));
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 Näytä tiedosto

3
 import com.shigongli.entity.TaHouseSetting;
3
 import com.shigongli.entity.TaHouseSetting;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
 import org.apache.ibatis.annotations.Mapper;
5
 import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
6
 
7
 
7
 /**
8
 /**
8
  * <p>
9
  * <p>
15
 @Mapper
16
 @Mapper
16
 public interface TaHouseSettingMapper extends BaseMapper<TaHouseSetting> {
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 Näytä tiedosto

13
  */
13
  */
14
 public interface ITaHouseSettingService extends IService<TaHouseSetting> {
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 Näytä tiedosto

4
 import com.shigongli.mapper.TaHouseSettingMapper;
4
 import com.shigongli.mapper.TaHouseSettingMapper;
5
 import com.shigongli.service.ITaHouseSettingService;
5
 import com.shigongli.service.ITaHouseSettingService;
6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.beans.factory.annotation.Autowired;
7
 import org.springframework.stereotype.Service;
8
 import org.springframework.stereotype.Service;
8
 
9
 
9
 /**
10
 /**
17
 @Service
18
 @Service
18
 public class TaHouseSettingServiceImpl extends ServiceImpl<TaHouseSettingMapper, TaHouseSetting> implements ITaHouseSettingService {
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 Näytä tiedosto

18
   level:
18
   level:
19
     root: info
19
     root: info
20
     springfox: info
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 Näytä tiedosto

52
     token: yansenisahero
52
     token: yansenisahero
53
     aesKey: oz3KPVpLL1yWPWUKEv1JLIE23yB8wIPA9OkdhKKK0UB
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
 spring:
69
 spring:
59
     name: demo
71
     name: demo
60
   profiles:
72
   profiles:
61
     active: @profileActive@
73
     active: @profileActive@
62
-
63
-

+ 12
- 0
src/main/resources/mapper/TaHouseSettingMapper.xml Näytä tiedosto

2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
 <mapper namespace="com.shigongli.mapper.TaHouseSettingMapper">
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
 </mapper>
17
 </mapper>