Skip to content

Commit 50d80a7

Browse files
committed
回收站字段和该字段的逻辑
作品被删除时用户的喜爱数的校正 用户个人作品数的校正
1 parent 95029e8 commit 50d80a7

File tree

12 files changed

+168
-18
lines changed

12 files changed

+168
-18
lines changed

springboot-dubbo-api/src/main/java/com/lzq/api/dto/AccountResult.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ public class AccountResult implements Serializable{
8282
@TableField("description")
8383
@JsonProperty("description")
8484
private String description;
85+
/**
86+
* 作品数
87+
*/
88+
@TableField("works")
89+
@JsonProperty("works")
90+
private Integer works;
8591
/**
8692
* 喜爱人数
8793
*/
@@ -100,12 +106,19 @@ public class AccountResult implements Serializable{
100106
@TableField("following")
101107
@JsonProperty("following")
102108
private Integer following;
103-
@TableField(exist = false)
109+
/**
110+
* 回收站
111+
*/
112+
@TableField("recycle")
113+
@JsonProperty("recycle")
114+
private Integer recycle;
104115
/**
105116
* 我的关注
106117
*/
118+
@TableField(exist = false)
107119
@JsonProperty("myFollow")
108120
private Boolean myFollow=false;
121+
109122
/**
110123
* 创建时间
111124
*/

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ public class Account implements Serializable, UserDetails {
103103
@TableField("description")
104104
@JsonProperty("description")
105105
private String description;
106+
/**
107+
* 作品数
108+
*/
109+
@TableField("works")
110+
@JsonProperty("works")
111+
private Integer works;
106112
/**
107113
* 喜爱人数
108114
*/
@@ -121,6 +127,12 @@ public class Account implements Serializable, UserDetails {
121127
@TableField("following")
122128
@JsonProperty("following")
123129
private Integer following;
130+
/**
131+
* 回收站
132+
*/
133+
@TableField("recycle")
134+
@JsonProperty("recycle")
135+
private Integer recycle;
124136
/**
125137
* 创建时间
126138
*/

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,33 @@ public interface AccountService {
3333
*/
3434
Boolean update(Account account) throws Exception;
3535

36-
Boolean updateFavorites(String username);
36+
/**
37+
* 增加作品数
38+
* @param username
39+
* @return
40+
*/
41+
Boolean addWorks(String username);
42+
43+
/**
44+
* 减少作品数
45+
* @param username
46+
* @return
47+
*/
48+
Boolean reduceWorks(String username);
49+
50+
/**
51+
* 添加喜爱数
52+
* @param username
53+
* @return
54+
*/
55+
Boolean addFavorites(String username);
56+
57+
/**
58+
* 更新喜爱数(校正喜爱数)
59+
* @param account
60+
* @return
61+
*/
62+
Boolean updateFavorites(Account account);
3763

3864
/**
3965
* 根据第三方id查询用户
@@ -56,8 +82,19 @@ public interface AccountService {
5682
*/
5783
void deleteAccount(Account account);
5884

85+
/**
86+
* 增加回收站作品数
87+
* @param username
88+
* @return
89+
*/
90+
Boolean increaseRecycle(String username);
5991

60-
92+
/**
93+
* 删除回收站作品
94+
* @param username
95+
* @return
96+
*/
97+
Boolean reduceRecycle(String username);
6198

6299

63100
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,16 @@
1212
*/
1313
@Repository
1414
public interface AccountMapper extends BaseMapper<Account> {
15-
Integer updateFavorites(@Param("username") String username);
15+
16+
Integer addFavorites(@Param("username") String username);
17+
18+
Integer updateFavorites(Account account);
19+
20+
Integer addWorks(@Param("username") String username);
21+
22+
Integer reduceWorks(@Param("username") String username);
23+
24+
Integer increaseRecycle(@Param("username") String username);
25+
26+
Integer reduceRecycle(@Param("username") String username);
1627
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lzq.dubboservice.rabbitmq;
22

33
import com.lzq.api.pojo.Example;
4+
import com.lzq.api.service.AccountService;
45
import com.lzq.api.service.ContentService;
56
import com.lzq.api.service.ExampleService;
67
import com.lzq.api.service.FavoritesService;
@@ -34,6 +35,9 @@ public class QueueReceiver {
3435
@Autowired
3536
FavoritesService favoritesService;
3637

38+
@Autowired
39+
AccountService accountService;
40+
3741
@RabbitHandler
3842
public void process(Example example){
3943
log.info(example.toString());
@@ -50,6 +54,9 @@ public void process(Example example){
5054
QiniuyunUtils.deleteFiles(example.getImg());
5155
//删除用户的喜爱
5256
favoritesService.deleteFavorites(example.getExampleId());
57+
//减少回收站数量(删除实例)
58+
accountService.reduceRecycle(example.getUsername());
59+
5360
}
5461

5562
}

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,23 @@ public Boolean update(Account account) throws NullPointerException {
4949
}
5050

5151
@Override
52-
public Boolean updateFavorites(String username) {
53-
return baseMapper.updateFavorites(username)>0?true:false;
52+
public Boolean addWorks(String username) {
53+
return baseMapper.addWorks(username)>0?true:false;
54+
}
55+
56+
@Override
57+
public Boolean reduceWorks(String username) {
58+
return baseMapper.reduceWorks(username)>0?true:false;
59+
}
60+
61+
@Override
62+
public Boolean addFavorites(String username) {
63+
return baseMapper.addFavorites(username)>0?true:false;
64+
}
65+
66+
@Override
67+
public Boolean updateFavorites(Account account) {
68+
return baseMapper.updateFavorites(account)>0?true:false;
5469
}
5570

5671
@Override
@@ -79,5 +94,15 @@ public void deleteAccount(Account account) {
7994
baseMapper.delete(wrapper);
8095
}
8196

97+
@Override
98+
public Boolean increaseRecycle(String username) {
99+
return baseMapper.increaseRecycle(username)>0?true:false;
100+
}
101+
102+
@Override
103+
public Boolean reduceRecycle(String username) {
104+
return baseMapper.reduceRecycle(username)>0?true:false;
105+
}
106+
82107

83108
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public PageInfo<Example> queryByPublic(String username, Integer currentPage) {
6060
@Override
6161
public void deleteExample(Integer exampleId) {
6262
baseMapper.deleteExample(exampleId);
63+
6364
}
6465

6566

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
33
<mapper namespace="com.lzq.dubboservice.mapper.AccountMapper">
4-
<update id="updateFavorites">
4+
5+
6+
<update id="addFavorites">
57
update account set favorites=favorites+1 where username=#{username}
68
</update>
9+
<update id="updateFavorites">
10+
update account set favorites=#{favorites} where username=#{username}
11+
</update>
12+
<update id="addWorks">
13+
update account set works=works+1 where username=#{username}
14+
</update>
15+
<update id="reduceWorks">
16+
update account set works=works-1 where username=#{username}
17+
</update>
18+
<update id="increaseRecycle">
19+
update account set recycle=recycle+1 where username=#{username}
20+
</update>
21+
<update id="reduceRecycle">
22+
update account set recycle=recycle-1 where username=#{username}
23+
</update>
724
</mapper>

springboot-dubbo-web/src/main/java/com/lzq/web/config/SecurityConfig.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.lzq.web.utils.JWTUtils;
88
import com.lzq.web.utils.ResultMapUtils;
99
import com.lzq.web.utils.UserUtils;
10+
import lombok.extern.slf4j.Slf4j;
1011
import org.apache.dubbo.config.annotation.Reference;
1112
import org.springframework.beans.factory.annotation.Autowired;
1213
import org.springframework.context.annotation.Bean;
@@ -21,7 +22,7 @@
2122
import javax.sql.DataSource;
2223
import java.util.HashMap;
2324
import java.util.Map;
24-
25+
@Slf4j
2526
@Configuration
2627
public class SecurityConfig extends WebSecurityConfigurerAdapter {
2728

@@ -50,7 +51,10 @@ protected void configure(HttpSecurity http) throws Exception {
5051
Account account = (Account) authentication.getPrincipal();
5152
Integer count = favoritesService.getCount(account.getUsername());
5253
if (!count.equals(account.getFavorites())){
53-
54+
account.setFavorites(count);
55+
//更新(校正)我的喜爱数
56+
Boolean aBoolean = accountService.updateFavorites(account);
57+
log.info(aBoolean.toString());
5458
}
5559
//是否需要进行第三方绑定
5660
String token = httpServletRequest.getHeader("token");

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.lzq.api.service.ExampleService;
1010
import com.lzq.api.service.FavoritesService;
1111
import com.lzq.web.utils.ExampleUtils;
12-
import com.lzq.web.utils.JWTUtils;
1312
import com.lzq.web.utils.QiniuyunUtils;
1413
import com.lzq.web.utils.ResultMapUtils;
1514
import com.qiniu.util.StringUtils;
@@ -26,15 +25,13 @@
2625
import org.springframework.data.redis.core.RedisTemplate;
2726
import org.springframework.web.bind.annotation.*;
2827

29-
import javax.servlet.http.HttpServletRequest;
3028
import java.io.File;
3129
import java.io.FileNotFoundException;
3230
import java.io.FileOutputStream;
3331
import java.io.IOException;
3432
import java.text.SimpleDateFormat;
3533
import java.util.Date;
3634
import java.util.HashMap;
37-
import java.util.List;
3835
import java.util.Map;
3936

4037
@Slf4j
@@ -90,6 +87,8 @@ public Map<String, Object> CreateFile(Example example) {
9087
example.setFileName(Long.toString(time));
9188
//把文件信息插入到数据库中
9289
Boolean bol = exampleService.insert(example);
90+
Boolean aBoolean = accountService.addWorks(example.getUsername());
91+
log.info(aBoolean.toString());
9392
return ResultMapUtils.ResultMap(bol, 0, example);
9493
} catch (Exception e) {
9594
e.printStackTrace();
@@ -168,13 +167,15 @@ public Map<String,Object> addFavorites(Favorites favorites){
168167
redisTemplate.opsForList().leftPush(favorites.getUsername()+"fav",favorites.getExampleId());
169168
}
170169
//更新用户喜爱数量
171-
Boolean aBoolean = accountService.updateFavorites(favorites.getUsername());
170+
Boolean aBoolean = accountService.addFavorites(favorites.getUsername());
172171
log.info(aBoolean.toString());
173172
return ResultMapUtils.ResultMap(bol,0,null);
174173
}else {
175174
return ResultMapUtils.ResultMap(false,1,null);
176175
}
177176
}
177+
178+
178179
/**
179180
* 放入回收站
180181
* @param example
@@ -192,11 +193,15 @@ public Map<String,Object> deleteExample(Example example){
192193
rabbitTemplate.convertAndSend("delete_exchange", "delete", example, new MessagePostProcessor() {
193194
@Override
194195
public Message postProcessMessage(Message message) throws AmqpException {
195-
//设置延迟时间
196-
message.getMessageProperties().setHeader("x-delay",1000*15);
196+
//设置延迟时间 1天
197+
message.getMessageProperties().setHeader("x-delay",1000*60*60*24*1);
197198
return message;
198199
}
199200
});
201+
//减少用户作品数
202+
accountService.reduceWorks(example.getUsername());
203+
//回收站数量增加
204+
accountService.increaseRecycle(example.getUsername());
200205
return ResultMapUtils.ResultMap(b,0,null);
201206
}else {
202207
return ResultMapUtils.ResultMap(b,0,null);

0 commit comments

Comments
 (0)