Skip to content

Commit 1d71ca6

Browse files
committed
设置私人公开实例(包括搜索)
1 parent a5228c8 commit 1d71ca6

File tree

13 files changed

+44
-57
lines changed

13 files changed

+44
-57
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
@@ -76,6 +76,12 @@ public class Content implements Serializable {
7676
@TableField(exist = false)
7777
@JsonProperty("myFavorites")
7878
private Boolean myFavorites=false;
79+
/**
80+
* 是否公开
81+
*/
82+
@TableField(exist = false)
83+
@JsonIgnore
84+
private Integer ispublic;
7985
/**
8086
* 创建时间
8187
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class Example implements Serializable {
4040
* 是否公开
4141
*/
4242
@TableField(value = "ispublic")
43-
@JsonIgnore
43+
@JsonProperty("ispublic")
4444
private Integer ispublic;
4545
/**
4646
* 标签

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ public interface ContentService {
3030
*
3131
* @param exampleId
3232
* @param username
33+
* @param ispublic
3334
* @return
3435
*/
35-
Content getContent(String exampleId, String username);
36+
Content getContent(String exampleId, String username, Integer ispublic);
3637

3738
/**
3839
* 删除实例内容

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,9 @@ public interface ExampleService {
4747
* @param currentPage 当前页
4848
* @return
4949
*/
50-
PageInfo<Example> queryByAccount(String username, Integer currentPage, Integer orderCondition);
50+
PageInfo<Example> queryByAccount(String username, Integer currentPage, Integer orderCondition, Integer ispublic);
5151

5252

53-
/**
54-
* 查询用户公开的实例
55-
*
56-
* @param username 用户名
57-
* @param currentPage 当前页
58-
* @param orderCondition
59-
* @return
60-
*/
61-
PageInfo<Example> queryByPublic(String username, Integer currentPage,Integer orderCondition);
6253

6354
/**
6455
* 删除实例(物理删除实例)
@@ -78,6 +69,7 @@ public interface ExampleService {
7869

7970
/**
8071
* 通过实例id和用户名查询实例
72+
*
8173
* @param example
8274
* @return
8375
*/
@@ -86,20 +78,23 @@ public interface ExampleService {
8678

8779
/**
8880
* 查询用户的回收站
81+
*
8982
* @param username
9083
* @return
9184
*/
9285
List<Example> queryRecycle(String username);
9386

9487
/**
9588
* 恢复回收站实例
89+
*
9690
* @param exampleId
9791
* @return
9892
*/
9993
Boolean resumeExample(String exampleId);
10094

10195
/**
10296
* 查询回收站是否有该实例
97+
*
10398
* @param example
10499
* @return
105100
*/

springboot-dubbo-service/src/main/java/com/lzq/dubboservice/mapper/ContentMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
public interface ContentMapper extends BaseMapper<Content> {
1515
void deleteContent(@Param("exampleId") String exampleId);
1616

17-
Content getContent(@Param("exampleId") String exampleId, @Param("username") String username);
17+
Content getContent(@Param("exampleId") String exampleId, @Param("username") String username, @Param("ispublic") Integer ispublic);
1818
}

springboot-dubbo-service/src/main/java/com/lzq/dubboservice/service/ContentServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public Boolean addContent(Content content) {
2626
public Boolean updateContent(Content content) {
2727
QueryWrapper<Content> wrapper = new QueryWrapper<>();
2828
wrapper.eq("example_id", content.getExampleId());
29-
return baseMapper.update(content,wrapper) > 0 ? true : false;
29+
return baseMapper.update(content, wrapper) > 0 ? true : false;
3030
}
3131

3232
@Override
33-
public Content getContent(String exampleId, String username) {
34-
return baseMapper.getContent(exampleId,username);
33+
public Content getContent(String exampleId, String username, Integer ispublic) {
34+
return baseMapper.getContent(exampleId, username,ispublic);
3535
}
3636

3737
@Override

springboot-dubbo-service/src/main/java/com/lzq/dubboservice/service/ExampleServiceImpl.java

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,13 @@ public boolean deleteById(String exampleId) {
3737
}
3838

3939
@Override
40-
public PageInfo<Example> queryByAccount(String username, Integer currentPage, Integer orderCondition) {
40+
public PageInfo<Example> queryByAccount(String username, Integer currentPage, Integer orderCondition, Integer ispublic) {
4141
QueryWrapper<Example> wrapper = new QueryWrapper<>();
4242
wrapper.eq("username", username);
43-
switch (orderCondition){
44-
case 0:
45-
wrapper.orderByDesc("create_time");
46-
break;
47-
case 1:
48-
wrapper.orderByDesc("update_time");
49-
break;
50-
case 2:
51-
wrapper.orderByDesc("favorites");
52-
break;
43+
if (ispublic==0){
44+
wrapper.eq("ispublic", 0);
5345
}
54-
//当前页和每页条数
55-
PageHelper.startPage(currentPage, 12);
56-
List<Example> list = baseMapper.selectList(wrapper);
57-
return new PageInfo<>(list);
58-
}
59-
60-
@Override
61-
public PageInfo<Example> queryByPublic(String username, Integer currentPage, Integer orderCondition) {
62-
QueryWrapper<Example> wrapper = new QueryWrapper<>();
63-
wrapper.eq("username", username);
64-
wrapper.eq("ispublic", 0);
65-
switch (orderCondition){
46+
switch (orderCondition) {
6647
case 0:
6748
wrapper.orderByDesc("create_time");
6849
break;
@@ -95,8 +76,8 @@ public Example queryById(String exampleId) {
9576
@Override
9677
public Example queryByIdUsername(Example example) {
9778
QueryWrapper<Example> wrapper = new QueryWrapper<>();
98-
wrapper.eq("username",example.getUsername());
99-
wrapper.eq("example_id",example.getExampleId());
79+
wrapper.eq("username", example.getUsername());
80+
wrapper.eq("example_id", example.getExampleId());
10081
return baseMapper.selectOne(wrapper);
10182
}
10283

@@ -107,7 +88,7 @@ public List<Example> queryRecycle(String username) {
10788

10889
@Override
10990
public Boolean resumeExample(String exampleId) {
110-
return baseMapper.resumeExample(exampleId)>0?true:false;
91+
return baseMapper.resumeExample(exampleId) > 0 ? true : false;
11192
}
11293

11394
@Override

springboot-dubbo-service/src/main/resources/mapper/ContentMapper.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
delete from content where example_id=#{exampleId}
66
</delete>
77
<select id="getContent" resultType="com.lzq.api.pojo.Content">
8-
select a.example_id, code_content, css_style, js_style, html_style, b.example_name, b.label, c.name
8+
select a.example_id, code_content, css_style, js_style, html_style, b.example_name, b.label, c.name, b.ispublic
99
from content a left join example b
1010
on
1111
a.example_id=b.example_id
@@ -14,5 +14,8 @@
1414
b.username=c.username
1515
where
1616
a.example_id=#{exampleId} and b.username=#{username}
17+
<if test="ispublic=0">
18+
and b.ispublic=0
19+
</if>
1720
</select>
1821
</mapper>

springboot-dubbo-service/src/main/resources/mapper/ExampleAccoutMapper.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
on
3838
b.example_id=c.example_id
3939
where
40-
b.example_name like concat('%',#{queryContent},'%')
40+
b.example_name like concat('%',#{queryContent},'%') and b.ispublic=0
4141
<include refid="style"/>
4242
or
43-
b.label like concat('%',#{queryContent},'%')
43+
b.label like concat('%',#{queryContent},'%') and b.ispublic=0
4444
<include refid="style"/>
4545
or
46-
a.name like concat('%',#{queryContent},'%')
46+
a.name like concat('%',#{queryContent},'%') and b.ispublic=0
4747
<include refid="style"/>
4848
and
4949
length(b.example_id)>0

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ public class ContentController {
4949
public Map<String, Object> getContent(HttpServletRequest request, String exampleId, String username) {
5050
log.info("获取实例内容接口"+exampleId+"------"+username);
5151
String token = request.getHeader("token");
52-
Content content = contentService.getContent(exampleId, username);
52+
Content content=null;
5353
//当token不为空时用户已登录
5454
if (StringUtils.isNotBlank(token)){
55+
content = contentService.getContent(exampleId, username,1);
5556
String s = JWTUtils.verify(token).getClaim("username").asString();
5657
List<Integer> favoriteslist = redisTemplate.opsForList().range(s + "fav", 0, -1);
5758
//判断改实例是否为用户的喜爱
5859
if (favoriteslist.contains(content.getExampleId())){
5960
content.setMyFavorites(true);
6061
}
62+
}else {
63+
content = contentService.getContent(exampleId, username,0);
6164
}
6265
return ResultMapUtils.ResultMap(true, 0, content);
6366
}

0 commit comments

Comments
 (0)