Skip to content

Commit dbf416b

Browse files
committedOct 28, 2020
fix
1 parent ed149ec commit dbf416b

39 files changed

+721
-268
lines changed
 

‎.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ model**.txt
2222
#*.txt
2323
/src/main/resources/data/*
2424
#/src/test/*
25-
/tmp/*
25+
#/tmp/*
2626
src/main/resources/application.yml

‎README.md

+104-12
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
基于Elasticsearch的租房搜索系统
33

44
## 概述
5-
### 系统架构
5+
### 一、系统架构
66
主要是以MySQL作为基础数据存储,结合ES实现站内搜索引擎。
77
![img/系统架构.png](img/系统架构.png)
88

9-
### 涉及技术
9+
### 二、涉及技术
1010
- 核心搜索技术:
1111
SpringBoot + Elasticsearch(方便实现站内搜索引擎)
1212
- 站内搜索引擎实现:
@@ -30,8 +30,8 @@ Spring Security(权限控制、自定义安全策略)
3030

3131
## 项目设计
3232

33-
### 数据库设计
34-
#### ER图
33+
### 一、数据库设计
34+
#### 1、ER图
3535
实体-联系图(Entity Relationship Diagram)
3636

3737
- 用户ER图:
@@ -43,19 +43,19 @@ Spring Security(权限控制、自定义安全策略)
4343
![img/数据库表模型.png](img/数据库表模型.png)
4444

4545

46-
#### 结构
46+
#### 2、结构
4747
- 数据+结构转储sql
4848
见文件:db/elasticsearch_house.sql
4949

50-
### 项目结构
51-
#### 结构分层
50+
### 二、项目结构
51+
#### 1、结构分层
5252
经典的MVC架构:
5353
- 1、表示层:web包
5454
- 2、业务逻辑层:service包
5555
- 3、数据层:entity包、repository包
5656

57-
#### API结构设计
58-
##### RESTFul风格API:
57+
#### 2、API结构设计
58+
##### 2.1、RESTFul风格API:
5959
<p> restful是一种软件架构风格、设计风格,而不是标准,只是提供了一组设计原则和约束条件。
6060
它主要用于客户端和服务器交互类的软件。基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制。
6161
<p> REST(表现层状态转化),即Representational State Transfer的缩写。
@@ -69,7 +69,7 @@ Spring Security(权限控制、自定义安全策略)
6969
<p> 对资源的操作不能改变资源标识(URI)本身;
7070
<p> 所有的操作都是无状态的等。
7171

72-
##### API数据格式标准
72+
##### 2.2、API数据格式标准
7373
- code:自定义请求状态码:
7474
<p> 如`com.bubble.house.base.api.ApiStatus`定义的状态码信息;
7575

@@ -78,7 +78,7 @@ Spring Security(权限控制、自定义安全策略)
7878

7979
- data:当前API请求的目标数据;
8080

81-
##### 异常拦截器
81+
##### 2.3、异常拦截器
8282
用于拦截项目运行中的无法预知的情况,通过统一拦截器进行异常拦截。
8383
- 页面异常拦截器:
8484
- API异常拦截器:
@@ -94,4 +94,96 @@ server:
9494
path: /error
9595
```
9696
97-
####
97+
##### 2.4、功能性页面
98+
功能性页面接口定义:`com.bubble.house.web.controller.HomeController`
99+
100+
- 403:权限限制提示页面;
101+
- 404:NotFound提示页面;
102+
- 500:服务异常提示页面;
103+
- logout:登出(注销返回首页)的基本服务页面;
104+
105+
### 三、 业务和功能设计
106+
#### 1、后台管理模块
107+
提供一个后台管理模块来统一管理租房网站的数据和人员信息。
108+
后台管理中心入口:`com.bubble.house.web.controller.admin.AdminController`
109+
管理系统参考:[H-ui.admin是用H-ui前端框架开发的轻量级网站后台模版](http://demo.h-ui.net/H-ui.admin/3.1/index.html#)
110+
主要功能有:
111+
<p> 后台登录:
112+
<p> 权限控制:`com.bubble.house.config.WebSecurityConfig`
113+
<p> 注销功能:
114+
115+
#### 2、权限控制模块
116+
基于spring-security来实现:`com.bubble.house.config.WebSecurityConfig`
117+
<p> 根据不同的请求,跳转到不同的登录页面。如普通用户跳转user/login,管理员跳转admin/login页面。
118+
参考:`com.bubble.house.config.security`包下的实现
119+
120+
#### 3、房源信息管理模块
121+
主要就是对房源信息的增删查改和审核等功能。
122+
##### 3.1、房源浏览:
123+
124+
##### 3.2、房源编辑:
125+
126+
##### 3.3、房源审核:
127+
128+
##### 3.4、房源图片(基于七牛云):
129+
图片上传,主要基于七牛云和百度的WebUploader:`elasticsearch-house/src/main/resources/static/js/admin/upload.js`
130+
131+
##### 3.5、房源新增:
132+
133+
##### 3.6、房源排序:
134+
135+
##### 3.7、房源详情页:
136+
137+
138+
#### 4、地图找房模块
139+
140+
#### 5、会员系统模块
141+
142+
#### 6、预约看房模块
143+
144+
145+
### 四、搜索相关
146+
147+
### 五、报警监控
148+
149+
### 六、日志分析
150+
151+
152+
## 总结
153+
154+
155+
## 注意事项
156+
##### 1、热部署
157+
```yml
158+
# 热部署
159+
devtools:
160+
restart:
161+
# 热部署生效
162+
enabled: true
163+
# 设置重启的目录,添加那个目录的文件需要restart
164+
additional-paths: src/main/java,src/main/resources
165+
# 不需实时加载
166+
exclude: db/** #,static/**
167+
```
168+
169+
##### 2、thymeleaf页面中文乱码
170+
在`com.bubble.house.config.WebMVCConfig`中配置编码:
171+
```java
172+
/**
173+
* 模板资源解析器。
174+
* ConfigurationProperties 绑定配置文件中thymeleaf的前缀
175+
*/
176+
@Bean
177+
@ConfigurationProperties(prefix = "spring.thymeleaf")
178+
public SpringResourceTemplateResolver templateResolver() {
179+
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
180+
// 配置Spring上下文
181+
templateResolver.setApplicationContext(this.applicationContext);
182+
// 防止中文乱码
183+
templateResolver.setCharacterEncoding("UTF-8");
184+
templateResolver.setCacheable(thymeleafCacheEnable);
185+
return templateResolver;
186+
}
187+
188+
```
189+

‎pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<modelmapper.version>2.3.5</modelmapper.version>
2323
<spring-security-core.version>5.2.0.RELEASE</spring-security-core.version>
2424
<guava.version>28.1-jre</guava.version>
25-
<qiniu-java-jdk.version>[7.2.0, 7.2.99]</qiniu-java-jdk.version>
25+
<qiniu-java-jdk.version>[7.3.0, 7.3.99]</qiniu-java-jdk.version>
2626
<aliyun-java-sdk-core.version>4.4.6</aliyun-java-sdk-core.version>
2727
<aliyun-java-sdk-dysmsapi.version>1.1.0</aliyun-java-sdk-dysmsapi.version>
2828
<es.version>7.4.2</es.version>
@@ -110,7 +110,6 @@
110110
<artifactId>spring-security-core</artifactId>
111111
<version>${spring-security-core.version}</version>
112112
</dependency>
113-
114113
<!-- Thymeleaf方言支持SpringSecurity 依赖-->
115114
<dependency>
116115
<groupId>org.thymeleaf.extras</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.bubble.house.base;
2+
3+
import com.bubble.house.entity.user.UserEntity;
4+
import org.springframework.security.core.context.SecurityContextHolder;
5+
6+
import java.util.regex.Pattern;
7+
8+
/**
9+
* 用户登录处理工具
10+
*
11+
* @author wugang
12+
* date: 2020-10-27 17:56
13+
**/
14+
public class LoginUserUtil {
15+
private static final String PHONE_REGEX = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[0,5-9])|(18[0,5-9]))\\d{8}$";
16+
private static final Pattern PHONE_PATTERN = Pattern.compile(PHONE_REGEX);
17+
18+
private static final String EMAIL_REGEX = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
19+
private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX);
20+
21+
public static UserEntity load() {
22+
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
23+
if (principal instanceof UserEntity) {
24+
return (UserEntity) principal;
25+
}
26+
return null;
27+
}
28+
29+
public static Long getLoginUserId() {
30+
UserEntity user = load();
31+
return user == null ? -1L : user.getId();
32+
}
33+
34+
/**
35+
* 验证手机号码
36+
* <p>
37+
* 移动号码段:139、138、137、136、135、134、150、151、152、157、158、159、182、183、187、188、147
38+
* 联通号码段:130、131、132、136、185、186、145、175、185
39+
* 电信号码段:133、153、180、189
40+
*
41+
* @param target 目标号码
42+
* @return 如果是手机号码 返回true; 反之,返回false
43+
*/
44+
public static boolean checkTelephone(String target) {
45+
return PHONE_PATTERN.matcher(target).matches();
46+
}
47+
48+
/**
49+
* 验证一般的英文邮箱
50+
*
51+
* @param target 目标邮箱
52+
* @return 如果符合邮箱规则 返回true; 反之,返回false
53+
*/
54+
public static boolean checkEmail(String target) {
55+
return EMAIL_PATTERN.matcher(target).matches();
56+
}
57+
58+
}

‎src/main/java/com/bubble/house/config/WebMVCConfig.java

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.springframework.context.annotation.Bean;
1010
import org.springframework.context.annotation.Configuration;
1111
import org.springframework.web.servlet.config.annotation.*;
12+
import org.thymeleaf.extras.springsecurity5.dialect.SpringSecurityDialect;
1213
import org.thymeleaf.spring5.SpringTemplateEngine;
1314
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
1415
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
@@ -46,6 +47,7 @@ public SpringResourceTemplateResolver templateResolver() {
4647
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
4748
// 配置Spring上下文
4849
templateResolver.setApplicationContext(this.applicationContext);
50+
// 防止中文乱码
4951
templateResolver.setCharacterEncoding("UTF-8");
5052
templateResolver.setCacheable(thymeleafCacheEnable);
5153
return templateResolver;
@@ -62,6 +64,9 @@ public SpringTemplateEngine templateEngine() {
6264
templateEngine.setTemplateResolver(templateResolver());
6365
// 支持Spring EL表达式
6466
templateEngine.setEnableSpringELCompiler(true);
67+
// 支持SpringSecurity方言
68+
SpringSecurityDialect securityDialect = new SpringSecurityDialect();
69+
templateEngine.addDialect(securityDialect);
6570
return templateEngine;
6671
}
6772

‎src/main/java/com/bubble/house/config/WebSecurityConfig.java

+26-12
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,35 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
3131
@Override
3232
protected void configure(HttpSecurity http) throws Exception {
3333
http.addFilterBefore(authFilter(), UsernamePasswordAuthenticationFilter.class);
34-
3534
// 资源访问权限
3635
http.authorizeRequests()
37-
.antMatchers("/admin/login").permitAll() // permitAll不需要验证, 管理员登录入口
38-
.antMatchers("/static/**").permitAll() // 静态资源
39-
.antMatchers("/user/login").permitAll() // 用户登录入口
40-
.antMatchers("/admin/**").hasRole("ADMIN") // 需要相应的角色才能访问
36+
// permitAll不需要验证, 管理员登录入口
37+
.antMatchers("/admin/login").permitAll()
38+
// 静态资源
39+
.antMatchers("/static/**").permitAll()
40+
// 用户登录入口
41+
.antMatchers("/user/login").permitAll()
42+
// 需要相应的角色才能访问
43+
.antMatchers("/admin/**").hasRole("ADMIN")
4144
.antMatchers("/user/**").hasAnyRole("ADMIN", "USER")
4245
.antMatchers("/api/user/**").hasAnyRole("ADMIN", "USER")
4346
.and()
44-
.formLogin() // 基于Form表单登录验证
45-
.loginProcessingUrl("/login") // 配置角色登录处理入口
47+
// 基于Form表单登录验证
48+
.formLogin()
49+
// 配置角色登录处理入口
50+
.loginProcessingUrl("/login")
51+
// 登录验证失败处理器
4652
.failureHandler(authFailHandler())
4753
.and()
48-
.logout()
49-
.logoutUrl("/logout")
50-
.logoutSuccessUrl("/logout/page")
51-
.deleteCookies("JSESSIONID")
52-
.invalidateHttpSession(true)
54+
// 登出注销配置
55+
.logout().logoutUrl("/logout").logoutSuccessUrl("/logout/page")
56+
// 登出后删除session,使会话失效
57+
.deleteCookies("JSESSIONID").invalidateHttpSession(true)
5358
.and()
59+
// 路由Mapping后的跳转登录入口
5460
.exceptionHandling()
5561
.authenticationEntryPoint(urlEntryPoint())
62+
// 无权访问的提示页面
5663
.accessDeniedPage("/status/403");
5764

5865
http.csrf().disable();
@@ -72,11 +79,18 @@ public AuthProvider authProvider() {
7279
return new AuthProvider();
7380
}
7481

82+
/**
83+
* 根据访问路径来进行路由Mapping后的跳转登录入口
84+
*/
7585
@Bean
7686
public LoginUrlEntryPoint urlEntryPoint() {
87+
// 默认走用户的登录入口
7788
return new LoginUrlEntryPoint("/user/login");
7889
}
7990

91+
/**
92+
* 登录验证失败处理器
93+
*/
8094
@Bean
8195
public LoginAuthFailHandler authFailHandler() {
8296
return new LoginAuthFailHandler(urlEntryPoint());

‎src/main/java/com/bubble/house/config/security/AuthFilter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
5353
String inputCode = request.getParameter("smsCode");
5454
String sessionCode = this.smsService.getSmsCode(telephone);
5555
if (Objects.equals(inputCode, sessionCode)) {
56-
if (user == null) { // 如果用户第一次用手机登录 则自动注册该用户
56+
// 如果用户第一次用手机登录 则自动注册该用户
57+
if (user == null) {
5758
user = this.userService.addUserByPhone(telephone);
5859
}
5960
return new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());

‎src/main/java/com/bubble/house/config/security/AuthProvider.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class AuthProvider implements AuthenticationProvider {
2323

2424
@Autowired
2525
private UserService userService;
26-
// private PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
2726

2827
@Override
2928
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
@@ -35,10 +34,8 @@ public Authentication authenticate(Authentication authentication) throws Authent
3534
LOGGER.error("用户[{}]无权限", userName);
3635
throw new AuthenticationCredentialsNotFoundException("authError");
3736
}
38-
// if (this.passwordEncoder.matches(user.getPassword(), inputPassword + user.getId())) {
39-
// return new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
40-
// }
4137
if (user.getPassword().equals(inputPassword)) {
38+
// 参数:认证用户、密码、拥有的认证权限
4239
return new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
4340
}
4441

‎src/main/java/com/bubble/house/config/security/LoginAuthFailHandler.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public LoginAuthFailHandler(LoginUrlEntryPoint urlEntryPoint) {
2424
@Override
2525
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
2626
AuthenticationException exception) throws IOException, ServletException {
27+
// 获取要跳转的url
2728
String targetUrl = this.urlEntryPoint.determineUrlToUseForThisRequest(request, response, exception);
2829

2930
targetUrl += "?" + exception.getMessage();

‎src/main/java/com/bubble/house/config/security/LoginUrlEntryPoint.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class LoginUrlEntryPoint extends LoginUrlAuthenticationEntryPoint {
2525
private static final String API_CODE_403 = "{\"code\": 403}";
2626
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
2727

28-
private PathMatcher pathMatcher = new AntPathMatcher();
28+
private final PathMatcher pathMatcher = new AntPathMatcher();
2929
private final Map<String, String> authEntryPointMap;
3030

3131
public LoginUrlEntryPoint(String loginFormUrl) {
@@ -44,8 +44,9 @@ public LoginUrlEntryPoint(String loginFormUrl) {
4444
@Override
4545
protected String determineUrlToUseForThisRequest(HttpServletRequest request, HttpServletResponse response,
4646
AuthenticationException exception) {
47+
// 获取原先要跳转的url,即访问路径
4748
String uri = request.getRequestURI().replace(request.getContextPath(), "");
48-
49+
// 根据访问路径来匹配登录入口
4950
for (Map.Entry<String, String> authEntry : this.authEntryPointMap.entrySet()) {
5051
if (this.pathMatcher.match(authEntry.getKey(), uri)) {
5152
return authEntry.getValue();

‎src/main/java/com/bubble/house/entity/dto/UserDTO.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import java.io.Serializable;
44

55
/**
6-
* User
6+
* User:
7+
* DTO: 即数据传输对象。用于表现层和应用层之间的数据交互
8+
* 简单来说Model面向业务,我们是通过业务来定义Model的。而DTO是面向界面UI,是通过UI的需求来定义的。
9+
* 通过DTO我们实现了表现层与Model之间的解耦,表现层不引用Model,
10+
* 如果开发过程中我们的模型改变了,而界面没变,我们就只需要改Model而不需要去改表现层中的东西。
711
*
812
* @author wugang
913
* date: 2019-11-06 10:47
@@ -57,4 +61,14 @@ public void setLastLoginTime(String lastLoginTime) {
5761
this.lastLoginTime = lastLoginTime;
5862
}
5963

64+
@Override
65+
public String toString() {
66+
return "UserDTO{" +
67+
"id=" + id +
68+
", name='" + name + '\'' +
69+
", avatar='" + avatar + '\'' +
70+
", phoneNumber='" + phoneNumber + '\'' +
71+
", lastLoginTime='" + lastLoginTime + '\'' +
72+
'}';
73+
}
6074
}

‎src/main/java/com/bubble/house/entity/house/HouseStatus.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@
77
* date: 2019-11-06 16:19
88
**/
99
public enum HouseStatus {
10-
NOT_AUDITED(0), // 未审核
11-
PASSES(1), // 审核通过
12-
RENTED(2), // 已出租
13-
DELETED(3); // 逻辑删除
10+
/**
11+
* 未审核
12+
*/
13+
NOT_AUDITED(0),
14+
/**
15+
* 审核通过
16+
*/
17+
PASSES(1),
18+
/**
19+
* 已出租
20+
*/
21+
RENTED(2),
22+
/**
23+
* 逻辑删除
24+
*/
25+
DELETED(3);
1426

1527
private int value;
1628

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.bubble.house.entity.house;
2+
3+
/**
4+
* 预约状态码
5+
*
6+
* @author wugang
7+
* date: 2019-11-06 16:19
8+
**/
9+
public enum HouseSubscribeStatus {
10+
/**
11+
* 未预约
12+
*/
13+
NO_SUBSCRIBE(0),
14+
/**
15+
* 已加入待看清单
16+
*/
17+
IN_ORDER_LIST(1),
18+
/**
19+
* 已经预约看房时间
20+
*/
21+
IN_ORDER_TIME(2),
22+
/**
23+
* 已完成预约
24+
*/
25+
FINISH(3);
26+
27+
private int value;
28+
29+
HouseSubscribeStatus(int value) {
30+
this.value = value;
31+
}
32+
33+
public int getValue() {
34+
return value;
35+
}
36+
37+
public static HouseSubscribeStatus of(int value) {
38+
for (HouseSubscribeStatus status : HouseSubscribeStatus.values()) {
39+
if (status.getValue() == value) {
40+
return status;
41+
}
42+
}
43+
return HouseSubscribeStatus.NO_SUBSCRIBE;
44+
}
45+
}

‎src/main/java/com/bubble/house/entity/result/MultiResultEntity.java ‎src/main/java/com/bubble/house/entity/result/ServiceMultiResultEntity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
* @author wugang
1010
* date: 2019-11-05 16:23
1111
**/
12-
public class MultiResultEntity<T> implements Serializable {
12+
public class ServiceMultiResultEntity<T> implements Serializable {
1313
private static final long serialVersionUID = -4332117581412537479L;
1414

1515
private long total;
1616
private List<T> result;
1717

18-
public MultiResultEntity(long total, List<T> result) {
18+
public ServiceMultiResultEntity(long total, List<T> result) {
1919
this.total = total;
2020
this.result = result;
2121
}

‎src/main/java/com/bubble/house/entity/result/ResultEntity.java ‎src/main/java/com/bubble/house/entity/result/ServiceResultEntity.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
import java.io.Serializable;
44

55
/**
6-
* 单一结果
6+
* 单一服务接口通用结构
77
*
88
* @author wugang
99
* date: 2019-11-05 18:25
1010
**/
11-
public class ResultEntity<T> implements Serializable {
11+
public class ServiceResultEntity<T> implements Serializable {
1212
private static final long serialVersionUID = 8366884940162742457L;
1313

1414
private boolean success;
1515
private String message;
1616
private T result;
1717

18-
public ResultEntity(boolean success) {
18+
public ServiceResultEntity(boolean success) {
1919
this.success = success;
2020
}
2121

22-
public ResultEntity(boolean success, String message) {
22+
public ServiceResultEntity(boolean success, String message) {
2323
this.success = success;
2424
this.message = message;
2525
}
2626

27-
public ResultEntity(boolean success, String message, T result) {
27+
public ServiceResultEntity(boolean success, String message, T result) {
2828
this.success = success;
2929
this.message = message;
3030
this.result = result;
@@ -54,21 +54,24 @@ public void setResult(T result) {
5454
this.result = result;
5555
}
5656

57-
public static <T> ResultEntity<T> success() {
58-
return new ResultEntity<>(true);
57+
public static <T> ServiceResultEntity<T> success() {
58+
return new ServiceResultEntity<>(true);
5959
}
6060

61-
public static <T> ResultEntity<T> of(T result) {
62-
ResultEntity<T> serviceResult = new ResultEntity<>(true);
61+
public static <T> ServiceResultEntity<T> of(T result) {
62+
ServiceResultEntity<T> serviceResult = new ServiceResultEntity<>(true);
6363
serviceResult.setResult(result);
6464
return serviceResult;
6565
}
6666

67-
public static <T> ResultEntity<T> notFound() {
68-
return new ResultEntity<>(false, Message.NOT_FOUND.getValue());
67+
public static <T> ServiceResultEntity<T> notFound() {
68+
return new ServiceResultEntity<>(false, Message.NOT_FOUND.getValue());
6969
}
7070

7171
public enum Message {
72+
/**
73+
* 服务返回信息
74+
*/
7275
NOT_FOUND("Not Found Resource!"),
7376
NOT_LOGIN("User not login!");
7477

‎src/main/java/com/bubble/house/entity/user/RoleEntity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.io.Serializable;
55

66
/**
7-
* Role
7+
* Role:角色数据
88
*
99
* @author wugang
1010
* date: 2019-11-05 19:15

‎src/main/java/com/bubble/house/entity/user/UserEntity.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public class UserEntity implements Serializable, UserDetails {
7070
private String avatar;
7171

7272
/**
73-
*
73+
* 用户权限信息集合。
74+
* 注意:因为user表中没有该字段,所以添加@Transient注解,不需要去验证该字段,让该字段处于透明状态。
7475
*/
7576
@Transient
7677
private List<GrantedAuthority> authorityList;

‎src/main/java/com/bubble/house/repository/RoleRepository.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
import java.util.List;
77

88
/**
9-
* Role
9+
* Role:角色数据Dao
1010
*
1111
* @author wugang
1212
* date: 2019-11-06 10:51
1313
**/
1414
public interface RoleRepository extends CrudRepository<RoleEntity, Long> {
15+
/**
16+
* 根据userId获取Role信息
17+
*
18+
* @param userId 用户ID
19+
* @return List<RoleEntity>
20+
*/
1521
List<RoleEntity> findRolesByUserId(Long userId);
1622
}

‎src/main/java/com/bubble/house/service/house/AddressService.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.bubble.house.service.house;
22

33
import com.bubble.house.entity.BaiDuMapEntity;
4-
import com.bubble.house.entity.result.MultiResultEntity;
4+
import com.bubble.house.entity.result.ServiceMultiResultEntity;
55
import com.bubble.house.entity.house.CityEntity;
66
import com.bubble.house.entity.house.CityLevel;
77
import com.bubble.house.entity.house.SubwayEntity;
88
import com.bubble.house.entity.house.SubwayStationEntity;
9-
import com.bubble.house.entity.result.ResultEntity;
9+
import com.bubble.house.entity.result.ServiceResultEntity;
1010

1111
import java.util.List;
1212
import java.util.Map;
@@ -24,7 +24,7 @@ public interface AddressService {
2424
*
2525
* @return 城市列表
2626
*/
27-
MultiResultEntity<CityEntity> findAllCities();
27+
ServiceMultiResultEntity<CityEntity> findAllCities();
2828

2929
/**
3030
* 根据英文简写获取具体区域的信息
@@ -42,7 +42,7 @@ public interface AddressService {
4242
* @param cityEnName 城市英文简写
4343
* @return 城市所有支持的区域信息
4444
*/
45-
MultiResultEntity<CityEntity> findAllRegionsByCityEnName(String cityEnName);
45+
ServiceMultiResultEntity<CityEntity> findAllRegionsByCityEnName(String cityEnName);
4646

4747
/**
4848
* 获取该城市所有的地铁线路
@@ -63,33 +63,33 @@ public interface AddressService {
6363
/**
6464
* 获取地铁线信息
6565
*/
66-
ResultEntity<SubwayEntity> findSubway(Long subwayId);
66+
ServiceResultEntity<SubwayEntity> findSubway(Long subwayId);
6767

6868
/**
6969
* 获取地铁站点信息
7070
*/
71-
ResultEntity<SubwayStationEntity> findSubwayStation(Long stationId);
71+
ServiceResultEntity<SubwayStationEntity> findSubwayStation(Long stationId);
7272

7373
/**
7474
* 根据城市英文简写获取城市详细信息
7575
*/
76-
ResultEntity<CityEntity> findCity(String cityEnName);
76+
ServiceResultEntity<CityEntity> findCity(String cityEnName);
7777

7878
/**
7979
* 根据城市以及具体地位获取百度地图的经纬度
8080
* (需请求百度地图API,建议加缓存、)
8181
*/
82-
ResultEntity<BaiDuMapEntity> getBaiDuMapLocation(String city, String address);
82+
ServiceResultEntity<BaiDuMapEntity> getBaiDuMapLocation(String city, String address);
8383

8484
/**
8585
* 上传百度LBS数据
8686
*/
87-
ResultEntity lbsUpload(BaiDuMapEntity location, String title, String address,
88-
long houseId, int price, int area);
87+
ServiceResultEntity lbsUpload(BaiDuMapEntity location, String title, String address,
88+
long houseId, int price, int area);
8989

9090
/**
9191
* 移除百度LBS数据
9292
*/
93-
ResultEntity removeLbs(Long houseId);
93+
ServiceResultEntity removeLbs(Long houseId);
9494

9595
}

‎src/main/java/com/bubble/house/service/house/AddressServiceImpl.java

+32-32
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import com.bubble.house.entity.house.CityLevel;
66
import com.bubble.house.entity.house.SubwayEntity;
77
import com.bubble.house.entity.house.SubwayStationEntity;
8-
import com.bubble.house.entity.result.MultiResultEntity;
9-
import com.bubble.house.entity.result.ResultEntity;
8+
import com.bubble.house.entity.result.ServiceMultiResultEntity;
9+
import com.bubble.house.entity.result.ServiceResultEntity;
1010
import com.bubble.house.repository.CityRepository;
1111
import com.bubble.house.repository.SubwayRepository;
1212
import com.bubble.house.repository.SubwayStationRepository;
@@ -61,10 +61,10 @@ public AddressServiceImpl(CityRepository cityRepository, SubwayRepository subway
6161
private ObjectMapper objectMapper;
6262

6363
@Override
64-
public MultiResultEntity<CityEntity> findAllCities() {
64+
public ServiceMultiResultEntity<CityEntity> findAllCities() {
6565
List<CityEntity> cityEntityList = this.cityRepository.findAllByLevel(CityLevel.CITY.getValue());
6666
LOGGER.debug("加载城市信息:{}", cityEntityList.size());
67-
return new MultiResultEntity<>(cityEntityList.size(), cityEntityList);
67+
return new ServiceMultiResultEntity<>(cityEntityList.size(), cityEntityList);
6868
}
6969

7070
@Override
@@ -79,13 +79,13 @@ public Map<CityLevel, CityEntity> findCityAndRegion(String cityEnName, String re
7979
}
8080

8181
@Override
82-
public MultiResultEntity<CityEntity> findAllRegionsByCityEnName(String cityEnName) {
82+
public ServiceMultiResultEntity<CityEntity> findAllRegionsByCityEnName(String cityEnName) {
8383
LOGGER.debug("开始加载城市[{}]下的县区信息", cityEnName);
8484
if (null == cityEnName) {
85-
return new MultiResultEntity<>(0, null);
85+
return new ServiceMultiResultEntity<>(0, null);
8686
}
8787
List<CityEntity> regions = this.cityRepository.findAllByLevelAndBelongTo(CityLevel.REGION.getValue(), cityEnName);
88-
return new MultiResultEntity<>(regions.size(), regions);
88+
return new ServiceMultiResultEntity<>(regions.size(), regions);
8989
}
9090

9191
@Override
@@ -106,40 +106,40 @@ public List<SubwayStationEntity> findAllStationBySubway(Long subwayId) {
106106
}
107107

108108
@Override
109-
public ResultEntity<SubwayEntity> findSubway(Long subwayId) {
109+
public ServiceResultEntity<SubwayEntity> findSubway(Long subwayId) {
110110
LOGGER.debug("开始加载地铁[{}]的地铁线路信息", subwayId);
111111
if (subwayId == null) {
112-
return ResultEntity.notFound();
112+
return ServiceResultEntity.notFound();
113113
}
114114
Optional<SubwayEntity> subwayOp = subwayRepository.findById(subwayId);
115-
return subwayOp.map(ResultEntity::of).orElseGet(ResultEntity::notFound);
115+
return subwayOp.map(ServiceResultEntity::of).orElseGet(ServiceResultEntity::notFound);
116116
}
117117

118118
@Override
119-
public ResultEntity<SubwayStationEntity> findSubwayStation(Long stationId) {
119+
public ServiceResultEntity<SubwayStationEntity> findSubwayStation(Long stationId) {
120120
LOGGER.debug("开始加载地铁站[{}]的信息", stationId);
121121
if (null == stationId) {
122-
return ResultEntity.notFound();
122+
return ServiceResultEntity.notFound();
123123
}
124124
Optional<SubwayStationEntity> subwayStationOp = subwayStationRepository.findById(stationId);
125-
return subwayStationOp.map(ResultEntity::of).orElseGet(ResultEntity::notFound);
125+
return subwayStationOp.map(ServiceResultEntity::of).orElseGet(ServiceResultEntity::notFound);
126126
}
127127

128128
@Override
129-
public ResultEntity<CityEntity> findCity(String cityEnName) {
129+
public ServiceResultEntity<CityEntity> findCity(String cityEnName) {
130130
LOGGER.debug("开始加载城市[{}]的信息", cityEnName);
131131
if (null == cityEnName) {
132-
return ResultEntity.notFound();
132+
return ServiceResultEntity.notFound();
133133
}
134134
CityEntity city = cityRepository.findByEnNameAndLevel(cityEnName, CityLevel.CITY.getValue());
135-
return city == null ? ResultEntity.notFound() : ResultEntity.of(city);
135+
return city == null ? ServiceResultEntity.notFound() : ServiceResultEntity.of(city);
136136
}
137137

138138
private static final String BAIDU_MAP_GEOCONV_API = "http://api.map.baidu.com/geocoder/v2/?";
139139
private static final String BAIDU_MAP_KEY = "6QtSF673D1pYl3eQkEXfwp8ZgsQpB77U";
140140

141141
@Override
142-
public ResultEntity<BaiDuMapEntity> getBaiDuMapLocation(String city, String address) {
142+
public ServiceResultEntity<BaiDuMapEntity> getBaiDuMapLocation(String city, String address) {
143143
LOGGER.debug("开始获取[{}-{}]的地理编码信息", city, address);
144144
String encodeAddress;
145145
String encodeCity;
@@ -149,7 +149,7 @@ public ResultEntity<BaiDuMapEntity> getBaiDuMapLocation(String city, String addr
149149
encodeCity = URLEncoder.encode(city, "UTF-8");
150150
} catch (UnsupportedEncodingException e) {
151151
LOGGER.error("[{} - {}] Encode 失败", city, address);
152-
return new ResultEntity<>(false, "Encode house address失败");
152+
return new ServiceResultEntity<>(false, "Encode house address失败");
153153
}
154154
// 百度地理编码服务
155155
HttpClient httpClient = HttpClients.createDefault();
@@ -164,24 +164,24 @@ public ResultEntity<BaiDuMapEntity> getBaiDuMapLocation(String city, String addr
164164
HttpResponse response = httpClient.execute(get);
165165
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
166166
LOGGER.error("[{} - {}] 获取百度坐标失败", city, address);
167-
return new ResultEntity<>(false, "获取百度坐标信息失败");
167+
return new ServiceResultEntity<>(false, "获取百度坐标信息失败");
168168
}
169169
String result = EntityUtils.toString(response.getEntity(), "UTF-8");
170170
JsonNode jsonNode = objectMapper.readTree(result);
171171
int status = jsonNode.get("status").asInt();
172172
if (status != 0) {
173173
LOGGER.error("[{} - {}] 获取百度坐标失败", city, address);
174-
return new ResultEntity<>(false, "获取百度坐标信息失败, Status: " + status);
174+
return new ServiceResultEntity<>(false, "获取百度坐标信息失败, Status: " + status);
175175
} else {
176176
BaiDuMapEntity location = new BaiDuMapEntity();
177177
JsonNode jsonLocation = jsonNode.get("result").get("location");
178178
location.setLongitude(jsonLocation.get("lng").asDouble());
179179
location.setLatitude(jsonLocation.get("lat").asDouble());
180-
return ResultEntity.of(location);
180+
return ServiceResultEntity.of(location);
181181
}
182182
} catch (IOException e) {
183183
LOGGER.error("[{} - {}] 获取百度坐标异常", city, address);
184-
return new ResultEntity<>(false, "获取百度坐标信息出现异常");
184+
return new ServiceResultEntity<>(false, "获取百度坐标信息出现异常");
185185
}
186186
}
187187

@@ -195,7 +195,7 @@ public ResultEntity<BaiDuMapEntity> getBaiDuMapLocation(String city, String addr
195195
private final String GEO_TABLE_ID = "175730";
196196

197197
@Override
198-
public ResultEntity lbsUpload(BaiDuMapEntity location, String title, String address, long houseId, int price, int area) {
198+
public ServiceResultEntity lbsUpload(BaiDuMapEntity location, String title, String address, long houseId, int price, int area) {
199199
LOGGER.debug("开始上传LBS数据到百度存储, House:{}", houseId);
200200
HttpClient httpClient = HttpClients.createDefault();
201201
List<NameValuePair> nvps = Lists.newArrayList();
@@ -223,22 +223,22 @@ public ResultEntity lbsUpload(BaiDuMapEntity location, String title, String addr
223223
String result = EntityUtils.toString(response.getEntity(), "UTF-8");
224224
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
225225
LOGGER.error("上传LBS数据到百度云存储失败, Response: {}", result);
226-
return new ResultEntity(false, "上传LBS数据到百度云存储失败");
226+
return new ServiceResultEntity(false, "上传LBS数据到百度云存储失败");
227227
} else {
228228
JsonNode jsonNode = objectMapper.readTree(result);
229229
int status = jsonNode.get("status").asInt();
230230
if (status != 0) {
231231
String message = jsonNode.get("message").asText();
232232
LOGGER.error("上传LBS数据到百度云存储失败, Status: {}. Message: {}", status, message);
233-
return new ResultEntity(false, "上传LBS数据到百度云存储失败");
233+
return new ServiceResultEntity(false, "上传LBS数据到百度云存储失败");
234234
} else {
235-
return ResultEntity.success();
235+
return ServiceResultEntity.success();
236236
}
237237
}
238238

239239
} catch (IOException e) {
240240
LOGGER.error("上传LBS数据到百度云存储异常");
241-
return new ResultEntity(false, "上传LBS数据到百度云存储异常");
241+
return new ServiceResultEntity(false, "上传LBS数据到百度云存储异常");
242242
}
243243
}
244244

@@ -277,7 +277,7 @@ private boolean isLbsDataExists(Long houseId) {
277277
}
278278

279279
@Override
280-
public ResultEntity removeLbs(Long houseId) {
280+
public ServiceResultEntity removeLbs(Long houseId) {
281281
LOGGER.debug("开始移除LBS数据, House: {}", houseId);
282282
HttpClient httpClient = HttpClients.createDefault();
283283
List<NameValuePair> nvps = Lists.newArrayListWithCapacity(3);
@@ -292,20 +292,20 @@ public ResultEntity removeLbs(Long houseId) {
292292
String result = EntityUtils.toString(response.getEntity(), "UTF-8");
293293
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
294294
LOGGER.error("移除LBS数据失败, Response: {}", response);
295-
return new ResultEntity(false, "移除LBS数据失败");
295+
return new ServiceResultEntity(false, "移除LBS数据失败");
296296
}
297297

298298
JsonNode jsonNode = objectMapper.readTree(result);
299299
int status = jsonNode.get("status").asInt();
300300
if (status != 0) {
301301
String message = jsonNode.get("message").asText();
302302
LOGGER.error("移除LBS数据失败, Message: {}", message);
303-
return new ResultEntity(false, "移除LBS数据失败, Message: {}" + message);
303+
return new ServiceResultEntity(false, "移除LBS数据失败, Message: {}" + message);
304304
}
305-
return ResultEntity.success();
305+
return ServiceResultEntity.success();
306306
} catch (IOException e) {
307307
LOGGER.error("移除LBS数据异常");
308-
return new ResultEntity(false, "移除LBS数据异常");
308+
return new ServiceResultEntity(false, "移除LBS数据异常");
309309
}
310310
}
311311

‎src/main/java/com/bubble/house/service/house/HouseService.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.bubble.house.entity.param.DatatableSearchParam;
55
import com.bubble.house.entity.param.HouseParam;
66
import com.bubble.house.entity.param.RentSearchParam;
7-
import com.bubble.house.entity.result.MultiResultEntity;
8-
import com.bubble.house.entity.result.ResultEntity;
7+
import com.bubble.house.entity.result.ServiceMultiResultEntity;
8+
import com.bubble.house.entity.result.ServiceResultEntity;
99
import com.bubble.house.entity.search.MapSearchEntity;
1010

1111
/**
@@ -18,62 +18,63 @@ public interface HouseService {
1818
/**
1919
* 新增House信息
2020
*/
21-
ResultEntity<HouseDTO> save(HouseParam houseParam);
21+
ServiceResultEntity<HouseDTO> save(HouseParam houseParam);
2222

2323
/**
2424
* House信息展示:分页、筛选、搜索
2525
*/
26-
MultiResultEntity<HouseDTO> adminQuery(DatatableSearchParam searchBody);
26+
ServiceMultiResultEntity<HouseDTO> adminQuery(DatatableSearchParam searchBody);
2727

2828
/**
2929
* 查询完整房源信息
3030
*/
31-
ResultEntity<HouseDTO> findCompleteOne(Long id);
31+
ServiceResultEntity<HouseDTO> findCompleteOne(Long id);
3232

3333
/**
3434
* 数据更新
3535
*/
36-
ResultEntity update(HouseParam houseParam);
36+
ServiceResultEntity update(HouseParam houseParam);
3737

3838
/**
3939
* 移除图片
4040
*/
41-
ResultEntity removePhoto(Long id);
41+
ServiceResultEntity removePhoto(Long id);
4242

4343
/**
4444
* 更新封面
4545
*/
46-
ResultEntity updateCover(Long coverId, Long targetId);
46+
ServiceResultEntity updateCover(Long coverId, Long targetId);
4747

4848
/**
4949
* 新增标签
5050
*/
51-
ResultEntity addTag(Long houseId, String tag);
51+
ServiceResultEntity addTag(Long houseId, String tag);
5252

5353
/**
5454
* 移除标签
5555
*/
56-
ResultEntity removeTag(Long houseId, String tag);
56+
ServiceResultEntity removeTag(Long houseId, String tag);
5757

5858
/**
5959
* 更新房源状态
6060
*/
61-
ResultEntity updateStatus(Long id, int status);
61+
ServiceResultEntity updateStatus(Long id, int status);
6262

6363

6464
/**
6565
* 查询房源信息集
6666
*/
67-
MultiResultEntity<HouseDTO> query(RentSearchParam rentSearch);
67+
ServiceMultiResultEntity<HouseDTO> query(RentSearchParam rentSearch);
6868

6969
/**
7070
* 全地图查询
7171
*/
72-
MultiResultEntity<HouseDTO> wholeMapQuery(MapSearchEntity mapSearch);
72+
ServiceMultiResultEntity<HouseDTO> wholeMapQuery(MapSearchEntity mapSearch);
7373

7474
/**
7575
* 精确范围数据查询
7676
*/
77-
MultiResultEntity<HouseDTO> boundMapQuery(MapSearchEntity mapSearch);
77+
ServiceMultiResultEntity<HouseDTO> boundMapQuery(MapSearchEntity mapSearch);
78+
7879

7980
}

‎src/main/java/com/bubble/house/service/house/HouseServiceImpl.java

+54-54
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import com.bubble.house.entity.param.HouseParam;
1111
import com.bubble.house.entity.param.PhotoParam;
1212
import com.bubble.house.entity.param.RentSearchParam;
13-
import com.bubble.house.entity.result.MultiResultEntity;
14-
import com.bubble.house.entity.result.ResultEntity;
13+
import com.bubble.house.entity.result.ServiceMultiResultEntity;
14+
import com.bubble.house.entity.result.ServiceResultEntity;
1515
import com.bubble.house.entity.search.MapSearchEntity;
1616
import com.bubble.house.repository.*;
1717
import com.bubble.house.service.search.SearchService;
@@ -80,9 +80,9 @@ public HouseServiceImpl(SubwayRepository subwayRepository, SubwayStationReposito
8080
}
8181

8282
@Override
83-
public ResultEntity<HouseDTO> save(HouseParam houseParam) {
83+
public ServiceResultEntity<HouseDTO> save(HouseParam houseParam) {
8484
HouseDetailEntity detail = new HouseDetailEntity();
85-
ResultEntity<HouseDTO> subwayValidationResult = wrapperDetailInfo(detail, houseParam);
85+
ServiceResultEntity<HouseDTO> subwayValidationResult = wrapperDetailInfo(detail, houseParam);
8686
if (subwayValidationResult != null) {
8787
return subwayValidationResult;
8888
}
@@ -123,7 +123,7 @@ public ResultEntity<HouseDTO> save(HouseParam houseParam) {
123123
houseDTO.setTags(tags);
124124
}
125125
LOGGER.info("save house [{}] info successfully", house.getId());
126-
return new ResultEntity<>(true, null, houseDTO);
126+
return new ServiceResultEntity<>(true, null, houseDTO);
127127
}
128128

129129
/**
@@ -149,14 +149,14 @@ private List<HousePictureEntity> generatePictures(HouseParam houseParam, Long ho
149149
/**
150150
* 房源详细信息对象填充
151151
*/
152-
private ResultEntity<HouseDTO> wrapperDetailInfo(HouseDetailEntity houseDetail, HouseParam houseParam) {
152+
private ServiceResultEntity<HouseDTO> wrapperDetailInfo(HouseDetailEntity houseDetail, HouseParam houseParam) {
153153
Optional<SubwayEntity> subwayOp = this.subwayRepository.findById(houseParam.getSubwayLineId());
154154
if (subwayOp.isPresent()) {
155155
SubwayEntity subway = subwayOp.get();
156156
Optional<SubwayStationEntity> subwayStationOp = this.subwayStationRepository.findById(houseParam.getSubwayStationId());
157157
if (!subwayStationOp.isPresent() || !subway.getId().equals(subwayStationOp.get().getSubwayId())) {
158158
LOGGER.error("[{}] Not valid subway station!", houseDetail.getHouseId());
159-
return new ResultEntity<>(false, "Not valid subway station!");
159+
return new ServiceResultEntity<>(false, "Not valid subway station!");
160160
} else {
161161
SubwayStationEntity subwayStation = subwayStationOp.get();
162162

@@ -175,13 +175,13 @@ private ResultEntity<HouseDTO> wrapperDetailInfo(HouseDetailEntity houseDetail,
175175
}
176176
} else {
177177
LOGGER.error("[{}] Not valid subway line!", houseDetail.getHouseId());
178-
return new ResultEntity<>(false, "Not valid subway line!");
178+
return new ServiceResultEntity<>(false, "Not valid subway line!");
179179
}
180180
return null;
181181
}
182182

183183
@Override
184-
public MultiResultEntity<HouseDTO> adminQuery(DatatableSearchParam searchBody) {
184+
public ServiceMultiResultEntity<HouseDTO> adminQuery(DatatableSearchParam searchBody) {
185185
List<HouseDTO> houseDTOS = Lists.newArrayList();
186186
// 分页查询
187187
Sort sort = Sort.by(Sort.Direction.fromString(searchBody.getDirection()), searchBody.getOrderBy());
@@ -222,15 +222,15 @@ public MultiResultEntity<HouseDTO> adminQuery(DatatableSearchParam searchBody) {
222222
houseDTOS.add(houseDTO);
223223
});
224224

225-
return new MultiResultEntity<>(houses.getTotalElements(), houseDTOS);
225+
return new ServiceMultiResultEntity<>(houses.getTotalElements(), houseDTOS);
226226
// return new MultiResultEntity<>(houseDTOS.size(), houseDTOS);
227227
}
228228

229229
@Override
230-
public ResultEntity<HouseDTO> findCompleteOne(Long id) {
230+
public ServiceResultEntity<HouseDTO> findCompleteOne(Long id) {
231231
Optional<HouseEntity> houseOp = houseRepository.findById(id);
232232
if (!houseOp.isPresent()) {
233-
return ResultEntity.notFound();
233+
return ServiceResultEntity.notFound();
234234
}
235235
HouseDetailEntity detail = houseDetailRepository.findByHouseId(id);
236236
List<HousePictureEntity> pictures = housePictureRepository.findAllByHouseId(id);
@@ -258,22 +258,22 @@ public ResultEntity<HouseDTO> findCompleteOne(Long id) {
258258
result.setSubscribeStatus(subscribe.getStatus());
259259
}
260260
}
261-
return ResultEntity.of(result);
261+
return ServiceResultEntity.of(result);
262262
}
263263

264264
@Override
265265
@Transactional
266-
public ResultEntity update(HouseParam houseParam) {
266+
public ServiceResultEntity update(HouseParam houseParam) {
267267
Optional<HouseEntity> houseOp = this.houseRepository.findById(houseParam.getId());
268268
if (!houseOp.isPresent()) {
269-
return ResultEntity.notFound();
269+
return ServiceResultEntity.notFound();
270270
}
271271
HouseEntity house = houseOp.get();
272272
HouseDetailEntity detail = this.houseDetailRepository.findByHouseId(house.getId());
273273
if (detail == null) {
274-
return ResultEntity.notFound();
274+
return ServiceResultEntity.notFound();
275275
}
276-
ResultEntity wrapperResult = wrapperDetailInfo(detail, houseParam);
276+
ServiceResultEntity wrapperResult = wrapperDetailInfo(detail, houseParam);
277277
if (wrapperResult != null) {
278278
return wrapperResult;
279279
}
@@ -293,91 +293,91 @@ public ResultEntity update(HouseParam houseParam) {
293293
this.searchService.index(house.getId());
294294
}
295295

296-
return ResultEntity.success();
296+
return ServiceResultEntity.success();
297297
}
298298

299299
@Override
300-
public ResultEntity removePhoto(Long id) {
300+
public ServiceResultEntity removePhoto(Long id) {
301301
Optional<HousePictureEntity> pictureOp = this.housePictureRepository.findById(id);
302302
if (pictureOp.isPresent()) {
303303
try {
304304
Response response = this.qiNiuService.delete(pictureOp.get().getPath());
305305
if (response.isOK()) {
306306
this.housePictureRepository.deleteById(id);
307-
return ResultEntity.success();
307+
return ServiceResultEntity.success();
308308
} else {
309-
return new ResultEntity(false, response.error);
309+
return new ServiceResultEntity(false, response.error);
310310
}
311311
} catch (QiniuException e) {
312312
LOGGER.error("删除七牛云图片[{}]异常", id);
313-
return new ResultEntity(false, e.getMessage());
313+
return new ServiceResultEntity(false, e.getMessage());
314314
}
315315
} else {
316-
return ResultEntity.notFound();
316+
return ServiceResultEntity.notFound();
317317
}
318318
}
319319

320320
@Override
321321
@Transactional
322-
public ResultEntity updateCover(Long coverId, Long targetId) {
322+
public ServiceResultEntity updateCover(Long coverId, Long targetId) {
323323
Optional<HousePictureEntity> coverOp = this.housePictureRepository.findById(coverId);
324324
if (!coverOp.isPresent()) {
325-
return ResultEntity.notFound();
325+
return ServiceResultEntity.notFound();
326326
}
327327
this.houseRepository.updateCover(targetId, coverOp.get().getPath());
328-
return ResultEntity.success();
328+
return ServiceResultEntity.success();
329329
}
330330

331331
@Override
332332
@Transactional
333-
public ResultEntity addTag(Long houseId, String tag) {
333+
public ServiceResultEntity addTag(Long houseId, String tag) {
334334
Optional<HouseEntity> houseOp = this.houseRepository.findById(houseId);
335335
if (!houseOp.isPresent()) {
336-
return ResultEntity.notFound();
336+
return ServiceResultEntity.notFound();
337337
}
338338

339339
HouseTagEntity houseTag = this.houseTagRepository.findByNameAndHouseId(tag, houseId);
340340
if (houseTag != null) {
341-
return new ResultEntity(false, "标签已存在");
341+
return new ServiceResultEntity(false, "标签已存在");
342342
}
343343
this.houseTagRepository.save(new HouseTagEntity(houseId, tag));
344-
return ResultEntity.success();
344+
return ServiceResultEntity.success();
345345
}
346346

347347
@Override
348348
@Transactional
349-
public ResultEntity removeTag(Long houseId, String tag) {
349+
public ServiceResultEntity removeTag(Long houseId, String tag) {
350350
Optional<HouseEntity> houseOp = this.houseRepository.findById(houseId);
351351
if (!houseOp.isPresent()) {
352-
return ResultEntity.notFound();
352+
return ServiceResultEntity.notFound();
353353
}
354354

355355
HouseTagEntity houseTag = this.houseTagRepository.findByNameAndHouseId(tag, houseId);
356356
if (houseTag == null) {
357-
return new ResultEntity(false, "标签不存在");
357+
return new ServiceResultEntity(false, "标签不存在");
358358
}
359359

360360
this.houseTagRepository.deleteById(houseTag.getId());
361-
return ResultEntity.success();
361+
return ServiceResultEntity.success();
362362
}
363363

364364

365365
@Override
366366
@Transactional
367-
public ResultEntity updateStatus(Long id, int status) {
367+
public ServiceResultEntity updateStatus(Long id, int status) {
368368
Optional<HouseEntity> houseOp = this.houseRepository.findById(id);
369369
if (!houseOp.isPresent()) {
370-
return ResultEntity.notFound();
370+
return ServiceResultEntity.notFound();
371371
}
372372
HouseEntity house = houseOp.get();
373373
if (house.getStatus() == status) {
374-
return new ResultEntity(false, "状态没有发生变化");
374+
return new ServiceResultEntity(false, "状态没有发生变化");
375375
}
376376
if (house.getStatus() == HouseStatus.RENTED.getValue()) {
377-
return new ResultEntity(false, "已出租的房源不允许修改状态");
377+
return new ServiceResultEntity(false, "已出租的房源不允许修改状态");
378378
}
379379
if (house.getStatus() == HouseStatus.DELETED.getValue()) {
380-
return new ResultEntity(false, "已删除的资源不允许操作");
380+
return new ServiceResultEntity(false, "已删除的资源不允许操作");
381381
}
382382
this.houseRepository.updateStatus(id, status);
383383

@@ -387,23 +387,23 @@ public ResultEntity updateStatus(Long id, int status) {
387387
} else {
388388
searchService.remove(id);
389389
}
390-
return ResultEntity.success();
390+
return ServiceResultEntity.success();
391391
}
392392

393393
@Override
394-
public MultiResultEntity<HouseDTO> query(RentSearchParam rentSearch) {
394+
public ServiceMultiResultEntity<HouseDTO> query(RentSearchParam rentSearch) {
395395
if (rentSearch.getKeywords() != null && !rentSearch.getKeywords().isEmpty()) {
396-
MultiResultEntity<Long> multiResult = this.searchService.query(rentSearch);
396+
ServiceMultiResultEntity<Long> multiResult = this.searchService.query(rentSearch);
397397
if (multiResult.getTotal() == 0) {
398-
return new MultiResultEntity<>(0, Lists.newArrayList());
398+
return new ServiceMultiResultEntity<>(0, Lists.newArrayList());
399399
}
400-
return new MultiResultEntity<>(multiResult.getTotal(), wrapperHouseResult(multiResult.getResult()));
400+
return new ServiceMultiResultEntity<>(multiResult.getTotal(), wrapperHouseResult(multiResult.getResult()));
401401
}
402402
// 简单查询
403403
return simpleQuery(rentSearch);
404404
}
405405

406-
private MultiResultEntity<HouseDTO> simpleQuery(RentSearchParam rentSearch) {
406+
private ServiceMultiResultEntity<HouseDTO> simpleQuery(RentSearchParam rentSearch) {
407407
Sort sort = HouseSort.generateSort(rentSearch.getOrderBy(), rentSearch.getOrderDirection());
408408
int page = rentSearch.getStart() / rentSearch.getSize();
409409
Pageable pageable = PageRequest.of(page, rentSearch.getSize(), sort);
@@ -440,7 +440,7 @@ private MultiResultEntity<HouseDTO> simpleQuery(RentSearchParam rentSearch) {
440440
List<Long> houseIds = Lists.newArrayList();
441441
houses.forEach(h -> houseIds.add(h.getId()));
442442
List<HouseDTO> houseDTOS = wrapperHouseResult(houseIds);
443-
return new MultiResultEntity<>(houses.getTotalElements(), houseDTOS);
443+
return new ServiceMultiResultEntity<>(houses.getTotalElements(), houseDTOS);
444444
}
445445

446446
/**
@@ -483,25 +483,25 @@ private void wrapperHouseList(List<Long> houseIds, Map<Long, HouseDTO> idToHouse
483483

484484

485485
@Override
486-
public MultiResultEntity<HouseDTO> wholeMapQuery(MapSearchEntity mapSearch) {
487-
MultiResultEntity<Long> serviceResult = searchService.mapQuery(mapSearch.getCityEnName(), mapSearch.getOrderBy(), mapSearch.getOrderDirection(), mapSearch.getStart(), mapSearch.getSize());
486+
public ServiceMultiResultEntity<HouseDTO> wholeMapQuery(MapSearchEntity mapSearch) {
487+
ServiceMultiResultEntity<Long> serviceResult = searchService.mapQuery(mapSearch.getCityEnName(), mapSearch.getOrderBy(), mapSearch.getOrderDirection(), mapSearch.getStart(), mapSearch.getSize());
488488

489489
if (serviceResult.getTotal() == 0) {
490-
return new MultiResultEntity<>(0, Lists.newArrayList());
490+
return new ServiceMultiResultEntity<>(0, Lists.newArrayList());
491491
}
492492
List<HouseDTO> houses = wrapperHouseResult(serviceResult.getResult());
493-
return new MultiResultEntity<>(serviceResult.getTotal(), houses);
493+
return new ServiceMultiResultEntity<>(serviceResult.getTotal(), houses);
494494
}
495495

496496
@Override
497-
public MultiResultEntity<HouseDTO> boundMapQuery(MapSearchEntity mapSearch) {
498-
MultiResultEntity<Long> serviceResult = searchService.mapQuery(mapSearch);
497+
public ServiceMultiResultEntity<HouseDTO> boundMapQuery(MapSearchEntity mapSearch) {
498+
ServiceMultiResultEntity<Long> serviceResult = searchService.mapQuery(mapSearch);
499499
if (serviceResult.getTotal() == 0) {
500-
return new MultiResultEntity<>(0, Lists.newArrayList());
500+
return new ServiceMultiResultEntity<>(0, Lists.newArrayList());
501501
}
502502

503503
List<HouseDTO> houses = wrapperHouseResult(serviceResult.getResult());
504-
return new MultiResultEntity<>(serviceResult.getTotal(), houses);
504+
return new ServiceMultiResultEntity<>(serviceResult.getTotal(), houses);
505505
}
506506

507507
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.bubble.house.service.house;
2+
3+
import com.bubble.house.entity.result.ServiceResultEntity;
4+
5+
/**
6+
* 预约管理服务
7+
*
8+
* @author wugang
9+
* date: 2020-10-27 18:13
10+
**/
11+
public interface SubscribeService {
12+
13+
/* --- 房源预约管理 --- */
14+
15+
/**
16+
* 加入预约清单
17+
*
18+
* @param houseId 房源ID
19+
* @return ResultEntity
20+
*/
21+
ServiceResultEntity addSubscribeOrder(Long houseId);
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.bubble.house.service.house;
2+
3+
import com.bubble.house.base.LoginUserUtil;
4+
import com.bubble.house.entity.house.HouseEntity;
5+
import com.bubble.house.entity.house.HouseSubscribeEntity;
6+
import com.bubble.house.entity.house.HouseSubscribeStatus;
7+
import com.bubble.house.entity.result.ServiceResultEntity;
8+
import com.bubble.house.repository.HouseRepository;
9+
import com.bubble.house.repository.HouseSubscribeRepository;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
import org.springframework.stereotype.Service;
13+
import org.springframework.transaction.annotation.Transactional;
14+
15+
import java.util.Date;
16+
import java.util.Optional;
17+
18+
/**
19+
* 房源预约管理服务实现
20+
*
21+
* @author wugang
22+
* date: 2020-10-27 18:14
23+
**/
24+
@Service
25+
public class SubscribeServiceImpl implements SubscribeService {
26+
private final Logger logger = LoggerFactory.getLogger(SubscribeServiceImpl.class);
27+
28+
private final HouseSubscribeRepository subscribeRepository;
29+
private final HouseRepository houseRepository;
30+
31+
public SubscribeServiceImpl(HouseSubscribeRepository subscribeRepository, HouseRepository houseRepository) {
32+
this.subscribeRepository = subscribeRepository;
33+
this.houseRepository = houseRepository;
34+
}
35+
36+
@Override
37+
@Transactional
38+
public ServiceResultEntity addSubscribeOrder(Long houseId) {
39+
Long userId = LoginUserUtil.getLoginUserId();
40+
HouseSubscribeEntity subscribe = subscribeRepository.findByHouseIdAndUserId(houseId, userId);
41+
if (subscribe != null) {
42+
return new ServiceResultEntity(false, "已加入预约");
43+
}
44+
45+
Optional<HouseEntity> houseOp = houseRepository.findById(houseId);
46+
if (!houseOp.isPresent()) {
47+
return new ServiceResultEntity(false, "查无此房");
48+
}
49+
HouseEntity house = houseOp.get();
50+
subscribe = new HouseSubscribeEntity();
51+
Date now = new Date();
52+
subscribe.setCreateTime(now);
53+
subscribe.setLastUpdateTime(now);
54+
subscribe.setUserId(userId);
55+
subscribe.setHouseId(houseId);
56+
subscribe.setStatus(HouseSubscribeStatus.IN_ORDER_LIST.getValue());
57+
subscribe.setAdminId(house.getAdminId());
58+
subscribeRepository.save(subscribe);
59+
return ServiceResultEntity.success();
60+
}
61+
}

‎src/main/java/com/bubble/house/service/search/SearchService.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.bubble.house.service.search;
22

33
import com.bubble.house.entity.param.RentSearchParam;
4-
import com.bubble.house.entity.result.MultiResultEntity;
5-
import com.bubble.house.entity.result.ResultEntity;
4+
import com.bubble.house.entity.result.ServiceMultiResultEntity;
5+
import com.bubble.house.entity.result.ServiceResultEntity;
66
import com.bubble.house.entity.search.HouseBucketEntity;
77
import com.bubble.house.entity.search.MapSearchEntity;
88

@@ -29,32 +29,32 @@ public interface SearchService {
2929
/**
3030
* 查询房源接口
3131
*/
32-
MultiResultEntity<Long> query(RentSearchParam rentSearch);
32+
ServiceMultiResultEntity<Long> query(RentSearchParam rentSearch);
3333

3434
/**
3535
* 获取补全建议关键词
3636
*/
37-
ResultEntity<List<String>> suggest(String prefix);
37+
ServiceResultEntity<List<String>> suggest(String prefix);
3838

3939
/**
4040
* 聚合特定小区的房间数
4141
*/
42-
ResultEntity<Long> aggregateDistrictHouse(String cityEnName, String regionEnName, String district);
42+
ServiceResultEntity<Long> aggregateDistrictHouse(String cityEnName, String regionEnName, String district);
4343

4444
/**
4545
* 聚合城市数据
4646
*/
47-
MultiResultEntity<HouseBucketEntity> mapAggregate(String cityEnName);
47+
ServiceMultiResultEntity<HouseBucketEntity> mapAggregate(String cityEnName);
4848

4949
/**
5050
* 城市级别查询
5151
*/
52-
MultiResultEntity<Long> mapQuery(String cityEnName, String orderBy,
53-
String orderDirection, int start, int size);
52+
ServiceMultiResultEntity<Long> mapQuery(String cityEnName, String orderBy,
53+
String orderDirection, int start, int size);
5454

5555
/**
5656
* 精确范围数据查询
5757
*/
58-
MultiResultEntity<Long> mapQuery(MapSearchEntity mapSearch);
58+
ServiceMultiResultEntity<Long> mapQuery(MapSearchEntity mapSearch);
5959

6060
}

‎src/main/java/com/bubble/house/service/search/SearchServiceImpl.java

+29-29
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import com.bubble.house.entity.BaiDuMapEntity;
99
import com.bubble.house.entity.house.*;
1010
import com.bubble.house.entity.param.RentSearchParam;
11-
import com.bubble.house.entity.result.MultiResultEntity;
12-
import com.bubble.house.entity.result.ResultEntity;
11+
import com.bubble.house.entity.result.ServiceMultiResultEntity;
12+
import com.bubble.house.entity.result.ServiceResultEntity;
1313
import com.bubble.house.entity.search.HouseBucketEntity;
1414
import com.bubble.house.entity.search.MapSearchEntity;
1515
import com.bubble.house.entity.search.RentValueBlockEntity;
@@ -144,7 +144,7 @@ private void removeIndex(HouseIndexMessage message) {
144144
if (result == DocWriteResponse.Result.DELETED) {
145145
LOGGER.info("删除[{}]成功.", houseId);
146146

147-
ResultEntity serviceResult = addressService.removeLbs(houseId);
147+
ServiceResultEntity serviceResult = addressService.removeLbs(houseId);
148148
if (!serviceResult.isSuccess()) {
149149
LOGGER.error("删除LBS data [{}]失败.", houseId);
150150
// 重新加入消息队列
@@ -181,7 +181,7 @@ private void createOrUpdateIndex(HouseIndexMessage message) {
181181
CityEntity region = cityRepository.findByEnNameAndLevel(house.getRegionEnName(), CityLevel.REGION.getValue());
182182

183183
String address = city.getCnName() + region.getCnName() + house.getStreet() + house.getDistrict() + detail.getDetailAddress();
184-
ResultEntity<BaiDuMapEntity> location = addressService.getBaiDuMapLocation(city.getCnName(), address);
184+
ServiceResultEntity<BaiDuMapEntity> location = addressService.getBaiDuMapLocation(city.getCnName(), address);
185185
if (!location.isSuccess()) {
186186
this.index(message.getHouseId(), message.getRetry() + 1);
187187
return;
@@ -213,7 +213,7 @@ private void createOrUpdateIndex(HouseIndexMessage message) {
213213
success = deleteAndCreate(totalHit, indexTemplate);
214214
}
215215

216-
ResultEntity serviceResult = addressService.lbsUpload(location.getResult(), house.getStreet() + house.getDistrict(),
216+
ServiceResultEntity serviceResult = addressService.lbsUpload(location.getResult(), house.getStreet() + house.getDistrict(),
217217
city.getCnName() + region.getCnName() + house.getStreet() + house.getDistrict(),
218218
message.getHouseId(), house.getPrice(), house.getArea());
219219

@@ -345,7 +345,7 @@ public void remove(Long houseId) {
345345
}
346346

347347
@Override
348-
public MultiResultEntity<Long> query(RentSearchParam rentSearch) {
348+
public ServiceMultiResultEntity<Long> query(RentSearchParam rentSearch) {
349349
// city_en_name
350350
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
351351
boolQuery.filter(QueryBuilders.termQuery(HouseIndexConstants.CITY_EN_NAME, rentSearch.getCityEnName()));
@@ -435,20 +435,20 @@ public MultiResultEntity<Long> query(RentSearchParam rentSearch) {
435435
String houseId = String.valueOf(hit.getSourceAsMap().get(HouseIndexConstants.HOUSE_ID));
436436
houseIds.add(Long.parseLong(houseId));
437437
}
438-
return new MultiResultEntity<>(totalHits.value, houseIds);
438+
return new ServiceMultiResultEntity<>(totalHits.value, houseIds);
439439
} else {
440440
LOGGER.error("Search status is not ok for: {}", request);
441-
return new MultiResultEntity<>(0, houseIds);
441+
return new ServiceMultiResultEntity<>(0, houseIds);
442442
}
443443
} catch (IOException e) {
444444
LOGGER.error("Query Error...");
445445
}
446446

447-
return new MultiResultEntity<>(0, Lists.newArrayList());
447+
return new ServiceMultiResultEntity<>(0, Lists.newArrayList());
448448
}
449449

450450
@Override
451-
public ResultEntity<List<String>> suggest(String prefix) {
451+
public ServiceResultEntity<List<String>> suggest(String prefix) {
452452
SearchRequest searchRequest = new SearchRequest(HouseIndexConstants.INDEX_NAME);
453453
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
454454
SuggestionBuilder suggestion = SuggestBuilders.completionSuggestion("suggest").prefix(prefix).size(HouseIndexConstants.SUGGESTION_COUNT);
@@ -462,7 +462,7 @@ public ResultEntity<List<String>> suggest(String prefix) {
462462
if (response.status() == RestStatus.OK) {
463463
Suggest suggest = response.getSuggest();
464464
if (null == suggest) {
465-
return ResultEntity.of(Lists.newArrayList());
465+
return ServiceResultEntity.of(Lists.newArrayList());
466466
}
467467
Suggest.Suggestion result = suggest.getSuggestion(HouseIndexConstants.SUGGESTION_NAME);
468468
int maxSuggest = 0;
@@ -487,15 +487,15 @@ public ResultEntity<List<String>> suggest(String prefix) {
487487
}
488488
}
489489
List<String> suggests = Lists.newArrayList(suggestSet.toArray(new String[]{}));
490-
return ResultEntity.of(suggests);
490+
return ServiceResultEntity.of(suggests);
491491
} else {
492-
return ResultEntity.of(Lists.newArrayList());
492+
return ServiceResultEntity.of(Lists.newArrayList());
493493
}
494494
} catch (IOException e) {
495495
LOGGER.error("异常");
496496
}
497497

498-
return ResultEntity.of(Lists.newArrayList());
498+
return ServiceResultEntity.of(Lists.newArrayList());
499499
}
500500

501501
private boolean updateSuggest(HouseIndexTemplate indexTemplate) {
@@ -539,7 +539,7 @@ private boolean updateSuggest(HouseIndexTemplate indexTemplate) {
539539
}
540540

541541
@Override
542-
public ResultEntity<Long> aggregateDistrictHouse(String cityEnName, String regionEnName, String district) {
542+
public ServiceResultEntity<Long> aggregateDistrictHouse(String cityEnName, String regionEnName, String district) {
543543
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
544544
.filter(QueryBuilders.termQuery(HouseIndexConstants.CITY_EN_NAME, cityEnName))
545545
.filter(QueryBuilders.termQuery(HouseIndexConstants.REGION_EN_NAME, regionEnName))
@@ -557,7 +557,7 @@ public ResultEntity<Long> aggregateDistrictHouse(String cityEnName, String regio
557557
Terms terms = response.getAggregations().get(HouseIndexConstants.AGG_DISTRICT);
558558
if (null != terms) { // ES中无该数据时
559559
if (null != terms.getBuckets() && !terms.getBuckets().isEmpty()) {
560-
return ResultEntity.of(terms.getBucketByKey(district).getDocCount());
560+
return ServiceResultEntity.of(terms.getBucketByKey(district).getDocCount());
561561
}
562562
}
563563
} else {
@@ -567,11 +567,11 @@ public ResultEntity<Long> aggregateDistrictHouse(String cityEnName, String regio
567567
LOGGER.info("aggregate district house 异常");
568568
}
569569

570-
return ResultEntity.of(0L);
570+
return ServiceResultEntity.of(0L);
571571
}
572572

573573
@Override
574-
public MultiResultEntity<HouseBucketEntity> mapAggregate(String cityEnName) {
574+
public ServiceMultiResultEntity<HouseBucketEntity> mapAggregate(String cityEnName) {
575575
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
576576
boolQuery.filter(QueryBuilders.termQuery(HouseIndexConstants.CITY_EN_NAME, cityEnName));
577577
AggregationBuilder aggregationBuilder = AggregationBuilders.terms(HouseIndexConstants.AGG_REGION)
@@ -588,22 +588,22 @@ public MultiResultEntity<HouseBucketEntity> mapAggregate(String cityEnName) {
588588
List<HouseBucketEntity> buckets = Lists.newArrayList();
589589
if (response.status() != RestStatus.OK) {
590590
LOGGER.error("Aggregate status is not ok for: {}", searchRequest.toString());
591-
return new MultiResultEntity<>(0, buckets);
591+
return new ServiceMultiResultEntity<>(0, buckets);
592592
}
593593
Terms terms = response.getAggregations().get(HouseIndexConstants.AGG_REGION);
594594
for (Terms.Bucket bucket : terms.getBuckets()) {
595595
buckets.add(new HouseBucketEntity(bucket.getKeyAsString(), bucket.getDocCount()));
596596
}
597-
return new MultiResultEntity<>(response.getHits().getTotalHits().value, buckets);
597+
return new ServiceMultiResultEntity<>(response.getHits().getTotalHits().value, buckets);
598598
} catch (IOException e) {
599599
LOGGER.error("map aggregate error.");
600600
}
601601

602-
return new MultiResultEntity<>(0, Lists.newArrayList());
602+
return new ServiceMultiResultEntity<>(0, Lists.newArrayList());
603603
}
604604

605605
@Override
606-
public MultiResultEntity<Long> mapQuery(String cityEnName, String orderBy, String orderDirection, int start, int size) {
606+
public ServiceMultiResultEntity<Long> mapQuery(String cityEnName, String orderBy, String orderDirection, int start, int size) {
607607
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
608608
boolQuery.filter(QueryBuilders.termQuery(HouseIndexConstants.CITY_EN_NAME, cityEnName));
609609

@@ -621,20 +621,20 @@ public MultiResultEntity<Long> mapQuery(String cityEnName, String orderBy, Strin
621621

622622
if (response.status() != RestStatus.OK) {
623623
LOGGER.error("Search status is not ok for: {}", searchRequest.toString());
624-
return new MultiResultEntity<>(0, houseIds);
624+
return new ServiceMultiResultEntity<>(0, houseIds);
625625
}
626626
for (SearchHit hit : response.getHits()) {
627627
houseIds.add(Long.parseLong(String.valueOf(hit.getSourceAsMap().get(HouseIndexConstants.HOUSE_ID))));
628628
}
629-
return new MultiResultEntity<>(response.getHits().getTotalHits().value, houseIds);
629+
return new ServiceMultiResultEntity<>(response.getHits().getTotalHits().value, houseIds);
630630
} catch (IOException e) {
631631
LOGGER.error("异常");
632632
}
633-
return new MultiResultEntity<>(0, Lists.newArrayList());
633+
return new ServiceMultiResultEntity<>(0, Lists.newArrayList());
634634
}
635635

636636
@Override
637-
public MultiResultEntity<Long> mapQuery(MapSearchEntity mapSearch) {
637+
public ServiceMultiResultEntity<Long> mapQuery(MapSearchEntity mapSearch) {
638638
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
639639
boolQuery.filter(QueryBuilders.termQuery(HouseIndexConstants.CITY_EN_NAME, mapSearch.getCityEnName()));
640640

@@ -660,16 +660,16 @@ public MultiResultEntity<Long> mapQuery(MapSearchEntity mapSearch) {
660660

661661
if (response.status() != RestStatus.OK) {
662662
LOGGER.error("Search status is not ok for: {}", searchRequest.toString());
663-
return new MultiResultEntity<>(0, houseIds);
663+
return new ServiceMultiResultEntity<>(0, houseIds);
664664
}
665665
for (SearchHit hit : response.getHits()) {
666666
houseIds.add(Long.parseLong(String.valueOf(hit.getSourceAsMap().get(HouseIndexConstants.HOUSE_ID))));
667667
}
668-
return new MultiResultEntity<>(response.getHits().getTotalHits().value, houseIds);
668+
return new ServiceMultiResultEntity<>(response.getHits().getTotalHits().value, houseIds);
669669
} catch (IOException e) {
670670
LOGGER.error("异常");
671671
}
672-
return new MultiResultEntity<>(0, Lists.newArrayList());
672+
return new ServiceMultiResultEntity<>(0, Lists.newArrayList());
673673
}
674674

675675
}

‎src/main/java/com/bubble/house/service/user/SMSService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.bubble.house.service.user;
22

3-
import com.bubble.house.entity.result.ResultEntity;
3+
import com.bubble.house.entity.result.ServiceResultEntity;
44

55
/**
66
* SMS短信服务:验证码服务
@@ -13,7 +13,7 @@ public interface SMSService {
1313
/**
1414
* 发送验证码到指定手机 并 缓存验证码 10分钟 及 请求间隔时间1分钟
1515
*/
16-
ResultEntity<String> sendSms(String telephone);
16+
ServiceResultEntity<String> sendSms(String telephone);
1717

1818
/**
1919
* 获取缓存中的验证码

‎src/main/java/com/bubble/house/service/user/SMSServiceImpl.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.aliyuncs.http.MethodType;
99
import com.aliyuncs.profile.DefaultProfile;
1010
import com.aliyuncs.profile.IClientProfile;
11-
import com.bubble.house.entity.result.ResultEntity;
11+
import com.bubble.house.entity.result.ServiceResultEntity;
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
1414
import org.springframework.beans.factory.InitializingBean;
@@ -51,12 +51,12 @@ public SMSServiceImpl(RedisTemplate<String, String> redisTemplate) {
5151

5252

5353
@Override
54-
public ResultEntity<String> sendSms(String telephone) {
54+
public ServiceResultEntity<String> sendSms(String telephone) {
5555
String gapKey = "SMS::CODE::INTERVAL::" + telephone;
5656
String result = redisTemplate.opsForValue().get(gapKey);
5757
if (result != null) {
5858
LOGGER.error("send sms [{}] 请求次数太频繁", telephone);
59-
return new ResultEntity<>(false, "请求次数太频繁");
59+
return new ServiceResultEntity<>(false, "请求次数太频繁");
6060
}
6161
String code = generateRandomSmsCode();
6262
String templateParam = String.format("{\"code\": \"%s\"}", code);
@@ -83,10 +83,10 @@ public ResultEntity<String> sendSms(String telephone) {
8383
if (success) {
8484
redisTemplate.opsForValue().set(gapKey, code, 60, TimeUnit.SECONDS);
8585
redisTemplate.opsForValue().set(SMS_CODE_CONTENT_PREFIX + telephone, code, 10, TimeUnit.MINUTES);
86-
return ResultEntity.of(code);
86+
return ServiceResultEntity.of(code);
8787
} else {
8888
LOGGER.error("send sms [{}] 服务忙,请稍后重试", telephone);
89-
return new ResultEntity<>(false, "服务忙,请稍后重试");
89+
return new ServiceResultEntity<>(false, "服务忙,请稍后重试");
9090
}
9191
}
9292

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.bubble.house.service.user;
22

33
import com.bubble.house.entity.dto.UserDTO;
4-
import com.bubble.house.entity.result.ResultEntity;
4+
import com.bubble.house.entity.result.ServiceResultEntity;
55
import com.bubble.house.entity.user.UserEntity;
66

77
/**
@@ -12,23 +12,45 @@
1212
**/
1313
public interface UserService {
1414

15+
/**
16+
* 根据用户名查询并获取用户权限
17+
*
18+
* @param userName 用户名
19+
* @return 用户实体
20+
*/
1521
UserEntity findUserByName(String userName);
1622

17-
ResultEntity<UserDTO> findById(Long userId);
23+
/**
24+
* 根据用户ID查询
25+
*
26+
* @param userId 用户ID
27+
* @return ResultEntity<UserDTO>
28+
*/
29+
ServiceResultEntity<UserDTO> findById(Long userId);
1830

1931
/**
2032
* 根据电话号码寻找用户
33+
*
34+
* @param telephone 联系方式
35+
* @return UserEntity
2136
*/
2237
UserEntity findUserByTelephone(String telephone);
2338

2439
/**
2540
* 通过手机号注册用户
41+
*
42+
* @param telephone 手机号
43+
* @return UserEntity
2644
*/
2745
UserEntity addUserByPhone(String telephone);
2846

2947
/**
3048
* 修改指定属性值
49+
*
50+
* @param profile 要修改的属性
51+
* @param value 值
52+
* @return ResultEntity
3153
*/
32-
ResultEntity modifyUserProfile(String profile, String value);
54+
ServiceResultEntity modifyUserProfile(String profile, String value);
3355

3456
}

‎src/main/java/com/bubble/house/service/user/UserServiceImpl.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.bubble.house.base.ToolKits;
44
import com.bubble.house.entity.dto.UserDTO;
5-
import com.bubble.house.entity.result.ResultEntity;
5+
import com.bubble.house.entity.result.ServiceResultEntity;
66
import com.bubble.house.entity.user.RoleEntity;
77
import com.bubble.house.entity.user.UserEntity;
88
import com.bubble.house.repository.RoleRepository;
@@ -61,7 +61,7 @@ public UserEntity findUserByName(String userName) {
6161
LOGGER.error("用户[{}]无权限", userName);
6262
throw new DisabledException("用户[" + userName + "]无权限");
6363
}
64-
64+
// 设置用户权限
6565
List<GrantedAuthority> authorities = new ArrayList<>();
6666
roles.forEach(role -> authorities.add(new SimpleGrantedAuthority("ROLE_" + role.getName())));
6767
user.setAuthorityList(authorities);
@@ -71,13 +71,13 @@ public UserEntity findUserByName(String userName) {
7171
}
7272

7373
@Override
74-
public ResultEntity<UserDTO> findById(Long userId) {
74+
public ServiceResultEntity<UserDTO> findById(Long userId) {
7575
Optional<UserEntity> userOp = userRepository.findById(userId);
7676
if (!userOp.isPresent()) {
77-
return ResultEntity.notFound();
77+
return ServiceResultEntity.notFound();
7878
}
7979
UserDTO userDTO = modelMapper.map(userOp.get(), UserDTO.class);
80-
return ResultEntity.of(userDTO);
80+
return ServiceResultEntity.of(userDTO);
8181
}
8282

8383
@Override
@@ -119,10 +119,10 @@ public UserEntity addUserByPhone(String telephone) {
119119

120120
@Override
121121
@Transactional
122-
public ResultEntity modifyUserProfile(String profile, String value) {
122+
public ServiceResultEntity modifyUserProfile(String profile, String value) {
123123
Long userId = ToolKits.getLoginUserId();
124124
if (profile == null || profile.isEmpty()) {
125-
return new ResultEntity(false, "属性不可以为空");
125+
return new ServiceResultEntity(false, "属性不可以为空");
126126
}
127127
switch (profile) {
128128
case "name":
@@ -136,8 +136,8 @@ public ResultEntity modifyUserProfile(String profile, String value) {
136136
userRepository.updatePassword(userId, value);
137137
break;
138138
default:
139-
return new ResultEntity(false, "不支持的属性");
139+
return new ServiceResultEntity(false, "不支持的属性");
140140
}
141-
return ResultEntity.success();
141+
return ServiceResultEntity.success();
142142
}
143143
}

‎src/main/java/com/bubble/house/web/controller/HomeController.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.springframework.web.bind.annotation.GetMapping;
66

77
/**
8-
* 首页
8+
* 首页和功能性页面接口定义
99
*
1010
* @author wugang
1111
* date: 2019-11-04 14:45
@@ -48,9 +48,11 @@ public String internalError() {
4848
return "status/500";
4949
}
5050

51+
/**
52+
* 登出 注销页面
53+
*/
5154
@GetMapping("/logout/page")
5255
public String logoutPage() {
53-
// 登出页面
5456
return "logout";
5557
}
5658

‎src/main/java/com/bubble/house/web/controller/AdminController.java ‎src/main/java/com/bubble/house/web/controller/admin/AdminController.java

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.bubble.house.web.controller;
1+
package com.bubble.house.web.controller.admin;
22

33
import com.alibaba.fastjson.JSONObject;
44
import com.bubble.house.base.api.ApiDataTableResponse;
@@ -10,8 +10,8 @@
1010
import com.bubble.house.entity.house.*;
1111
import com.bubble.house.entity.param.DatatableSearchParam;
1212
import com.bubble.house.entity.param.HouseParam;
13-
import com.bubble.house.entity.result.MultiResultEntity;
14-
import com.bubble.house.entity.result.ResultEntity;
13+
import com.bubble.house.entity.result.ServiceMultiResultEntity;
14+
import com.bubble.house.entity.result.ServiceResultEntity;
1515
import com.bubble.house.service.house.AddressService;
1616
import com.bubble.house.service.house.HouseService;
1717
import com.bubble.house.service.house.QiNiuService;
@@ -34,7 +34,7 @@
3434
import java.util.Map;
3535

3636
/**
37-
* 后台管理中心
37+
* 角色为Admin:Admin用户的后台管理中心
3838
*
3939
* @author wugang
4040
* date: 2019-11-05 11:32
@@ -43,6 +43,9 @@
4343
public class AdminController {
4444
private final static Logger LOGGER = LoggerFactory.getLogger(AdminController.class);
4545

46+
/**
47+
* 图片上传到本地的文件路径
48+
*/
4649
@Value("${spring.http.multipart.location}")
4750
private String imageLocation;
4851

@@ -103,7 +106,7 @@ public String houseListPage() {
103106
@ResponseBody
104107
public ApiDataTableResponse houses(@ModelAttribute DatatableSearchParam searchBody) {
105108
LOGGER.debug("进入房源信息展示接口:[admin/houses]");
106-
MultiResultEntity<HouseDTO> result = houseService.adminQuery(searchBody);
109+
ServiceMultiResultEntity<HouseDTO> result = houseService.adminQuery(searchBody);
107110
ApiDataTableResponse response = new ApiDataTableResponse(ApiStatus.SUCCESS);
108111
response.setData(result.getResult());
109112
response.setRecordsFiltered(result.getTotal());
@@ -140,7 +143,7 @@ public ApiResponse addHouse(@Valid @ModelAttribute("form-house-add") HouseParam
140143
return ApiResponse.ofStatus(ApiStatus.NOT_VALID_PARAM);
141144
}
142145

143-
ResultEntity<HouseDTO> result = this.houseService.save(houseParam);
146+
ServiceResultEntity<HouseDTO> result = this.houseService.save(houseParam);
144147
if (result.isSuccess()) {
145148
return ApiResponse.ofSuccess(result.getResult());
146149
}
@@ -156,7 +159,7 @@ public String houseEditPage(@RequestParam(value = "id") Long id, Model model) {
156159
if (id == null || id < 1) {
157160
return "status/404";
158161
}
159-
ResultEntity<HouseDTO> serviceResult = houseService.findCompleteOne(id);
162+
ServiceResultEntity<HouseDTO> serviceResult = houseService.findCompleteOne(id);
160163
if (!serviceResult.isSuccess()) {
161164
return "status/404";
162165
}
@@ -168,12 +171,12 @@ public String houseEditPage(@RequestParam(value = "id") Long id, Model model) {
168171
model.addAttribute("region", addressMap.get(CityLevel.REGION));
169172

170173
HouseDetailDTO detailDTO = result.getHouseDetail();
171-
ResultEntity<SubwayEntity> subwayServiceResult = addressService.findSubway(detailDTO.getSubwayLineId());
174+
ServiceResultEntity<SubwayEntity> subwayServiceResult = addressService.findSubway(detailDTO.getSubwayLineId());
172175
if (subwayServiceResult.isSuccess()) {
173176
model.addAttribute("subway", subwayServiceResult.getResult());
174177
}
175178

176-
ResultEntity<SubwayStationEntity> subwayStationServiceResult = addressService.findSubwayStation(detailDTO.getSubwayStationId());
179+
ServiceResultEntity<SubwayStationEntity> subwayStationServiceResult = addressService.findSubwayStation(detailDTO.getSubwayStationId());
177180
if (subwayStationServiceResult.isSuccess()) {
178181
model.addAttribute("station", subwayStationServiceResult.getResult());
179182
}
@@ -195,7 +198,7 @@ public ApiResponse saveHouse(@Valid @ModelAttribute("form-house-edit") HousePara
195198
return ApiResponse.ofSuccess(ApiStatus.NOT_VALID_PARAM);
196199
}
197200

198-
ResultEntity result = houseService.update(houseParam);
201+
ServiceResultEntity result = houseService.update(houseParam);
199202
if (result.isSuccess()) {
200203
return ApiResponse.ofSuccess(null);
201204
}
@@ -244,7 +247,7 @@ public ApiResponse uploadPhoto(@RequestParam("file") MultipartFile file) {
244247
public ApiResponse removeHousePhoto(@RequestParam(value = "id") Long id) {
245248
LOGGER.debug("进入图片删除接口:[admin/house/photo]");
246249

247-
ResultEntity result = this.houseService.removePhoto(id);
250+
ServiceResultEntity result = this.houseService.removePhoto(id);
248251
if (result.isSuccess()) {
249252
return ApiResponse.ofStatus(ApiStatus.SUCCESS);
250253
} else {
@@ -261,7 +264,7 @@ public ApiResponse updateCover(@RequestParam(value = "cover_id") Long coverId,
261264
@RequestParam(value = "target_id") Long targetId) {
262265
LOGGER.debug("进入修改房源封面接口:[admin/house/cover]");
263266

264-
ResultEntity result = this.houseService.updateCover(coverId, targetId);
267+
ServiceResultEntity result = this.houseService.updateCover(coverId, targetId);
265268

266269
if (result.isSuccess()) {
267270
return ApiResponse.ofStatus(ApiStatus.SUCCESS);
@@ -282,7 +285,7 @@ public ApiResponse addHouseTag(@RequestParam(value = "house_id") Long houseId,
282285
if (houseId < 1 || Strings.isNullOrEmpty(tag)) {
283286
return ApiResponse.ofStatus(ApiStatus.BAD_REQUEST);
284287
}
285-
ResultEntity result = this.houseService.addTag(houseId, tag);
288+
ServiceResultEntity result = this.houseService.addTag(houseId, tag);
286289
if (result.isSuccess()) {
287290
return ApiResponse.ofStatus(ApiStatus.SUCCESS);
288291
} else {
@@ -303,7 +306,7 @@ public ApiResponse removeHouseTag(@RequestParam(value = "house_id") Long houseId
303306
return ApiResponse.ofStatus(ApiStatus.BAD_REQUEST);
304307
}
305308

306-
ResultEntity result = this.houseService.removeTag(houseId, tag);
309+
ServiceResultEntity result = this.houseService.removeTag(houseId, tag);
307310
if (result.isSuccess()) {
308311
return ApiResponse.ofStatus(ApiStatus.SUCCESS);
309312
} else {
@@ -323,7 +326,7 @@ public ApiResponse operateHouse(@PathVariable(value = "id") Long id,
323326
if (id <= 0) {
324327
return ApiResponse.ofStatus(ApiStatus.NOT_VALID_PARAM);
325328
}
326-
ResultEntity result;
329+
ServiceResultEntity result;
327330
switch (operation) {
328331
case HouseOperation.PASS:
329332
result = this.houseService.updateStatus(id, HouseStatus.PASSES.getValue());

‎src/main/java/com/bubble/house/web/controller/HouseController.java ‎src/main/java/com/bubble/house/web/controller/house/HouseController.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.bubble.house.web.controller;
1+
package com.bubble.house.web.controller.house;
22

33
import com.bubble.house.base.api.ApiResponse;
44
import com.bubble.house.base.api.ApiStatus;
@@ -9,8 +9,8 @@
99
import com.bubble.house.entity.house.SubwayEntity;
1010
import com.bubble.house.entity.house.SubwayStationEntity;
1111
import com.bubble.house.entity.param.RentSearchParam;
12-
import com.bubble.house.entity.result.MultiResultEntity;
13-
import com.bubble.house.entity.result.ResultEntity;
12+
import com.bubble.house.entity.result.ServiceMultiResultEntity;
13+
import com.bubble.house.entity.result.ServiceResultEntity;
1414
import com.bubble.house.entity.search.HouseBucketEntity;
1515
import com.bubble.house.entity.search.MapSearchEntity;
1616
import com.bubble.house.entity.search.RentValueBlockEntity;
@@ -56,7 +56,7 @@ public HouseController(AddressService addressService, HouseService houseService,
5656
@GetMapping("address/support/cities")
5757
@ResponseBody
5858
public ApiResponse getSupportCity() {
59-
MultiResultEntity<CityEntity> result = addressService.findAllCities();
59+
ServiceMultiResultEntity<CityEntity> result = addressService.findAllCities();
6060
if (result.getResultSize() == 0) {
6161
return ApiResponse.ofStatus(ApiStatus.NOT_FOUND);
6262
}
@@ -69,7 +69,7 @@ public ApiResponse getSupportCity() {
6969
@GetMapping("address/support/regions")
7070
@ResponseBody
7171
public ApiResponse getSupportRegions(@RequestParam(name = "city_name") String cityEnName) {
72-
MultiResultEntity<CityEntity> addressResult = addressService.findAllRegionsByCityEnName(cityEnName);
72+
ServiceMultiResultEntity<CityEntity> addressResult = addressService.findAllRegionsByCityEnName(cityEnName);
7373
if (addressResult.getResult() == null || addressResult.getTotal() < 1) {
7474
return ApiResponse.ofStatus(ApiStatus.NOT_FOUND);
7575
}
@@ -122,21 +122,21 @@ public String rentHousePage(@ModelAttribute RentSearchParam rentSearch,
122122
session.setAttribute("cityEnName", rentSearch.getCityEnName());
123123
}
124124
// 获取城市信息
125-
ResultEntity<CityEntity> city = addressService.findCity(rentSearch.getCityEnName());
125+
ServiceResultEntity<CityEntity> city = addressService.findCity(rentSearch.getCityEnName());
126126
if (!city.isSuccess()) {
127127
redirectAttributes.addAttribute("msg", "must_chose_city");
128128
// 跳转到index.html页面
129129
return "redirect:/index";
130130
}
131131
model.addAttribute("currentCity", city.getResult());
132132

133-
MultiResultEntity<CityEntity> addressResult = addressService.findAllRegionsByCityEnName(rentSearch.getCityEnName());
133+
ServiceMultiResultEntity<CityEntity> addressResult = addressService.findAllRegionsByCityEnName(rentSearch.getCityEnName());
134134
if (addressResult.getResult() == null || addressResult.getTotal() < 1) {
135135
redirectAttributes.addAttribute("msg", "must_chose_city");
136136
return "redirect:/index";
137137
}
138138

139-
MultiResultEntity<HouseDTO> serviceMultiResult = houseService.query(rentSearch);
139+
ServiceMultiResultEntity<HouseDTO> serviceMultiResult = houseService.query(rentSearch);
140140

141141
// 添加视图信息
142142
model.addAttribute("total", serviceMultiResult.getTotal());
@@ -171,7 +171,7 @@ public ApiResponse autocomplete(@RequestParam(value = "prefix") String prefix) {
171171
if (prefix.isEmpty()) {
172172
return ApiResponse.ofStatus(ApiStatus.BAD_REQUEST);
173173
}
174-
ResultEntity<List<String>> result = this.searchService.suggest(prefix);
174+
ServiceResultEntity<List<String>> result = this.searchService.suggest(prefix);
175175
return ApiResponse.ofSuccess(result.getResult());
176176
}
177177

@@ -184,7 +184,7 @@ public String show(@PathVariable(value = "id") Long houseId,
184184
if (houseId <= 0) {
185185
return "status/404";
186186
}
187-
ResultEntity<HouseDTO> serviceResult = houseService.findCompleteOne(houseId);
187+
ServiceResultEntity<HouseDTO> serviceResult = houseService.findCompleteOne(houseId);
188188
if (!serviceResult.isSuccess()) {
189189
return "status/404";
190190
}
@@ -196,12 +196,12 @@ public String show(@PathVariable(value = "id") Long houseId,
196196
model.addAttribute("city", city);
197197
model.addAttribute("region", region);
198198

199-
ResultEntity<UserDTO> userDTOServiceResult = userService.findById(houseDTO.getAdminId());
199+
ServiceResultEntity<UserDTO> userDTOServiceResult = userService.findById(houseDTO.getAdminId());
200200
// 经纪人
201201
model.addAttribute("agent", userDTOServiceResult.getResult());
202202
model.addAttribute("house", houseDTO);
203203
// 聚合数据:房源信息在小区中的数量
204-
ResultEntity<Long> aggResult = searchService.aggregateDistrictHouse(city.getEnName(), region.getEnName(), houseDTO.getDistrict());
204+
ServiceResultEntity<Long> aggResult = searchService.aggregateDistrictHouse(city.getEnName(), region.getEnName(), houseDTO.getDistrict());
205205
model.addAttribute("houseCountInDistrict", aggResult.getResult());
206206
// model.addAttribute("houseCountInDistrict", 0);
207207
return "house-detail";
@@ -213,17 +213,17 @@ public String show(@PathVariable(value = "id") Long houseId,
213213
@GetMapping("rent/house/map")
214214
public String rentMapPage(@RequestParam(value = "cityEnName") String cityEnName, Model model,
215215
HttpSession session, RedirectAttributes redirectAttributes) {
216-
ResultEntity<CityEntity> city = addressService.findCity(cityEnName);
216+
ServiceResultEntity<CityEntity> city = addressService.findCity(cityEnName);
217217
if (!city.isSuccess()) {
218218
redirectAttributes.addAttribute("msg", "must_chose_city");
219219
return "redirect:/index";
220220
} else {
221221
session.setAttribute("cityName", cityEnName);
222222
model.addAttribute("city", city.getResult());
223223
}
224-
MultiResultEntity<CityEntity> regions = addressService.findAllRegionsByCityEnName(cityEnName);
224+
ServiceMultiResultEntity<CityEntity> regions = addressService.findAllRegionsByCityEnName(cityEnName);
225225

226-
MultiResultEntity<HouseBucketEntity> serviceResult = searchService.mapAggregate(cityEnName);
226+
ServiceMultiResultEntity<HouseBucketEntity> serviceResult = searchService.mapAggregate(cityEnName);
227227

228228
model.addAttribute("aggData", serviceResult.getResult());
229229
model.addAttribute("total", serviceResult.getTotal());
@@ -240,7 +240,7 @@ public ApiResponse rentMapHouses(@ModelAttribute MapSearchEntity mapSearch) {
240240
if (mapSearch.getCityEnName() == null) {
241241
return ApiResponse.ofMessage(HttpStatus.BAD_REQUEST.value(), "必须选择城市");
242242
}
243-
MultiResultEntity<HouseDTO> serviceMultiResult;
243+
ServiceMultiResultEntity<HouseDTO> serviceMultiResult;
244244
if (mapSearch.getLevel() < 13) {
245245
serviceMultiResult = houseService.wholeMapQuery(mapSearch);
246246
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.bubble.house.web.controller.user;
2+
3+
import com.bubble.house.base.LoginUserUtil;
4+
import com.bubble.house.base.api.ApiResponse;
5+
import com.bubble.house.base.api.ApiStatus;
6+
import com.bubble.house.entity.result.ServiceResultEntity;
7+
import com.bubble.house.service.house.HouseService;
8+
import com.bubble.house.service.house.SubscribeService;
9+
import com.bubble.house.service.user.UserService;
10+
import org.apache.http.HttpStatus;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
import org.springframework.stereotype.Controller;
14+
import org.springframework.web.bind.annotation.GetMapping;
15+
import org.springframework.web.bind.annotation.PostMapping;
16+
import org.springframework.web.bind.annotation.RequestParam;
17+
import org.springframework.web.bind.annotation.ResponseBody;
18+
19+
/**
20+
* 角色为User:一般用户的处理逻辑接口
21+
*
22+
* @author wugang
23+
* date: 2020-10-27 17:48
24+
**/
25+
@Controller
26+
public class UserController {
27+
private final Logger logger = LoggerFactory.getLogger(UserController.class);
28+
29+
private final UserService userService;
30+
private final HouseService houseService;
31+
private final SubscribeService subscribeService;
32+
33+
public UserController(UserService userService, HouseService houseService, SubscribeService subscribeService) {
34+
this.userService = userService;
35+
this.houseService = houseService;
36+
this.subscribeService = subscribeService;
37+
}
38+
39+
/**
40+
* 普通用户登录页面
41+
*/
42+
@GetMapping("/user/login")
43+
public String loginPage() {
44+
return "user/login";
45+
}
46+
47+
/**
48+
* 普通用户管理页面
49+
*/
50+
@GetMapping("/user/center")
51+
public String centerPage() {
52+
return "user/center";
53+
}
54+
55+
@PostMapping(value = "/api/user/info")
56+
@ResponseBody
57+
public ApiResponse updateUserInfo(@RequestParam(value = "profile") String profile, @RequestParam(value = "value") String value) {
58+
if (value.isEmpty()) {
59+
return ApiResponse.ofStatus(ApiStatus.BAD_REQUEST);
60+
}
61+
if ("email".equals(profile) && !LoginUserUtil.checkEmail(value)) {
62+
return ApiResponse.ofMessage(HttpStatus.SC_BAD_REQUEST, "不支持的邮箱格式");
63+
}
64+
ServiceResultEntity result = userService.modifyUserProfile(profile, value);
65+
if (result.isSuccess()) {
66+
return ApiResponse.ofSuccess("");
67+
} else {
68+
return ApiResponse.ofMessage(HttpStatus.SC_BAD_REQUEST, result.getMessage());
69+
}
70+
}
71+
72+
/**
73+
* 加入预约清单
74+
*
75+
* @param houseId 房源ID
76+
* @return ApiResponse
77+
*/
78+
@PostMapping(value = "api/user/house/subscribe")
79+
@ResponseBody
80+
public ApiResponse subscribeHouse(@RequestParam(value = "house_id") Long houseId) {
81+
ServiceResultEntity result = subscribeService.addSubscribeOrder(houseId);
82+
if (result.isSuccess()) {
83+
return ApiResponse.ofSuccess("");
84+
} else {
85+
return ApiResponse.ofMessage(HttpStatus.SC_BAD_REQUEST, result.getMessage());
86+
}
87+
}
88+
89+
}

‎src/main/resources/application.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ spring:
2626
force: true
2727
charset: UTF-8
2828
enabled: true
29-
# multipart config
29+
# 文件上传 multipart config
3030
multipart:
3131
enabled: true
3232
location: /Users/wugang/code/java/elasticsearch-house/tmp/images/

‎src/main/resources/log4j2.xml

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
</Appenders>
7171

7272
<Loggers>
73+
<logger name="org" level="info"/>
7374
<logger name="org.springframework" level="INFO"/>
7475
<logger name="com.zaxxer" level="INFO"/>
7576
<logger name="org.hibernate" level="INFO"/>

‎src/main/resources/static/js/admin/upload.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@
216216
// 当有文件添加进来时执行,负责view的创建
217217
function addFile(file) {
218218
var $li = $('<li id="' + file.id + '">' +
219-
'<p class="title">' + file.name + '</p>' +
220-
'<p class="imgWrap"></p>' +
221-
'<p class="progress"><span></span></p>' +
222-
'</li>'),
219+
'<p class="title">' + file.name + '</p>' +
220+
'<p class="imgWrap"></p>' +
221+
'<p class="progress"><span></span></p>' +
222+
'</li>'),
223223

224224
$btns = $('<div class="file-panel">' +
225225
'<span class="cancel">删除</span>' +

‎src/main/resources/templates/admin/login.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<!DOCTYPE HTML>
22
<html xmlns:th="http://www.thymeleaf.org">
33
<head>
4-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
55

66
<title>房搜搜-后台登录系统</title>
77

88
<!--- CSS --->
9-
<link rel="stylesheet" href="/static/css/admin/login-style.css" type="text/css" />
9+
<link rel="stylesheet" href="/static/css/admin/login-style.css" type="text/css"/>
1010

1111

1212
<!--- Javascript libraries (jQuery and Selectivizr) used for the custom checkbox --->
1313

1414
<!--[if (gte IE 6)&(lte IE 8)]>
1515
<script type="text/javascript" src="/static/lib/jquery/1.9.1/jquery.js"></script>
1616
<script type="text/javascript" src="/static/js/admin/selectivizr.js"></script>
17-
<noscript><link rel="stylesheet" href="/static/css/admin/login-fallback.css" /></noscript>
17+
<noscript>
18+
<link rel="stylesheet" href="/static/css/admin/login-fallback.css"/>
19+
</noscript>
1820
<![endif]-->
1921

2022
</head>
@@ -23,7 +25,7 @@
2325
<div id="container">
2426
<form action="#" th:action="@{/login}" method="post">
2527
<div class="login">管理员登录</div>
26-
<div th:if="${param.error}" style="position: absolute; color: red; padding-top: 6%; padding-left: 3%">
28+
<div th:if="${param.error}" style="position: absolute; color: #ff0000; padding-top: 6%; padding-left: 3%">
2729
非法的用户名或密码
2830
</div>
2931
<div class="username-text">用户名:</div>
@@ -32,7 +34,7 @@
3234
<input type="text" name="username" placeholder="请输入用户名"/>
3335
</div>
3436
<div class="password-field">
35-
<input type="password" name="password" placeholder="请输入密码" />
37+
<input type="password" name="password" placeholder="请输入密码"/>
3638
</div>
3739

3840

‎src/test/java/com/bubble/house/AddressServiceTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.bubble.house;
22

33
import com.bubble.house.entity.BaiDuMapEntity;
4-
import com.bubble.house.entity.result.ResultEntity;
4+
import com.bubble.house.entity.result.ServiceResultEntity;
55
import com.bubble.house.service.house.AddressService;
66
import org.junit.jupiter.api.Assertions;
77
import org.junit.jupiter.api.Test;
@@ -23,7 +23,7 @@ public class AddressServiceTests extends ApplicationTests {
2323
public void testGetMapLocation() {
2424
String city = "北京";
2525
String address = "望京SOHO";
26-
ResultEntity<BaiDuMapEntity> result = addressService.getBaiDuMapLocation(city, address);
26+
ServiceResultEntity<BaiDuMapEntity> result = addressService.getBaiDuMapLocation(city, address);
2727
System.out.println(result.getResult().getLongitude());
2828
System.out.println(result.getResult().getLatitude());
2929

0 commit comments

Comments
 (0)
Please sign in to comment.