dingxin 6 年前
父节点
当前提交
2000e463de
共有 22 个文件被更改,包括 635 次插入35 次删除
  1. 5
    5
      whole-estate/pom.xml
  2. 3
    1
      whole-estate/src/main/java/com/example/wholeestate/common/Constant.java
  3. 8
    0
      whole-estate/src/main/java/com/example/wholeestate/common/base/BaseController.java
  4. 9
    9
      whole-estate/src/main/java/com/example/wholeestate/common/resp/ResponseBean.java
  5. 108
    0
      whole-estate/src/main/java/com/example/wholeestate/common/uuid/IdGen.java
  6. 9
    9
      whole-estate/src/main/java/com/example/wholeestate/config/SessionConfig.java
  7. 80
    4
      whole-estate/src/main/java/com/example/wholeestate/controller/ActivityController.java
  8. 65
    0
      whole-estate/src/main/java/com/example/wholeestate/controller/CommentController.java
  9. 18
    0
      whole-estate/src/main/java/com/example/wholeestate/controller/SysUserController.java
  10. 9
    0
      whole-estate/src/main/java/com/example/wholeestate/dao/ActivityEnrollMapper.java
  11. 1
    0
      whole-estate/src/main/java/com/example/wholeestate/dao/ActivityMapper.java
  12. 16
    0
      whole-estate/src/main/java/com/example/wholeestate/dao/CommentMapper.java
  13. 6
    1
      whole-estate/src/main/java/com/example/wholeestate/exception/ExceptionHandleAdice.java
  14. 24
    0
      whole-estate/src/main/java/com/example/wholeestate/model/Activity.java
  15. 78
    0
      whole-estate/src/main/java/com/example/wholeestate/model/Comment.java
  16. 8
    0
      whole-estate/src/main/java/com/example/wholeestate/service/IActivityEnrollService.java
  17. 1
    1
      whole-estate/src/main/java/com/example/wholeestate/service/IActivityService.java
  18. 25
    0
      whole-estate/src/main/java/com/example/wholeestate/service/ICommentService.java
  19. 35
    0
      whole-estate/src/main/java/com/example/wholeestate/service/impl/ActivityEnrollServiceImpl.java
  20. 16
    5
      whole-estate/src/main/java/com/example/wholeestate/service/impl/ActivityServiceImpl.java
  21. 60
    0
      whole-estate/src/main/java/com/example/wholeestate/service/impl/CommentServiceImpl.java
  22. 51
    0
      whole-estate/src/main/java/com/example/wholeestate/utils/MD5Utils.java

+ 5
- 5
whole-estate/pom.xml 查看文件

@@ -42,11 +42,11 @@
42 42
             <optional>true</optional>
43 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 查看文件

@@ -6,7 +6,9 @@ package com.example.wholeestate.common;
6 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 14
      * 用户 session

+ 8
- 0
whole-estate/src/main/java/com/example/wholeestate/common/base/BaseController.java 查看文件

@@ -36,4 +36,12 @@ public class BaseController {
36 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 查看文件

@@ -9,10 +9,10 @@ public class ResponseBean<T> implements Serializable {
9 9
 
10 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 17
     private String message = "成功";
18 18
 
@@ -22,27 +22,27 @@ public class ResponseBean<T> implements Serializable {
22 22
     }
23 23
 
24 24
     public void addDefaultError() {
25
-        this.code = "1";
25
+        this.code = 400;
26 26
         this.message = "失败";
27 27
     }
28 28
 
29 29
     public void addError(String message) {
30
-        this.code = "1";
30
+        this.code = 400;
31 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 35
         this.code = code;
36 36
         this.message = message;
37 37
     }
38 38
 
39 39
     public void addSuccess(String message) {
40
-        this.code = "0";
40
+        this.code = 200;
41 41
         this.message = message;
42 42
     }
43 43
 
44 44
     public void addSuccess(T data) {
45
-        this.code = "0";
45
+        this.code = 200;
46 46
         this.message = "成功";
47 47
         this.data = data;
48 48
     }
@@ -51,7 +51,7 @@ public class ResponseBean<T> implements Serializable {
51 51
         return this.data;
52 52
     }
53 53
 
54
-    public String getCode() {
54
+    public Integer getCode() {
55 55
         return this.code;
56 56
     }
57 57
 

+ 108
- 0
whole-estate/src/main/java/com/example/wholeestate/common/uuid/IdGen.java 查看文件

@@ -0,0 +1,108 @@
1
+package com.example.wholeestate.common.uuid;
2
+
3
+/**
4
+ * ID 生成策略
5
+ * @author  weiximei
6
+ */
7
+public class IdGen {
8
+
9
+    private long workerId;
10
+    private long datacenterId;
11
+    private long sequence = 0L;
12
+    private long twepoch = 1288834974657L;
13
+    //Thu, 04 Nov 2010 01:42:54 GMT
14
+    private long workerIdBits = 5L;
15
+    //节点ID长度
16
+    private long datacenterIdBits = 5L;
17
+    //数据中心ID长度
18
+    private long maxWorkerId = -1L ^ (-1L << workerIdBits);
19
+    //最大支持机器节点数0~31,一共32个
20
+    private long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
21
+    //最大支持数据中心节点数0~31,一共32个
22
+    private long sequenceBits = 12L;
23
+    //序列号12位
24
+    private long workerIdShift = sequenceBits;
25
+    //机器节点左移12位
26
+    private long datacenterIdShift = sequenceBits + workerIdBits;
27
+    //数据中心节点左移17位
28
+    private long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
29
+    //时间毫秒数左移22位
30
+    private long sequenceMask = -1L ^ (-1L << sequenceBits);
31
+    //最大为4095
32
+    private long lastTimestamp = -1L;
33
+
34
+    private static class IdGenHolder {
35
+        private static final IdGen instance = new IdGen();
36
+    }
37
+
38
+    public static IdGen get(){
39
+        return IdGenHolder.instance;
40
+    }
41
+
42
+    public IdGen() {
43
+        this(0L, 0L);
44
+    }
45
+
46
+    public IdGen(long workerId, long datacenterId) {
47
+        if (workerId > maxWorkerId || workerId < 0) {
48
+            throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
49
+        }
50
+        if (datacenterId > maxDatacenterId || datacenterId < 0) {
51
+            throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
52
+        }
53
+        this.workerId = workerId;
54
+        this.datacenterId = datacenterId;
55
+    }
56
+
57
+    public synchronized long nextId() {
58
+        long timestamp = timeGen();
59
+        //获取当前毫秒数
60
+        //如果服务器时间有问题(时钟后退) 报错。
61
+        if (timestamp < lastTimestamp) {
62
+            throw new RuntimeException(String.format(
63
+                    "Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
64
+        }
65
+        //如果上次生成时间和当前时间相同,在同一毫秒内
66
+        if (lastTimestamp == timestamp) {
67
+            //sequence自增,因为sequence只有12bit,所以和sequenceMask相与一下,去掉高位
68
+            sequence = (sequence + 1) & sequenceMask;
69
+            //判断是否溢出,也就是每毫秒内超过4095,当为4096时,与sequenceMask相与,sequence就等于0
70
+            if (sequence == 0) {
71
+                timestamp = tilNextMillis(lastTimestamp);
72
+                //自旋等待到下一毫秒
73
+            }
74
+        } else {
75
+            sequence = 0L;
76
+            //如果和上次生成时间不同,重置sequence,就是下一毫秒开始,sequence计数重新从0开始累加
77
+        }
78
+        lastTimestamp = timestamp;
79
+        // 最后按照规则拼出ID。
80
+        // 000000000000000000000000000000000000000000  00000            00000       000000000000
81
+        // time                                      datacenterId      workerId     sequence
82
+        // return ((timestamp - twepoch) << timestampLeftShift) | (datacenterId << datacenterIdShift)
83
+        //        | (workerId << workerIdShift) | sequence;
84
+
85
+        long longStr= ((timestamp - twepoch) << timestampLeftShift) | (datacenterId << datacenterIdShift) | (workerId << workerIdShift) | sequence;
86
+        // System.out.println(longStr);
87
+        return longStr;
88
+    }
89
+
90
+    protected long tilNextMillis(long lastTimestamp) {
91
+        long timestamp = timeGen();
92
+        while (timestamp <= lastTimestamp) {
93
+            timestamp = timeGen();
94
+        }
95
+        return timestamp;
96
+    }
97
+
98
+    protected long timeGen() {
99
+        return System.currentTimeMillis();
100
+    }
101
+
102
+
103
+    public static void main(String[] args) {
104
+        IdGen idGen = IdGen.get();
105
+        System.out.println(idGen.nextId());
106
+    }
107
+
108
+}

+ 9
- 9
whole-estate/src/main/java/com/example/wholeestate/config/SessionConfig.java 查看文件

@@ -2,21 +2,21 @@ package com.example.wholeestate.config;
2 2
 
3 3
 import org.springframework.context.annotation.Bean;
4 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 10
  * session 配置
11 11
  * @author weiximei
12 12
  */
13
- @Configuration
14
- @EnableJdbcHttpSession
13
+// @Configuration
14
+// @EnableJdbcHttpSession
15 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
 }

+ 80
- 4
whole-estate/src/main/java/com/example/wholeestate/controller/ActivityController.java 查看文件

@@ -1,18 +1,20 @@
1 1
 package com.example.wholeestate.controller;
2 2
 
3 3
 
4
+import com.alibaba.fastjson.JSONObject;
5
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 6
 import com.example.wholeestate.common.base.BaseController;
5 7
 import com.example.wholeestate.common.resp.ResponseBean;
8
+import com.example.wholeestate.common.uuid.IdGen;
9
+import com.example.wholeestate.model.Activity;
10
+import com.example.wholeestate.service.IActivityEnrollService;
6 11
 import com.example.wholeestate.service.IActivityService;
7 12
 import io.swagger.annotations.Api;
8 13
 import io.swagger.annotations.ApiImplicitParam;
9 14
 import io.swagger.annotations.ApiImplicitParams;
10 15
 import io.swagger.annotations.ApiOperation;
11 16
 import org.springframework.beans.factory.annotation.Autowired;
12
-import org.springframework.web.bind.annotation.RequestBody;
13
-import org.springframework.web.bind.annotation.RequestMapping;
14
-import org.springframework.web.bind.annotation.RequestMethod;
15
-import org.springframework.web.bind.annotation.RestController;
17
+import org.springframework.web.bind.annotation.*;
16 18
 
17 19
 /**
18 20
  * <p>
@@ -27,9 +29,15 @@ import org.springframework.web.bind.annotation.RestController;
27 29
 @Api(value = "活动 API", description = "活动 API")
28 30
 public class ActivityController extends BaseController {
29 31
 
32
+    private IdGen idGen = IdGen.get();
33
+
30 34
     @Autowired
31 35
     private IActivityService iActivityService;
32 36
 
37
+    @Autowired
38
+    private IActivityEnrollService iActivityEnrollService;
39
+
40
+
33 41
     @RequestMapping(value = "/activity/list", method = RequestMethod.POST)
34 42
     @ApiOperation(value = "活动列表", notes = "活动列表")
35 43
     @ApiImplicitParams({
@@ -41,4 +49,72 @@ public class ActivityController extends BaseController {
41 49
         return responseBean;
42 50
     }
43 51
 
52
+    @RequestMapping(value = "/activity/{activityId}", method = RequestMethod.GET)
53
+    @ApiOperation(value = "活动详情", notes = "活动详情")
54
+    @ApiImplicitParams({
55
+            @ApiImplicitParam(paramType = "path", dataTypeClass = String.class, name = "activityId", value = "activityId活动id")
56
+    })
57
+    public ResponseBean getById(@PathVariable String activityId) {
58
+        ResponseBean responseBean = new ResponseBean();
59
+        responseBean = iActivityService.getActivityId(activityId);
60
+        return responseBean;
61
+    }
62
+
63
+    @RequestMapping(value = "/activity/add", method = RequestMethod.POST)
64
+    @ApiOperation(value = "添加活动", notes = "添加活动")
65
+    @ApiImplicitParams({
66
+            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "title活动标题;activityDate活动时间;beginDate活动开始时间;endDate活动截止时间;maxNum人数限制;context内容;imgUrl图片地址")
67
+    })
68
+    public ResponseBean add(@RequestBody String parameter) {
69
+        ResponseBean responseBean = new ResponseBean();
70
+        Activity activity = JSONObject.parseObject(parameter, Activity.class);
71
+        activity.setActivityId(idGen.nextId()+"");
72
+        iActivityService.save(activity);
73
+        return responseBean;
74
+    }
75
+
76
+    @RequestMapping(value = "/activity/update", method = RequestMethod.PUT)
77
+    @ApiOperation(value = "修改活动", notes = "修改活动")
78
+    @ApiImplicitParams({
79
+            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "activityId活动编号;title活动标题;activityDate活动时间;beginDate活动开始时间;endDate活动截止时间;maxNum人数限制;context内容;imgUrl图片地址")
80
+    })
81
+    public ResponseBean update(@RequestBody String parameter) {
82
+        ResponseBean responseBean = new ResponseBean();
83
+        Activity activity = JSONObject.parseObject(parameter, Activity.class);
84
+        QueryWrapper<Activity> activityQueryWrapper = new QueryWrapper<>();
85
+        activityQueryWrapper.eq("activity_id", activity.getActivityId());
86
+        iActivityService.update(activity, activityQueryWrapper);
87
+        return responseBean;
88
+    }
89
+
90
+    @RequestMapping(value = "/activity/delete/{activityId}", method = RequestMethod.DELETE)
91
+    @ApiOperation(value = "删除活动", notes = "删除活动")
92
+    public ResponseBean delete(@PathVariable String activityId) {
93
+        ResponseBean responseBean = new ResponseBean();
94
+        Activity activity = iActivityService.getById(activityId);
95
+        if (null == activity) {
96
+            responseBean.addError("活动不存在!");
97
+            return responseBean;
98
+        }
99
+        activity.setStatus(-1);
100
+        QueryWrapper<Activity> activityQueryWrapper = new QueryWrapper<>();
101
+        activityQueryWrapper.eq("activity_id", activity.getActivityId());
102
+        iActivityService.update(activity, activityQueryWrapper);
103
+        responseBean.addSuccess("操作成功!");
104
+        return responseBean;
105
+    }
106
+
107
+
108
+    @RequestMapping(value = "/activity/enroll/list/{activityId}", method = RequestMethod.POST)
109
+    @ApiOperation(value = "根据活动id查询活动报名列表", notes = "根据活动id查询活动报名列表")
110
+    @ApiImplicitParams({
111
+            @ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "pageNum第几页;pageSize一页多少行")
112
+    })
113
+    public ResponseBean activityEnrollList(@PathVariable("activityId") String activityId, @RequestBody String parameter) {
114
+        ResponseBean responseBean = new ResponseBean();
115
+        responseBean = iActivityEnrollService.getActivitySignUpList(activityId, parameter);
116
+        return responseBean;
117
+    }
118
+
119
+
44 120
 }

+ 65
- 0
whole-estate/src/main/java/com/example/wholeestate/controller/CommentController.java 查看文件

@@ -0,0 +1,65 @@
1
+package com.example.wholeestate.controller;
2
+
3
+
4
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5
+import com.example.wholeestate.common.base.BaseController;
6
+import com.example.wholeestate.common.resp.ResponseBean;
7
+import com.example.wholeestate.model.Comment;
8
+import com.example.wholeestate.service.ICommentService;
9
+import io.swagger.annotations.Api;
10
+import io.swagger.annotations.ApiImplicitParam;
11
+import io.swagger.annotations.ApiImplicitParams;
12
+import io.swagger.annotations.ApiOperation;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.web.bind.annotation.PathVariable;
15
+import org.springframework.web.bind.annotation.RequestMapping;
16
+import org.springframework.web.bind.annotation.RequestMethod;
17
+import org.springframework.web.bind.annotation.RestController;
18
+
19
+/**
20
+ * <p>
21
+ * 评论表 前端控制器
22
+ * </p>
23
+ *
24
+ * @author weiximei
25
+ * @since 2019-03-20
26
+ */
27
+@RestController
28
+@RequestMapping("/")
29
+@Api(value = "评论 API", description = "评论 API")
30
+public class CommentController extends BaseController {
31
+
32
+    @Autowired
33
+    private ICommentService iCommentService;
34
+
35
+    @RequestMapping(value = "/comment/delete/{commentId}", method = RequestMethod.DELETE)
36
+    @ApiOperation(value = "删除评论", notes = "删除评论")
37
+    @ApiImplicitParams({
38
+            @ApiImplicitParam(paramType = "path", dataTypeClass = String.class, name = "commentId",value = "评论编号")
39
+    })
40
+    public ResponseBean delete(@PathVariable("commentId") String commentId) {
41
+        ResponseBean responseBean = new ResponseBean();
42
+        QueryWrapper<Comment> commentQueryWrapper = new QueryWrapper<>();
43
+        commentQueryWrapper.eq("comment_id", commentId);
44
+        Comment comment = iCommentService.getOne(commentQueryWrapper);
45
+        if (null == comment) {
46
+            responseBean.addError("评论不存在!");
47
+            return responseBean;
48
+        }
49
+
50
+        comment.setStatus(-1);
51
+        iCommentService.update(comment,commentQueryWrapper);
52
+
53
+        // 删除这个评论下的子评论
54
+        Comment  childComment = new Comment();
55
+        childComment.setStatus(-1);
56
+        QueryWrapper<Comment> childCommentQueryWrapper = new QueryWrapper<>();
57
+        childCommentQueryWrapper.eq("parent_id", commentId);
58
+        iCommentService.update(childComment, childCommentQueryWrapper);
59
+        responseBean.addSuccess("操作成功!");
60
+        return responseBean;
61
+    }
62
+
63
+
64
+
65
+}

+ 18
- 0
whole-estate/src/main/java/com/example/wholeestate/controller/SysUserController.java 查看文件

@@ -47,4 +47,22 @@ public class SysUserController extends BaseController {
47 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
 }

+ 9
- 0
whole-estate/src/main/java/com/example/wholeestate/dao/ActivityEnrollMapper.java 查看文件

@@ -1,7 +1,10 @@
1 1
 package com.example.wholeestate.dao;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
4 6
 import com.example.wholeestate.model.ActivityEnroll;
7
+import org.apache.ibatis.annotations.Select;
5 8
 
6 9
 /**
7 10
  * <p>
@@ -13,4 +16,10 @@ import com.example.wholeestate.model.ActivityEnroll;
13 16
  */
14 17
 public interface ActivityEnrollMapper extends BaseMapper<ActivityEnroll> {
15 18
 
19
+    @Select("SELECT tac.*,tacus.phone as phone,tacus.`name` as name,tacus.customer_name as customerName FROM ta_activity tac " +
20
+            "RIGHT JOIN ta_activity_enroll tace ON tac.activity_id = tace.activity_id " +
21
+            "LEFT JOIN ta_customer tacus ON tace.customer_id = tacus.customer_id " +
22
+            "WHERE tac.activity_id = #{activityId}")
23
+    IPage<ActivityEnroll> selectPageActivityEnroll(Page page, String activityId);
24
+
16 25
 }

+ 1
- 0
whole-estate/src/main/java/com/example/wholeestate/dao/ActivityMapper.java 查看文件

@@ -1,6 +1,7 @@
1 1
 package com.example.wholeestate.dao;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
4 5
 import com.example.wholeestate.model.Activity;
5 6
 
6 7
 /**

+ 16
- 0
whole-estate/src/main/java/com/example/wholeestate/dao/CommentMapper.java 查看文件

@@ -0,0 +1,16 @@
1
+package com.example.wholeestate.dao;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.example.wholeestate.model.Comment;
5
+
6
+/**
7
+ * <p>
8
+ * 评论表 Mapper 接口
9
+ * </p>
10
+ *
11
+ * @author weiximei
12
+ * @since 2019-03-20
13
+ */
14
+public interface CommentMapper extends BaseMapper<Comment> {
15
+
16
+}

+ 6
- 1
whole-estate/src/main/java/com/example/wholeestate/exception/ExceptionHandleAdice.java 查看文件

@@ -34,7 +34,12 @@ public class ExceptionHandleAdice {
34 34
     public ResponseBean handleException(WholeEstateException e) {
35 35
         log.error(e.getMessage(),e);
36 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 43
         return response;
39 44
     }
40 45
 

+ 24
- 0
whole-estate/src/main/java/com/example/wholeestate/model/Activity.java 查看文件

@@ -92,4 +92,28 @@ public class Activity implements Serializable {
92 92
     private Integer maxNum;
93 93
 
94 94
 
95
+    /**
96
+     * 楼盘
97
+     */
98
+    @TableField(exist = false)
99
+    private Building building;
100
+
101
+    /**
102
+     * 客户手机号
103
+     */
104
+    @TableField(exist = false)
105
+    private String phone;
106
+
107
+    /**
108
+     * 微信昵称
109
+     */
110
+    @TableField(exist = false)
111
+    private String name;
112
+
113
+    /**
114
+     * 客户姓名
115
+     */
116
+    @TableField(exist = false)
117
+    private String customerName;
118
+
95 119
 }

+ 78
- 0
whole-estate/src/main/java/com/example/wholeestate/model/Comment.java 查看文件

@@ -0,0 +1,78 @@
1
+package com.example.wholeestate.model;
2
+
3
+import com.baomidou.mybatisplus.annotation.TableName;
4
+import lombok.Data;
5
+import lombok.EqualsAndHashCode;
6
+import lombok.experimental.Accessors;
7
+
8
+import java.io.Serializable;
9
+import java.time.LocalDateTime;
10
+
11
+/**
12
+ * <p>
13
+ * 评论表
14
+ * </p>
15
+ *
16
+ * @author weiximei
17
+ * @since 2019-03-20
18
+ */
19
+@Data
20
+@EqualsAndHashCode(callSuper = false)
21
+@Accessors(chain = true)
22
+@TableName("ta_comment")
23
+public class Comment implements Serializable {
24
+
25
+    private static final long serialVersionUID = 1L;
26
+
27
+    /**
28
+     * 评论ID
29
+     */
30
+    private String commentId;
31
+
32
+    /**
33
+     * 用户ID
34
+     */
35
+    private String customerId;
36
+
37
+    /**
38
+     * 用户姓名
39
+     */
40
+    private String customerName;
41
+
42
+    /**
43
+     * 头像
44
+     */
45
+    private String avatar;
46
+
47
+    /**
48
+     * 评论主题类型
49
+     */
50
+    private String commentType;
51
+
52
+    /**
53
+     * 评论主体
54
+     */
55
+    private String mainId;
56
+
57
+    /**
58
+     * 父级
59
+     */
60
+    private String parentId;
61
+
62
+    /**
63
+     * 评论
64
+     */
65
+    private String commentContent;
66
+
67
+    /**
68
+     * 创建时间
69
+     */
70
+    private LocalDateTime createDate;
71
+
72
+    /**
73
+     * 0正常,-1删除
74
+     */
75
+    private Integer status;
76
+
77
+
78
+}

+ 8
- 0
whole-estate/src/main/java/com/example/wholeestate/service/IActivityEnrollService.java 查看文件

@@ -1,6 +1,7 @@
1 1
 package com.example.wholeestate.service;
2 2
 
3 3
 import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.example.wholeestate.common.resp.ResponseBean;
4 5
 import com.example.wholeestate.model.ActivityEnroll;
5 6
 
6 7
 /**
@@ -13,4 +14,11 @@ import com.example.wholeestate.model.ActivityEnroll;
13 14
  */
14 15
 public interface IActivityEnrollService extends IService<ActivityEnroll> {
15 16
 
17
+    /**
18
+     * 根据活动id 查询 活动报名列表
19
+     * @param parameter
20
+     * @return
21
+     */
22
+    ResponseBean getActivitySignUpList(String activityId,String parameter);
23
+
16 24
 }

+ 1
- 1
whole-estate/src/main/java/com/example/wholeestate/service/IActivityService.java 查看文件

@@ -26,6 +26,6 @@ public interface IActivityService extends IService<Activity> {
26 26
      * @param activityId
27 27
      * @return
28 28
      */
29
-    ResponseBean getById(String activityId);
29
+    ResponseBean getActivityId(String activityId);
30 30
 
31 31
 }

+ 25
- 0
whole-estate/src/main/java/com/example/wholeestate/service/ICommentService.java 查看文件

@@ -0,0 +1,25 @@
1
+package com.example.wholeestate.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.example.wholeestate.common.resp.ResponseBean;
5
+import com.example.wholeestate.model.Comment;
6
+import com.example.wholeestate.model.SysUser;
7
+
8
+/**
9
+ * <p>
10
+ * 评论表 服务类
11
+ * </p>
12
+ *
13
+ * @author weiximei
14
+ * @since 2019-03-20
15
+ */
16
+public interface ICommentService extends IService<Comment> {
17
+
18
+    /**
19
+     * 回复评论
20
+     * @param parameter
21
+     * @return
22
+     */
23
+    ResponseBean addComment(SysUser user, String parameter);
24
+
25
+}

+ 35
- 0
whole-estate/src/main/java/com/example/wholeestate/service/impl/ActivityEnrollServiceImpl.java 查看文件

@@ -1,9 +1,16 @@
1 1
 package com.example.wholeestate.service.impl;
2 2
 
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
3 6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import com.example.wholeestate.common.resp.ResponseBean;
4 8
 import com.example.wholeestate.dao.ActivityEnrollMapper;
9
+import com.example.wholeestate.dao.ActivityMapper;
10
+import com.example.wholeestate.model.Activity;
5 11
 import com.example.wholeestate.model.ActivityEnroll;
6 12
 import com.example.wholeestate.service.IActivityEnrollService;
13
+import org.springframework.beans.factory.annotation.Autowired;
7 14
 import org.springframework.stereotype.Service;
8 15
 
9 16
 /**
@@ -17,4 +24,32 @@ import org.springframework.stereotype.Service;
17 24
 @Service
18 25
 public class ActivityEnrollServiceImpl extends ServiceImpl<ActivityEnrollMapper, ActivityEnroll> implements IActivityEnrollService {
19 26
 
27
+    @Autowired
28
+    private ActivityEnrollMapper activityEnrollMapper;
29
+
30
+    @Autowired
31
+    private ActivityMapper activityMapper;
32
+
33
+    @Override
34
+    public ResponseBean getActivitySignUpList(String activityId,String parameter) {
35
+        ResponseBean responseBean = new ResponseBean();
36
+
37
+        Activity activity = activityMapper.selectById(activityId);
38
+        if (null == activity) {
39
+            responseBean.addError("活动不存在!");
40
+            return responseBean;
41
+        }
42
+
43
+        JSONObject jsonObject = JSONObject.parseObject(parameter);
44
+        Integer pageNum = jsonObject.getInteger("pageNum");
45
+        Integer pageSize = jsonObject.getInteger("pageSize");
46
+
47
+        Page<Activity> page = new Page<>();
48
+        page.setCurrent(pageNum == null ? 1 : pageNum);
49
+        page.setSize(pageSize == null ? 10 : pageSize);
50
+        IPage<ActivityEnroll> activityEnrollIPage = activityEnrollMapper.selectPageActivityEnroll(page, activityId);
51
+
52
+        responseBean.addSuccess(activityEnrollIPage);
53
+        return responseBean;
54
+    }
20 55
 }

+ 16
- 5
whole-estate/src/main/java/com/example/wholeestate/service/impl/ActivityServiceImpl.java 查看文件

@@ -7,7 +7,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7 7
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
8 8
 import com.example.wholeestate.common.resp.ResponseBean;
9 9
 import com.example.wholeestate.dao.ActivityMapper;
10
+import com.example.wholeestate.dao.BuildingMapper;
10 11
 import com.example.wholeestate.model.Activity;
12
+import com.example.wholeestate.model.Building;
11 13
 import com.example.wholeestate.service.IActivityService;
12 14
 import org.springframework.beans.factory.annotation.Autowired;
13 15
 import org.springframework.stereotype.Service;
@@ -26,6 +28,9 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> i
26 28
     @Autowired
27 29
     private ActivityMapper activityMapper;
28 30
 
31
+    @Autowired
32
+    private BuildingMapper buildingMapper;
33
+
29 34
     @Override
30 35
     public ResponseBean getList(String parameter) {
31 36
         ResponseBean responseBean = new ResponseBean();
@@ -35,8 +40,8 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> i
35 40
         Integer pageSize = jsonObject.getInteger("pageSize");
36 41
 
37 42
         Page<Activity> page = new Page<>();
38
-        page.setCurrent(pageNum);
39
-        page.setSize(pageSize);
43
+        page.setCurrent(pageNum == null ? 1 : pageNum);
44
+        page.setSize(pageSize == null ? 10 : pageSize);
40 45
         QueryWrapper<Activity> queryWrapper = new QueryWrapper<>();
41 46
         IPage<Activity> activityIPage = activityMapper.selectPage(page, queryWrapper);
42 47
         responseBean.addSuccess(activityIPage);
@@ -44,16 +49,22 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> i
44 49
     }
45 50
 
46 51
     @Override
47
-    public ResponseBean getById(String activityId) {
52
+    public ResponseBean getActivityId(String activityId) {
48 53
         ResponseBean responseBean = new ResponseBean();
49 54
 
50
-        Activity activity = activityMapper.selectById(activityId);
55
+        QueryWrapper<Activity> activityQueryWrapper = new QueryWrapper<>();
56
+        activityQueryWrapper.eq("activity_id", activityId);
57
+        Activity activity = activityMapper.selectOne(activityQueryWrapper);
51 58
         if (null == activity) {
52 59
             responseBean.addError("活动不存在!");
53 60
             return responseBean;
54 61
         }
55 62
 
56
-        responseBean.addSuccess(activityId);
63
+        QueryWrapper<Building> buildingQueryWrapper = new QueryWrapper<>();
64
+        buildingQueryWrapper.eq("building_id", activity.getBuildingId());
65
+        Building building = buildingMapper.selectOne(buildingQueryWrapper);
66
+        activity.setBuilding(building);
67
+        responseBean.addSuccess(activity);
57 68
         return responseBean;
58 69
     }
59 70
 }

+ 60
- 0
whole-estate/src/main/java/com/example/wholeestate/service/impl/CommentServiceImpl.java 查看文件

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

+ 51
- 0
whole-estate/src/main/java/com/example/wholeestate/utils/MD5Utils.java 查看文件

@@ -0,0 +1,51 @@
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
+}