Skip to content

Commit b6f7dfb

Browse files
committed
获取实例信息的同时判断该实例是否为用户所喜爱
1 parent c1fdf6d commit b6f7dfb

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

springboot-dubbo-api/src/main/java/com/lzq/api/pojo/Content.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public class Content implements Serializable {
6464
@TableField(value = "js_style")
6565
@JsonProperty("jsStyle")
6666
private String jsStyle;
67+
/**
68+
* 是否喜爱
69+
*/
70+
@TableField(exist = false)
71+
@JsonProperty("myFavorites")
72+
private Boolean myFavorites=false;
6773
/**
6874
* 创建时间
6975
*/

springboot-dubbo-api/src/main/java/com/lzq/api/service/ContentService.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,34 @@ public interface ContentService {
1111

1212
/**
1313
* 添加实例内容
14+
*
1415
* @param content
1516
* @return
1617
*/
17-
public Boolean addContent(Content content);
18+
Boolean addContent(Content content);
1819

1920
/**
2021
* 更新实例内容
22+
*
2123
* @param content
2224
* @return
2325
*/
24-
public Boolean updateContent(Content content);
26+
Boolean updateContent(Content content);
2527

2628
/**
2729
* 获取实例内容
30+
*
2831
* @param exampleId
2932
* @param username
3033
* @return
3134
*/
32-
public Content getContent(String exampleId,String username);
35+
Content getContent(String exampleId, String username);
3336

3437
/**
3538
* 删除实例内容
39+
*
3640
* @param exampleId 实例id
3741
* @return
3842
*/
39-
void deleteContent(String exampleId);
43+
void deleteContent(String exampleId);
4044
}

springboot-dubbo-web/src/main/java/com/lzq/web/controller/ContentController.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package com.lzq.web.controller;
22

3+
import com.auth0.jwt.JWT;
34
import com.lzq.api.pojo.Content;
45
import com.lzq.api.service.ContentService;
6+
import com.lzq.web.utils.JWTUtils;
57
import com.lzq.web.utils.ResultMapUtils;
68
import io.swagger.annotations.Api;
79
import io.swagger.annotations.ApiOperation;
810
import lombok.extern.slf4j.Slf4j;
11+
import org.apache.commons.lang.StringUtils;
912
import org.apache.dubbo.config.annotation.Reference;
13+
import org.springframework.beans.factory.annotation.Autowired;
14+
import org.springframework.data.redis.core.RedisTemplate;
1015
import org.springframework.web.bind.annotation.GetMapping;
1116
import org.springframework.web.bind.annotation.RequestMapping;
1217
import org.springframework.web.bind.annotation.RestController;
1318

19+
import javax.servlet.http.HttpServletRequest;
20+
import java.util.List;
1421
import java.util.Map;
1522

1623
/**
@@ -27,6 +34,9 @@ public class ContentController {
2734
@Reference
2835
private ContentService contentService;
2936

37+
@Autowired
38+
private RedisTemplate redisTemplate;
39+
3040
/**
3141
* 获取实例内容
3242
*
@@ -36,9 +46,19 @@ public class ContentController {
3646
*/
3747
@GetMapping("/getContent")
3848
@ApiOperation("获取实例内容")
39-
public Map<String, Object> getContent(String exampleId, String username) {
49+
public Map<String, Object> getContent(HttpServletRequest request, String exampleId, String username) {
4050
log.info("获取实例内容接口"+exampleId+"------"+username);
51+
String token = request.getHeader("token");
4152
Content content = contentService.getContent(exampleId, username);
53+
//当token不为空时用户已登录
54+
if (StringUtils.isNotBlank(token)){
55+
String s = JWTUtils.verify(token).getClaim("username").asString();
56+
List<Integer> favoriteslist = redisTemplate.opsForList().range(s + "fav", 0, -1);
57+
//判断改实例是否为用户的喜爱
58+
if (favoriteslist.contains(content.getExampleId())){
59+
content.setMyFavorites(true);
60+
}
61+
}
4262
return ResultMapUtils.ResultMap(true, 0, content);
4363
}
4464
}

springboot-dubbo-web/src/main/java/com/lzq/web/utils/ExampleUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public static String screenshot(String username, String filename) throws IOExcep
8383
options.setHeadless(true);
8484
ChromeDriver broswer = new ChromeDriver(options);
8585
//设置浏览器窗口大小
86-
int winHeight = 800;
87-
int winWidth = 1280;
86+
int winHeight = 528;
87+
int winWidth = 960;
8888
Dimension dim = new Dimension(winWidth, winHeight);
8989
broswer.manage().window().setSize(dim);
9090
//等待1秒,

0 commit comments

Comments
 (0)