weiximei 6 years ago
parent
commit
1e111d84ee

+ 5
- 5
whole-estate/pom.xml View File

42
             <optional>true</optional>
42
             <optional>true</optional>
43
         </dependency>
43
         </dependency>
44
 
44
 
45
-        <dependency>
46
-            <groupId>org.springframework.session</groupId>
47
-            <artifactId>spring-session-jdbc</artifactId>
48
-            <version>2.1.3.RELEASE</version>
49
-        </dependency>
45
+        <!--<dependency>-->
46
+            <!--<groupId>org.springframework.session</groupId>-->
47
+            <!--<artifactId>spring-session-jdbc</artifactId>-->
48
+            <!--<version>2.1.3.RELEASE</version>-->
49
+        <!--</dependency>-->
50
 
50
 
51
 
51
 
52
         <!-- 测试 -->
52
         <!-- 测试 -->

+ 3
- 1
whole-estate/src/main/java/com/example/wholeestate/common/Constant.java View File

6
 public class Constant {
6
 public class Constant {
7
 
7
 
8
 
8
 
9
-    public static final String REQUEST_ERROR = "500";
9
+    public static final Integer REQUEST_ERROR = 500;
10
+
11
+    public static final Integer NOT_SESSION_USER = 401;
10
 
12
 
11
     /**
13
     /**
12
      * 用户 session
14
      * 用户 session

+ 8
- 0
whole-estate/src/main/java/com/example/wholeestate/common/base/BaseController.java View File

36
         return sysUser;
36
         return sysUser;
37
     }
37
     }
38
 
38
 
39
+    /**
40
+     * 移除 session 用户
41
+     * @param session
42
+     */
43
+    protected void removeSessionUser(HttpSession session) {
44
+        session.removeAttribute(Constant.USER_SESSION);
45
+    }
46
+
39
 }
47
 }

+ 9
- 9
whole-estate/src/main/java/com/example/wholeestate/common/resp/ResponseBean.java View File

9
 
9
 
10
     private static final long serialVersionUID = 3593827217136880822L;
10
     private static final long serialVersionUID = 3593827217136880822L;
11
 
11
 
12
-    public static final String CODE_SUCCESS =  "0";
13
-    public static final String CODE_FAIL =  "1";
12
+    public static final Integer CODE_SUCCESS =  200;
13
+    public static final Integer CODE_FAIL =  400;
14
 
14
 
15
-    private String code = "0";
15
+    private Integer code = 200;
16
 
16
 
17
     private String message = "成功";
17
     private String message = "成功";
18
 
18
 
22
     }
22
     }
23
 
23
 
24
     public void addDefaultError() {
24
     public void addDefaultError() {
25
-        this.code = "1";
25
+        this.code = 400;
26
         this.message = "失败";
26
         this.message = "失败";
27
     }
27
     }
28
 
28
 
29
     public void addError(String message) {
29
     public void addError(String message) {
30
-        this.code = "1";
30
+        this.code = 400;
31
         this.message = message;
31
         this.message = message;
32
     }
32
     }
33
 
33
 
34
-    public void addError(String code, String message) {
34
+    public void addError(Integer code, String message) {
35
         this.code = code;
35
         this.code = code;
36
         this.message = message;
36
         this.message = message;
37
     }
37
     }
38
 
38
 
39
     public void addSuccess(String message) {
39
     public void addSuccess(String message) {
40
-        this.code = "0";
40
+        this.code = 200;
41
         this.message = message;
41
         this.message = message;
42
     }
42
     }
43
 
43
 
44
     public void addSuccess(T data) {
44
     public void addSuccess(T data) {
45
-        this.code = "0";
45
+        this.code = 200;
46
         this.message = "成功";
46
         this.message = "成功";
47
         this.data = data;
47
         this.data = data;
48
     }
48
     }
51
         return this.data;
51
         return this.data;
52
     }
52
     }
53
 
53
 
54
-    public String getCode() {
54
+    public Integer getCode() {
55
         return this.code;
55
         return this.code;
56
     }
56
     }
57
 
57
 

+ 9
- 9
whole-estate/src/main/java/com/example/wholeestate/config/SessionConfig.java View File

2
 
2
 
3
 import org.springframework.context.annotation.Bean;
3
 import org.springframework.context.annotation.Bean;
4
 import org.springframework.context.annotation.Configuration;
4
 import org.springframework.context.annotation.Configuration;
5
-import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession;
6
-import org.springframework.session.web.http.HeaderHttpSessionIdResolver;
7
-import org.springframework.session.web.http.HttpSessionIdResolver;
5
+//import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession;
6
+//import org.springframework.session.web.http.HeaderHttpSessionIdResolver;
7
+//import org.springframework.session.web.http.HttpSessionIdResolver;
8
 
8
 
9
 /**
9
 /**
10
  * session 配置
10
  * session 配置
11
  * @author weiximei
11
  * @author weiximei
12
  */
12
  */
13
- @Configuration
14
- @EnableJdbcHttpSession
13
+// @Configuration
14
+// @EnableJdbcHttpSession
15
 public class SessionConfig {
15
 public class SessionConfig {
16
 
16
 
17
-    @Bean
18
-    public HttpSessionIdResolver httpSessionIdResolver() {
19
-        return HeaderHttpSessionIdResolver.xAuthToken();
20
-    }
17
+//    @Bean
18
+//    public HttpSessionIdResolver httpSessionIdResolver() {
19
+//        return HeaderHttpSessionIdResolver.xAuthToken();
20
+//    }
21
 
21
 
22
 }
22
 }

+ 2
- 8
whole-estate/src/main/java/com/example/wholeestate/controller/ActivityController.java View File

63
     @RequestMapping(value = "/activity/add", method = RequestMethod.POST)
63
     @RequestMapping(value = "/activity/add", method = RequestMethod.POST)
64
     @ApiOperation(value = "添加活动", notes = "添加活动")
64
     @ApiOperation(value = "添加活动", notes = "添加活动")
65
     @ApiImplicitParams({
65
     @ApiImplicitParams({
66
-            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "title活动标题;activityDate活动时间;beginDate活动开始时间;endDate活动截止时间;maxNum人数限制;context内容;imgUrl图片地址"),
67
-//            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
66
+            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "title活动标题;activityDate活动时间;beginDate活动开始时间;endDate活动截止时间;maxNum人数限制;context内容;imgUrl图片地址")
68
     })
67
     })
69
     public ResponseBean add(@RequestBody String parameter) {
68
     public ResponseBean add(@RequestBody String parameter) {
70
         ResponseBean responseBean = new ResponseBean();
69
         ResponseBean responseBean = new ResponseBean();
77
     @RequestMapping(value = "/activity/update", method = RequestMethod.PUT)
76
     @RequestMapping(value = "/activity/update", method = RequestMethod.PUT)
78
     @ApiOperation(value = "修改活动", notes = "修改活动")
77
     @ApiOperation(value = "修改活动", notes = "修改活动")
79
     @ApiImplicitParams({
78
     @ApiImplicitParams({
80
-            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "activityId活动编号;title活动标题;activityDate活动时间;beginDate活动开始时间;endDate活动截止时间;maxNum人数限制;context内容;imgUrl图片地址"),
81
-//            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
79
+            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "activityId活动编号;title活动标题;activityDate活动时间;beginDate活动开始时间;endDate活动截止时间;maxNum人数限制;context内容;imgUrl图片地址")
82
     })
80
     })
83
     public ResponseBean update(@RequestBody String parameter) {
81
     public ResponseBean update(@RequestBody String parameter) {
84
         ResponseBean responseBean = new ResponseBean();
82
         ResponseBean responseBean = new ResponseBean();
91
 
89
 
92
     @RequestMapping(value = "/activity/delete/{activityId}", method = RequestMethod.DELETE)
90
     @RequestMapping(value = "/activity/delete/{activityId}", method = RequestMethod.DELETE)
93
     @ApiOperation(value = "删除活动", notes = "删除活动")
91
     @ApiOperation(value = "删除活动", notes = "删除活动")
94
-    @ApiImplicitParams({
95
-//            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
96
-    })
97
     public ResponseBean delete(@PathVariable String activityId) {
92
     public ResponseBean delete(@PathVariable String activityId) {
98
         ResponseBean responseBean = new ResponseBean();
93
         ResponseBean responseBean = new ResponseBean();
99
         Activity activity = iActivityService.getById(activityId);
94
         Activity activity = iActivityService.getById(activityId);
114
     @ApiOperation(value = "根据活动id查询活动报名列表", notes = "根据活动id查询活动报名列表")
109
     @ApiOperation(value = "根据活动id查询活动报名列表", notes = "根据活动id查询活动报名列表")
115
     @ApiImplicitParams({
110
     @ApiImplicitParams({
116
             @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "pageNum第几页;pageSize一页多少行")
111
             @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "pageNum第几页;pageSize一页多少行")
117
-//            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
118
     })
112
     })
119
     public ResponseBean activityEnrollList(@PathVariable("activityId") String activityId, @RequestBody String parameter) {
113
     public ResponseBean activityEnrollList(@PathVariable("activityId") String activityId, @RequestBody String parameter) {
120
         ResponseBean responseBean = new ResponseBean();
114
         ResponseBean responseBean = new ResponseBean();

+ 2
- 0
whole-estate/src/main/java/com/example/wholeestate/controller/CommentController.java View File

60
         return responseBean;
60
         return responseBean;
61
     }
61
     }
62
 
62
 
63
+
64
+
63
 }
65
 }

+ 18
- 0
whole-estate/src/main/java/com/example/wholeestate/controller/SysUserController.java View File

47
         return responseBean;
47
         return responseBean;
48
     }
48
     }
49
 
49
 
50
+    @RequestMapping(value = "/user/loginOut", method = RequestMethod.GET)
51
+    @ApiOperation(value = "退出登陆", notes = "退出登陆")
52
+    public ResponseBean loginOut(HttpSession session) {
53
+        ResponseBean responseBean = new ResponseBean();
54
+        removeSessionUser(session);
55
+        responseBean.addSuccess("退出登陆成功!");
56
+        return responseBean;
57
+    }
58
+
59
+    @RequestMapping(value = "/user/info", method = RequestMethod.GET)
60
+    @ApiOperation(value = "获取登陆的用户信息", notes = "获取登陆的用户信息")
61
+    public ResponseBean loginInfo(HttpSession session) {
62
+        ResponseBean responseBean = new ResponseBean();
63
+        SysUser sessionUser = getSessionUser(session);
64
+        responseBean.addSuccess(sessionUser);
65
+        return responseBean;
66
+    }
67
+
50
 }
68
 }

+ 6
- 1
whole-estate/src/main/java/com/example/wholeestate/exception/ExceptionHandleAdice.java View File

34
     public ResponseBean handleException(WholeEstateException e) {
34
     public ResponseBean handleException(WholeEstateException e) {
35
         log.error(e.getMessage(),e);
35
         log.error(e.getMessage(),e);
36
         ResponseBean response = new ResponseBean();
36
         ResponseBean response = new ResponseBean();
37
-        response.addError(e.getMessage());
37
+        String message = e.getMessage();
38
+        if (message.equals("用户 session 不存在!")) {
39
+            response.addError(Constant.NOT_SESSION_USER, message);
40
+            return response;
41
+        }
42
+        response.addError(message);
38
         return response;
43
         return response;
39
     }
44
     }
40
 
45
 

+ 1
- 1
whole-estate/src/main/java/com/example/wholeestate/service/IActivityEnrollService.java View File

15
 public interface IActivityEnrollService extends IService<ActivityEnroll> {
15
 public interface IActivityEnrollService extends IService<ActivityEnroll> {
16
 
16
 
17
     /**
17
     /**
18
-     * 活动报名
18
+     * 根据活动id 查询 活动报名列表
19
      * @param parameter
19
      * @param parameter
20
      * @return
20
      * @return
21
      */
21
      */

+ 2
- 2
whole-estate/src/main/java/com/example/wholeestate/service/ICommentService.java View File

3
 import com.baomidou.mybatisplus.extension.service.IService;
3
 import com.baomidou.mybatisplus.extension.service.IService;
4
 import com.example.wholeestate.common.resp.ResponseBean;
4
 import com.example.wholeestate.common.resp.ResponseBean;
5
 import com.example.wholeestate.model.Comment;
5
 import com.example.wholeestate.model.Comment;
6
+import com.example.wholeestate.model.SysUser;
6
 
7
 
7
 /**
8
 /**
8
  * <p>
9
  * <p>
16
 
17
 
17
     /**
18
     /**
18
      * 回复评论
19
      * 回复评论
19
-     * @param commentId
20
      * @param parameter
20
      * @param parameter
21
      * @return
21
      * @return
22
      */
22
      */
23
-    ResponseBean addComment(String commentId, String parameter);
23
+    ResponseBean addComment(SysUser user, String parameter);
24
 
24
 
25
 }
25
 }

+ 32
- 1
whole-estate/src/main/java/com/example/wholeestate/service/impl/CommentServiceImpl.java View File

1
 package com.example.wholeestate.service.impl;
1
 package com.example.wholeestate.service.impl;
2
 
2
 
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
 import com.example.wholeestate.common.resp.ResponseBean;
6
 import com.example.wholeestate.common.resp.ResponseBean;
5
 import com.example.wholeestate.dao.CommentMapper;
7
 import com.example.wholeestate.dao.CommentMapper;
8
+import com.example.wholeestate.dao.CustomerMapper;
6
 import com.example.wholeestate.model.Activity;
9
 import com.example.wholeestate.model.Activity;
7
 import com.example.wholeestate.model.Comment;
10
 import com.example.wholeestate.model.Comment;
11
+import com.example.wholeestate.model.Customer;
12
+import com.example.wholeestate.model.SysUser;
8
 import com.example.wholeestate.service.ICommentService;
13
 import com.example.wholeestate.service.ICommentService;
14
+import org.apache.commons.lang.StringUtils;
15
+import org.springframework.beans.factory.annotation.Autowired;
9
 import org.springframework.stereotype.Service;
16
 import org.springframework.stereotype.Service;
10
 
17
 
18
+import java.time.LocalDateTime;
19
+
11
 /**
20
 /**
12
  * <p>
21
  * <p>
13
  * 评论表 服务实现类
22
  * 评论表 服务实现类
19
 @Service
28
 @Service
20
 public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {
29
 public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {
21
 
30
 
31
+    @Autowired
32
+    private CommentMapper commentMapper;
33
+
34
+    @Autowired
35
+    private CustomerMapper customerMapper;
36
+
22
     @Override
37
     @Override
23
-    public ResponseBean addComment(String commentId, String parameter) {
38
+    public ResponseBean addComment(SysUser user, String parameter) {
24
         ResponseBean responseBean = new ResponseBean();
39
         ResponseBean responseBean = new ResponseBean();
40
+        Comment comment = JSONObject.parseObject(parameter, Comment.class);
41
+        comment.setCreateDate(LocalDateTime.now());
42
+        comment.setStatus(1);
25
 
43
 
44
+        QueryWrapper<Customer> customerQueryWrapper = new QueryWrapper<>();
45
+        customerQueryWrapper.eq("customer_id", comment.getCustomerId());
46
+        Customer customer = customerMapper.selectOne(customerQueryWrapper);
47
+        if (null == customer) {
48
+            responseBean.addError("用户不存在!");
49
+            return responseBean;
50
+        }
26
 
51
 
52
+        int insert = commentMapper.insert(comment);
53
+        if (insert <= 0) {
54
+            responseBean.addError("评论失败!");
55
+            return responseBean;
56
+        }
57
+        responseBean.addSuccess("评论成功!");
27
         return responseBean;
58
         return responseBean;
28
     }
59
     }
29
 }
60
 }

+ 51
- 0
whole-estate/src/main/java/com/example/wholeestate/utils/MD5Utils.java View File

1
+package com.example.wholeestate.utils;
2
+
3
+import java.io.UnsupportedEncodingException;
4
+import java.security.MessageDigest;
5
+
6
+/**
7
+ * 用户密码加密
8
+ * Created by Administrator on 2015/8/9.
9
+ */
10
+public class MD5Utils {
11
+    /**
12
+     * MD5加密
13
+     *
14
+     * @param s 字符串
15
+     * @return MD5加密 字符串
16
+     */
17
+    public static String encode(String s) {
18
+        try {
19
+            return encode(s.getBytes("utf-8"));
20
+        } catch (UnsupportedEncodingException e) {
21
+            e.printStackTrace();
22
+        }
23
+        return null;
24
+    }
25
+
26
+    private static String encode(byte[] b) {
27
+        char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
28
+                'a', 'b', 'c', 'd', 'e', 'f'};
29
+        try {
30
+            byte[] strTemp;
31
+            strTemp = b;
32
+            MessageDigest mdTemp = MessageDigest.getInstance("MD5");
33
+            mdTemp.update(strTemp);
34
+            byte[] md = mdTemp.digest();
35
+            int j = md.length;
36
+            char str[] = new char[j * 2];
37
+            int k = 0;
38
+            for (byte byte0 : md) {
39
+                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
40
+                str[k++] = hexDigits[byte0 & 0xf];
41
+            }
42
+            return new String(str);
43
+        } catch (Exception e) {
44
+            return null;
45
+        }
46
+    }
47
+
48
+    public static void main(String[] arge) throws Exception {
49
+       System.out.println(MD5Utils.encode("123456"));
50
+    }
51
+}